Skip to content

Commit 65545ea

Browse files
pmachatadavem330
authored andcommitted
net: sched: sch_red: Split init and change callbacks
In the following patches, RED will get two qevents. The implementation will be clearer if the callback for change is not a pure subset of the callback for init. Split the two and promote attribute parsing to the callbacks themselves from the common code, because it will be handy there. Signed-off-by: Petr Machata <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3625750 commit 65545ea

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

net/sched/sch_red.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,27 +215,18 @@ static const struct nla_policy red_policy[TCA_RED_MAX + 1] = {
215215
[TCA_RED_FLAGS] = NLA_POLICY_BITFIELD32(TC_RED_SUPPORTED_FLAGS),
216216
};
217217

218-
static int red_change(struct Qdisc *sch, struct nlattr *opt,
219-
struct netlink_ext_ack *extack)
218+
static int __red_change(struct Qdisc *sch, struct nlattr **tb,
219+
struct netlink_ext_ack *extack)
220220
{
221221
struct Qdisc *old_child = NULL, *child = NULL;
222222
struct red_sched_data *q = qdisc_priv(sch);
223-
struct nlattr *tb[TCA_RED_MAX + 1];
224223
struct nla_bitfield32 flags_bf;
225224
struct tc_red_qopt *ctl;
226225
unsigned char userbits;
227226
unsigned char flags;
228227
int err;
229228
u32 max_P;
230229

231-
if (opt == NULL)
232-
return -EINVAL;
233-
234-
err = nla_parse_nested_deprecated(tb, TCA_RED_MAX, opt, red_policy,
235-
NULL);
236-
if (err < 0)
237-
return err;
238-
239230
if (tb[TCA_RED_PARMS] == NULL ||
240231
tb[TCA_RED_STAB] == NULL)
241232
return -EINVAL;
@@ -323,11 +314,38 @@ static int red_init(struct Qdisc *sch, struct nlattr *opt,
323314
struct netlink_ext_ack *extack)
324315
{
325316
struct red_sched_data *q = qdisc_priv(sch);
317+
struct nlattr *tb[TCA_RED_MAX + 1];
318+
int err;
319+
320+
if (!opt)
321+
return -EINVAL;
322+
323+
err = nla_parse_nested_deprecated(tb, TCA_RED_MAX, opt, red_policy,
324+
extack);
325+
if (err < 0)
326+
return err;
326327

327328
q->qdisc = &noop_qdisc;
328329
q->sch = sch;
329330
timer_setup(&q->adapt_timer, red_adaptative_timer, 0);
330-
return red_change(sch, opt, extack);
331+
return __red_change(sch, tb, extack);
332+
}
333+
334+
static int red_change(struct Qdisc *sch, struct nlattr *opt,
335+
struct netlink_ext_ack *extack)
336+
{
337+
struct nlattr *tb[TCA_RED_MAX + 1];
338+
int err;
339+
340+
if (!opt)
341+
return -EINVAL;
342+
343+
err = nla_parse_nested_deprecated(tb, TCA_RED_MAX, opt, red_policy,
344+
extack);
345+
if (err < 0)
346+
return err;
347+
348+
return __red_change(sch, tb, extack);
331349
}
332350

333351
static int red_dump_offload_stats(struct Qdisc *sch)

0 commit comments

Comments
 (0)