Skip to content

Commit cc72bb0

Browse files
q2venkuba-moo
authored andcommitted
net: sched: Use rtnl_register_many().
We will remove rtnl_register() in favour of rtnl_register_many(). When it succeeds, rtnl_register_many() guarantees all rtnetlink types in the passed array are supported, and there is no chance that a part of message types is not supported. Let's use rtnl_register_many() instead. Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> Link: https://patch.msgid.link/20241014201828.91221-5-kuniyu@amazon.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent d0d14ae commit cc72bb0

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

net/sched/act_api.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,13 +2243,16 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
22432243
return skb->len;
22442244
}
22452245

2246+
static const struct rtnl_msg_handler tc_action_rtnl_msg_handlers[] __initconst = {
2247+
{.msgtype = RTM_NEWACTION, .doit = tc_ctl_action},
2248+
{.msgtype = RTM_DELACTION, .doit = tc_ctl_action},
2249+
{.msgtype = RTM_GETACTION, .doit = tc_ctl_action,
2250+
.dumpit = tc_dump_action},
2251+
};
2252+
22462253
static int __init tc_action_init(void)
22472254
{
2248-
rtnl_register(PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL, 0);
2249-
rtnl_register(PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL, 0);
2250-
rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action,
2251-
0);
2252-
2255+
rtnl_register_many(tc_action_rtnl_msg_handlers);
22532256
return 0;
22542257
}
22552258

net/sched/cls_api.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4055,6 +4055,19 @@ static struct pernet_operations tcf_net_ops = {
40554055
.size = sizeof(struct tcf_net),
40564056
};
40574057

4058+
static const struct rtnl_msg_handler tc_filter_rtnl_msg_handlers[] __initconst = {
4059+
{.msgtype = RTM_NEWTFILTER, .doit = tc_new_tfilter,
4060+
.flags = RTNL_FLAG_DOIT_UNLOCKED},
4061+
{.msgtype = RTM_DELTFILTER, .doit = tc_del_tfilter,
4062+
.flags = RTNL_FLAG_DOIT_UNLOCKED},
4063+
{.msgtype = RTM_GETTFILTER, .doit = tc_get_tfilter,
4064+
.dumpit = tc_dump_tfilter, .flags = RTNL_FLAG_DOIT_UNLOCKED},
4065+
{.msgtype = RTM_NEWCHAIN, .doit = tc_ctl_chain},
4066+
{.msgtype = RTM_DELCHAIN, .doit = tc_ctl_chain},
4067+
{.msgtype = RTM_GETCHAIN, .doit = tc_ctl_chain,
4068+
.dumpit = tc_dump_chain},
4069+
};
4070+
40584071
static int __init tc_filter_init(void)
40594072
{
40604073
int err;
@@ -4068,17 +4081,7 @@ static int __init tc_filter_init(void)
40684081
goto err_register_pernet_subsys;
40694082

40704083
xa_init_flags(&tcf_exts_miss_cookies_xa, XA_FLAGS_ALLOC1);
4071-
4072-
rtnl_register(PF_UNSPEC, RTM_NEWTFILTER, tc_new_tfilter, NULL,
4073-
RTNL_FLAG_DOIT_UNLOCKED);
4074-
rtnl_register(PF_UNSPEC, RTM_DELTFILTER, tc_del_tfilter, NULL,
4075-
RTNL_FLAG_DOIT_UNLOCKED);
4076-
rtnl_register(PF_UNSPEC, RTM_GETTFILTER, tc_get_tfilter,
4077-
tc_dump_tfilter, RTNL_FLAG_DOIT_UNLOCKED);
4078-
rtnl_register(PF_UNSPEC, RTM_NEWCHAIN, tc_ctl_chain, NULL, 0);
4079-
rtnl_register(PF_UNSPEC, RTM_DELCHAIN, tc_ctl_chain, NULL, 0);
4080-
rtnl_register(PF_UNSPEC, RTM_GETCHAIN, tc_ctl_chain,
4081-
tc_dump_chain, 0);
4084+
rtnl_register_many(tc_filter_rtnl_msg_handlers);
40824085

40834086
return 0;
40844087

net/sched/sch_api.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,6 +2420,17 @@ static struct pernet_operations psched_net_ops = {
24202420
DEFINE_STATIC_KEY_FALSE(tc_skip_wrapper);
24212421
#endif
24222422

2423+
static const struct rtnl_msg_handler psched_rtnl_msg_handlers[] __initconst = {
2424+
{.msgtype = RTM_NEWQDISC, .doit = tc_modify_qdisc},
2425+
{.msgtype = RTM_DELQDISC, .doit = tc_get_qdisc},
2426+
{.msgtype = RTM_GETQDISC, .doit = tc_get_qdisc,
2427+
.dumpit = tc_dump_qdisc},
2428+
{.msgtype = RTM_NEWTCLASS, .doit = tc_ctl_tclass},
2429+
{.msgtype = RTM_DELTCLASS, .doit = tc_ctl_tclass},
2430+
{.msgtype = RTM_GETTCLASS, .doit = tc_ctl_tclass,
2431+
.dumpit = tc_dump_tclass},
2432+
};
2433+
24232434
static int __init pktsched_init(void)
24242435
{
24252436
int err;
@@ -2438,14 +2449,7 @@ static int __init pktsched_init(void)
24382449
register_qdisc(&mq_qdisc_ops);
24392450
register_qdisc(&noqueue_qdisc_ops);
24402451

2441-
rtnl_register(PF_UNSPEC, RTM_NEWQDISC, tc_modify_qdisc, NULL, 0);
2442-
rtnl_register(PF_UNSPEC, RTM_DELQDISC, tc_get_qdisc, NULL, 0);
2443-
rtnl_register(PF_UNSPEC, RTM_GETQDISC, tc_get_qdisc, tc_dump_qdisc,
2444-
0);
2445-
rtnl_register(PF_UNSPEC, RTM_NEWTCLASS, tc_ctl_tclass, NULL, 0);
2446-
rtnl_register(PF_UNSPEC, RTM_DELTCLASS, tc_ctl_tclass, NULL, 0);
2447-
rtnl_register(PF_UNSPEC, RTM_GETTCLASS, tc_ctl_tclass, tc_dump_tclass,
2448-
0);
2452+
rtnl_register_many(psched_rtnl_msg_handlers);
24492453

24502454
tc_wrapper_init();
24512455

0 commit comments

Comments
 (0)