Skip to content

Commit 2536989

Browse files
tammeladavem330
authored andcommitted
net/sched: sch_qfq: refactor parsing of netlink parameters
Two parameters can be transformed into netlink policies and validated while parsing the netlink message. Reviewed-by: Simon Horman <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: Pedro Tammela <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c69a9b0 commit 2536989

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

net/sched/sch_qfq.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113

114114
#define QFQ_MTU_SHIFT 16 /* to support TSO/GSO */
115115
#define QFQ_MIN_LMAX 512 /* see qfq_slot_insert */
116+
#define QFQ_MAX_LMAX (1UL << QFQ_MTU_SHIFT)
116117

117118
#define QFQ_MAX_AGG_CLASSES 8 /* max num classes per aggregate allowed */
118119

@@ -214,9 +215,14 @@ static struct qfq_class *qfq_find_class(struct Qdisc *sch, u32 classid)
214215
return container_of(clc, struct qfq_class, common);
215216
}
216217

218+
static struct netlink_range_validation lmax_range = {
219+
.min = QFQ_MIN_LMAX,
220+
.max = QFQ_MAX_LMAX,
221+
};
222+
217223
static const struct nla_policy qfq_policy[TCA_QFQ_MAX + 1] = {
218-
[TCA_QFQ_WEIGHT] = { .type = NLA_U32 },
219-
[TCA_QFQ_LMAX] = { .type = NLA_U32 },
224+
[TCA_QFQ_WEIGHT] = NLA_POLICY_RANGE(NLA_U32, 1, QFQ_MAX_WEIGHT),
225+
[TCA_QFQ_LMAX] = NLA_POLICY_FULL_RANGE(NLA_U32, &lmax_range),
220226
};
221227

222228
/*
@@ -408,29 +414,20 @@ static int qfq_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
408414
}
409415

410416
err = nla_parse_nested_deprecated(tb, TCA_QFQ_MAX, tca[TCA_OPTIONS],
411-
qfq_policy, NULL);
417+
qfq_policy, extack);
412418
if (err < 0)
413419
return err;
414420

415-
if (tb[TCA_QFQ_WEIGHT]) {
421+
if (tb[TCA_QFQ_WEIGHT])
416422
weight = nla_get_u32(tb[TCA_QFQ_WEIGHT]);
417-
if (!weight || weight > (1UL << QFQ_MAX_WSHIFT)) {
418-
pr_notice("qfq: invalid weight %u\n", weight);
419-
return -EINVAL;
420-
}
421-
} else
423+
else
422424
weight = 1;
423425

424426
if (tb[TCA_QFQ_LMAX])
425427
lmax = nla_get_u32(tb[TCA_QFQ_LMAX]);
426428
else
427429
lmax = psched_mtu(qdisc_dev(sch));
428430

429-
if (lmax < QFQ_MIN_LMAX || lmax > (1UL << QFQ_MTU_SHIFT)) {
430-
pr_notice("qfq: invalid max length %u\n", lmax);
431-
return -EINVAL;
432-
}
433-
434431
inv_w = ONE_FP / weight;
435432
weight = ONE_FP / inv_w;
436433

0 commit comments

Comments
 (0)