aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched/sch_netem.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_netem.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_netem.c')
-rw-r--r--net/sched/sch_netem.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index 1a755799ffb8..c9c649b26eaa 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -368,9 +368,6 @@ static int get_correlation(struct Qdisc *sch, const struct nlattr *attr)
368 struct netem_sched_data *q = qdisc_priv(sch); 368 struct netem_sched_data *q = qdisc_priv(sch);
369 const struct tc_netem_corr *c = nla_data(attr); 369 const struct tc_netem_corr *c = nla_data(attr);
370 370
371 if (nla_len(attr) != sizeof(*c))
372 return -EINVAL;
373
374 init_crandom(&q->delay_cor, c->delay_corr); 371 init_crandom(&q->delay_cor, c->delay_corr);
375 init_crandom(&q->loss_cor, c->loss_corr); 372 init_crandom(&q->loss_cor, c->loss_corr);
376 init_crandom(&q->dup_cor, c->dup_corr); 373 init_crandom(&q->dup_cor, c->dup_corr);
@@ -382,9 +379,6 @@ static int get_reorder(struct Qdisc *sch, const struct nlattr *attr)
382 struct netem_sched_data *q = qdisc_priv(sch); 379 struct netem_sched_data *q = qdisc_priv(sch);
383 const struct tc_netem_reorder *r = nla_data(attr); 380 const struct tc_netem_reorder *r = nla_data(attr);
384 381
385 if (nla_len(attr) != sizeof(*r))
386 return -EINVAL;
387
388 q->reorder = r->probability; 382 q->reorder = r->probability;
389 init_crandom(&q->reorder_cor, r->correlation); 383 init_crandom(&q->reorder_cor, r->correlation);
390 return 0; 384 return 0;
@@ -395,14 +389,17 @@ static int get_corrupt(struct Qdisc *sch, const struct nlattr *attr)
395 struct netem_sched_data *q = qdisc_priv(sch); 389 struct netem_sched_data *q = qdisc_priv(sch);
396 const struct tc_netem_corrupt *r = nla_data(attr); 390 const struct tc_netem_corrupt *r = nla_data(attr);
397 391
398 if (nla_len(attr) != sizeof(*r))
399 return -EINVAL;
400
401 q->corrupt = r->probability; 392 q->corrupt = r->probability;
402 init_crandom(&q->corrupt_cor, r->correlation); 393 init_crandom(&q->corrupt_cor, r->correlation);
403 return 0; 394 return 0;
404} 395}
405 396
397static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
398 [TCA_NETEM_CORR] = { .len = sizeof(struct tc_netem_corr) },
399 [TCA_NETEM_REORDER] = { .len = sizeof(struct tc_netem_reorder) },
400 [TCA_NETEM_CORRUPT] = { .len = sizeof(struct tc_netem_corrupt) },
401};
402
406/* Parse netlink message to set options */ 403/* Parse netlink message to set options */
407static int netem_change(struct Qdisc *sch, struct nlattr *opt) 404static int netem_change(struct Qdisc *sch, struct nlattr *opt)
408{ 405{
@@ -414,8 +411,8 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt)
414 if (opt == NULL) 411 if (opt == NULL)
415 return -EINVAL; 412 return -EINVAL;
416 413
417 ret = nla_parse_nested_compat(tb, TCA_NETEM_MAX, opt, NULL, qopt, 414 ret = nla_parse_nested_compat(tb, TCA_NETEM_MAX, opt, netem_policy,
418 sizeof(*qopt)); 415 qopt, sizeof(*qopt));
419 if (ret < 0) 416 if (ret < 0)
420 return ret; 417 return ret;
421 418