diff options
author | Patrick McHardy <kaber@trash.net> | 2008-01-24 07:35:39 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-01-29 02:11:22 +0300 |
commit | 27a3421e4821734bc19496faa77b380605dc3b23 (patch) | |
tree | f9ded49845a39f41352ed09130bf3d2bd05e4ffe /net/sched/sch_dsmark.c | |
parent | 5feb5e1aaa887f6427b8290bce48bfb6b7010fc6 (diff) | |
download | linux-27a3421e4821734bc19496faa77b380605dc3b23.tar.xz |
[NET_SCHED]: Use nla_policy for attribute validation in packet schedulers
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sched/sch_dsmark.c')
-rw-r--r-- | net/sched/sch_dsmark.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/net/sched/sch_dsmark.c b/net/sched/sch_dsmark.c index f1d0a08aca75..0df911fd67b1 100644 --- a/net/sched/sch_dsmark.c +++ b/net/sched/sch_dsmark.c @@ -99,6 +99,14 @@ static void dsmark_put(struct Qdisc *sch, unsigned long cl) { } +static const struct nla_policy dsmark_policy[TCA_DSMARK_MAX + 1] = { + [TCA_DSMARK_INDICES] = { .type = NLA_U16 }, + [TCA_DSMARK_DEFAULT_INDEX] = { .type = NLA_U16 }, + [TCA_DSMARK_SET_TC_INDEX] = { .type = NLA_FLAG }, + [TCA_DSMARK_MASK] = { .type = NLA_U8 }, + [TCA_DSMARK_VALUE] = { .type = NLA_U8 }, +}; + static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent, struct nlattr **tca, unsigned long *arg) { @@ -119,21 +127,15 @@ static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent, if (!opt) goto errout; - err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, NULL); + err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, dsmark_policy); if (err < 0) - return err; + goto errout; - err = -EINVAL; - if (tb[TCA_DSMARK_MASK]) { - if (nla_len(tb[TCA_DSMARK_MASK]) < sizeof(u8)) - goto errout; + if (tb[TCA_DSMARK_MASK]) mask = nla_get_u8(tb[TCA_DSMARK_MASK]); - } - if (tb[TCA_DSMARK_VALUE]) { - if (nla_len(tb[TCA_DSMARK_VALUE]) < sizeof(u8)) - goto errout; + + if (tb[TCA_DSMARK_VALUE]) p->value[*arg-1] = nla_get_u8(tb[TCA_DSMARK_VALUE]); - } if (tb[TCA_DSMARK_MASK]) p->mask[*arg-1] = mask; @@ -359,23 +361,18 @@ static int dsmark_init(struct Qdisc *sch, struct nlattr *opt) if (!opt) goto errout; - err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, NULL); + err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, dsmark_policy); if (err < 0) goto errout; err = -EINVAL; - if (nla_len(tb[TCA_DSMARK_INDICES]) < sizeof(u16)) - goto errout; indices = nla_get_u16(tb[TCA_DSMARK_INDICES]); if (hweight32(indices) != 1) goto errout; - if (tb[TCA_DSMARK_DEFAULT_INDEX]) { - if (nla_len(tb[TCA_DSMARK_DEFAULT_INDEX]) < sizeof(u16)) - goto errout; + if (tb[TCA_DSMARK_DEFAULT_INDEX]) default_index = nla_get_u16(tb[TCA_DSMARK_DEFAULT_INDEX]); - } mask = kmalloc(indices * 2, GFP_KERNEL); if (mask == NULL) { |