aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched/sch_dsmark.c
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2008-01-23 23:35:39 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 18:11:22 -0500
commit27a3421e4821734bc19496faa77b380605dc3b23 (patch)
treef9ded49845a39f41352ed09130bf3d2bd05e4ffe /net/sched/sch_dsmark.c
parent5feb5e1aaa887f6427b8290bce48bfb6b7010fc6 (diff)
[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.c33
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)
99{ 99{
100} 100}
101 101
102static const struct nla_policy dsmark_policy[TCA_DSMARK_MAX + 1] = {
103 [TCA_DSMARK_INDICES] = { .type = NLA_U16 },
104 [TCA_DSMARK_DEFAULT_INDEX] = { .type = NLA_U16 },
105 [TCA_DSMARK_SET_TC_INDEX] = { .type = NLA_FLAG },
106 [TCA_DSMARK_MASK] = { .type = NLA_U8 },
107 [TCA_DSMARK_VALUE] = { .type = NLA_U8 },
108};
109
102static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent, 110static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent,
103 struct nlattr **tca, unsigned long *arg) 111 struct nlattr **tca, unsigned long *arg)
104{ 112{
@@ -119,21 +127,15 @@ static int dsmark_change(struct Qdisc *sch, u32 classid, u32 parent,
119 if (!opt) 127 if (!opt)
120 goto errout; 128 goto errout;
121 129
122 err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, NULL); 130 err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, dsmark_policy);
123 if (err < 0) 131 if (err < 0)
124 return err; 132 goto errout;
125 133
126 err = -EINVAL; 134 if (tb[TCA_DSMARK_MASK])
127 if (tb[TCA_DSMARK_MASK]) {
128 if (nla_len(tb[TCA_DSMARK_MASK]) < sizeof(u8))
129 goto errout;
130 mask = nla_get_u8(tb[TCA_DSMARK_MASK]); 135 mask = nla_get_u8(tb[TCA_DSMARK_MASK]);
131 } 136
132 if (tb[TCA_DSMARK_VALUE]) { 137 if (tb[TCA_DSMARK_VALUE])
133 if (nla_len(tb[TCA_DSMARK_VALUE]) < sizeof(u8))
134 goto errout;
135 p->value[*arg-1] = nla_get_u8(tb[TCA_DSMARK_VALUE]); 138 p->value[*arg-1] = nla_get_u8(tb[TCA_DSMARK_VALUE]);
136 }
137 139
138 if (tb[TCA_DSMARK_MASK]) 140 if (tb[TCA_DSMARK_MASK])
139 p->mask[*arg-1] = mask; 141 p->mask[*arg-1] = mask;
@@ -359,23 +361,18 @@ static int dsmark_init(struct Qdisc *sch, struct nlattr *opt)
359 if (!opt) 361 if (!opt)
360 goto errout; 362 goto errout;
361 363
362 err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, NULL); 364 err = nla_parse_nested(tb, TCA_DSMARK_MAX, opt, dsmark_policy);
363 if (err < 0) 365 if (err < 0)
364 goto errout; 366 goto errout;
365 367
366 err = -EINVAL; 368 err = -EINVAL;
367 if (nla_len(tb[TCA_DSMARK_INDICES]) < sizeof(u16))
368 goto errout;
369 indices = nla_get_u16(tb[TCA_DSMARK_INDICES]); 369 indices = nla_get_u16(tb[TCA_DSMARK_INDICES]);
370 370
371 if (hweight32(indices) != 1) 371 if (hweight32(indices) != 1)
372 goto errout; 372 goto errout;
373 373
374 if (tb[TCA_DSMARK_DEFAULT_INDEX]) { 374 if (tb[TCA_DSMARK_DEFAULT_INDEX])
375 if (nla_len(tb[TCA_DSMARK_DEFAULT_INDEX]) < sizeof(u16))
376 goto errout;
377 default_index = nla_get_u16(tb[TCA_DSMARK_DEFAULT_INDEX]); 375 default_index = nla_get_u16(tb[TCA_DSMARK_DEFAULT_INDEX]);
378 }
379 376
380 mask = kmalloc(indices * 2, GFP_KERNEL); 377 mask = kmalloc(indices * 2, GFP_KERNEL);
381 if (mask == NULL) { 378 if (mask == NULL) {