Skip to content

Commit 465bac9

Browse files
q2venkuba-moo
authored andcommitted
ipv4: 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> Link: https://patch.msgid.link/20241014201828.91221-7-kuniyu@amazon.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 803838a commit 465bac9

File tree

5 files changed

+55
-33
lines changed

5 files changed

+55
-33
lines changed

net/core/fib_rules.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,13 +1291,18 @@ static struct pernet_operations fib_rules_net_ops = {
12911291
.exit = fib_rules_net_exit,
12921292
};
12931293

1294+
static const struct rtnl_msg_handler fib_rules_rtnl_msg_handlers[] __initconst = {
1295+
{.msgtype = RTM_NEWRULE, .doit = fib_nl_newrule},
1296+
{.msgtype = RTM_DELRULE, .doit = fib_nl_delrule},
1297+
{.msgtype = RTM_GETRULE, .dumpit = fib_nl_dumprule,
1298+
.flags = RTNL_FLAG_DUMP_UNLOCKED},
1299+
};
1300+
12941301
static int __init fib_rules_init(void)
12951302
{
12961303
int err;
1297-
rtnl_register(PF_UNSPEC, RTM_NEWRULE, fib_nl_newrule, NULL, 0);
1298-
rtnl_register(PF_UNSPEC, RTM_DELRULE, fib_nl_delrule, NULL, 0);
1299-
rtnl_register(PF_UNSPEC, RTM_GETRULE, NULL, fib_nl_dumprule,
1300-
RTNL_FLAG_DUMP_UNLOCKED);
1304+
1305+
rtnl_register_many(fib_rules_rtnl_msg_handlers);
13011306

13021307
err = register_pernet_subsys(&fib_rules_net_ops);
13031308
if (err < 0)
@@ -1312,9 +1317,7 @@ static int __init fib_rules_init(void)
13121317
fail_unregister:
13131318
unregister_pernet_subsys(&fib_rules_net_ops);
13141319
fail:
1315-
rtnl_unregister(PF_UNSPEC, RTM_NEWRULE);
1316-
rtnl_unregister(PF_UNSPEC, RTM_DELRULE);
1317-
rtnl_unregister(PF_UNSPEC, RTM_GETRULE);
1320+
rtnl_unregister_many(fib_rules_rtnl_msg_handlers);
13181321
return err;
13191322
}
13201323

net/ipv4/devinet.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,18 +2797,22 @@ static struct rtnl_af_ops inet_af_ops __read_mostly = {
27972797
.set_link_af = inet_set_link_af,
27982798
};
27992799

2800+
static const struct rtnl_msg_handler devinet_rtnl_msg_handlers[] __initconst = {
2801+
{.protocol = PF_INET, .msgtype = RTM_NEWADDR, .doit = inet_rtm_newaddr},
2802+
{.protocol = PF_INET, .msgtype = RTM_DELADDR, .doit = inet_rtm_deladdr},
2803+
{.protocol = PF_INET, .msgtype = RTM_GETADDR, .dumpit = inet_dump_ifaddr,
2804+
.flags = RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE},
2805+
{.protocol = PF_INET, .msgtype = RTM_GETNETCONF,
2806+
.doit = inet_netconf_get_devconf, .dumpit = inet_netconf_dump_devconf,
2807+
.flags = RTNL_FLAG_DOIT_UNLOCKED | RTNL_FLAG_DUMP_UNLOCKED},
2808+
};
2809+
28002810
void __init devinet_init(void)
28012811
{
28022812
register_pernet_subsys(&devinet_ops);
28032813
register_netdevice_notifier(&ip_netdev_notifier);
28042814

28052815
rtnl_af_register(&inet_af_ops);
28062816

2807-
rtnl_register(PF_INET, RTM_NEWADDR, inet_rtm_newaddr, NULL, 0);
2808-
rtnl_register(PF_INET, RTM_DELADDR, inet_rtm_deladdr, NULL, 0);
2809-
rtnl_register(PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr,
2810-
RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE);
2811-
rtnl_register(PF_INET, RTM_GETNETCONF, inet_netconf_get_devconf,
2812-
inet_netconf_dump_devconf,
2813-
RTNL_FLAG_DOIT_UNLOCKED | RTNL_FLAG_DUMP_UNLOCKED);
2817+
rtnl_register_many(devinet_rtnl_msg_handlers);
28142818
}

net/ipv4/fib_frontend.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,15 @@ static struct pernet_operations fib_net_ops = {
16491649
.exit_batch = fib_net_exit_batch,
16501650
};
16511651

1652+
static const struct rtnl_msg_handler fib_rtnl_msg_handlers[] __initconst = {
1653+
{.protocol = PF_INET, .msgtype = RTM_NEWROUTE,
1654+
.doit = inet_rtm_newroute},
1655+
{.protocol = PF_INET, .msgtype = RTM_DELROUTE,
1656+
.doit = inet_rtm_delroute},
1657+
{.protocol = PF_INET, .msgtype = RTM_GETROUTE, .dumpit = inet_dump_fib,
1658+
.flags = RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE},
1659+
};
1660+
16521661
void __init ip_fib_init(void)
16531662
{
16541663
fib_trie_init();
@@ -1658,8 +1667,5 @@ void __init ip_fib_init(void)
16581667
register_netdevice_notifier(&fib_netdev_notifier);
16591668
register_inetaddr_notifier(&fib_inetaddr_notifier);
16601669

1661-
rtnl_register(PF_INET, RTM_NEWROUTE, inet_rtm_newroute, NULL, 0);
1662-
rtnl_register(PF_INET, RTM_DELROUTE, inet_rtm_delroute, NULL, 0);
1663-
rtnl_register(PF_INET, RTM_GETROUTE, NULL, inet_dump_fib,
1664-
RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE);
1670+
rtnl_register_many(fib_rtnl_msg_handlers);
16651671
}

net/ipv4/nexthop.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4042,25 +4042,30 @@ static struct pernet_operations nexthop_net_ops = {
40424042
.exit_batch_rtnl = nexthop_net_exit_batch_rtnl,
40434043
};
40444044

4045+
static const struct rtnl_msg_handler nexthop_rtnl_msg_handlers[] __initconst = {
4046+
{.msgtype = RTM_NEWNEXTHOP, .doit = rtm_new_nexthop},
4047+
{.msgtype = RTM_DELNEXTHOP, .doit = rtm_del_nexthop},
4048+
{.msgtype = RTM_GETNEXTHOP, .doit = rtm_get_nexthop,
4049+
.dumpit = rtm_dump_nexthop},
4050+
{.msgtype = RTM_GETNEXTHOPBUCKET, .doit = rtm_get_nexthop_bucket,
4051+
.dumpit = rtm_dump_nexthop_bucket},
4052+
{.protocol = PF_INET, .msgtype = RTM_NEWNEXTHOP,
4053+
.doit = rtm_new_nexthop},
4054+
{.protocol = PF_INET, .msgtype = RTM_GETNEXTHOP,
4055+
.dumpit = rtm_dump_nexthop},
4056+
{.protocol = PF_INET6, .msgtype = RTM_NEWNEXTHOP,
4057+
.doit = rtm_new_nexthop},
4058+
{.protocol = PF_INET6, .msgtype = RTM_GETNEXTHOP,
4059+
.dumpit = rtm_dump_nexthop},
4060+
};
4061+
40454062
static int __init nexthop_init(void)
40464063
{
40474064
register_pernet_subsys(&nexthop_net_ops);
40484065

40494066
register_netdevice_notifier(&nh_netdev_notifier);
40504067

4051-
rtnl_register(PF_UNSPEC, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0);
4052-
rtnl_register(PF_UNSPEC, RTM_DELNEXTHOP, rtm_del_nexthop, NULL, 0);
4053-
rtnl_register(PF_UNSPEC, RTM_GETNEXTHOP, rtm_get_nexthop,
4054-
rtm_dump_nexthop, 0);
4055-
4056-
rtnl_register(PF_INET, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0);
4057-
rtnl_register(PF_INET, RTM_GETNEXTHOP, NULL, rtm_dump_nexthop, 0);
4058-
4059-
rtnl_register(PF_INET6, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0);
4060-
rtnl_register(PF_INET6, RTM_GETNEXTHOP, NULL, rtm_dump_nexthop, 0);
4061-
4062-
rtnl_register(PF_UNSPEC, RTM_GETNEXTHOPBUCKET, rtm_get_nexthop_bucket,
4063-
rtm_dump_nexthop_bucket, 0);
4068+
rtnl_register_many(nexthop_rtnl_msg_handlers);
40644069

40654070
return 0;
40664071
}

net/ipv4/route.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,6 +3632,11 @@ static __net_initdata struct pernet_operations ipv4_inetpeer_ops = {
36323632
struct ip_rt_acct __percpu *ip_rt_acct __read_mostly;
36333633
#endif /* CONFIG_IP_ROUTE_CLASSID */
36343634

3635+
static const struct rtnl_msg_handler ip_rt_rtnl_msg_handlers[] __initconst = {
3636+
{.protocol = PF_INET, .msgtype = RTM_GETROUTE,
3637+
.doit = inet_rtm_getroute, .flags = RTNL_FLAG_DOIT_UNLOCKED},
3638+
};
3639+
36353640
int __init ip_rt_init(void)
36363641
{
36373642
void *idents_hash;
@@ -3689,8 +3694,7 @@ int __init ip_rt_init(void)
36893694
xfrm_init();
36903695
xfrm4_init();
36913696
#endif
3692-
rtnl_register(PF_INET, RTM_GETROUTE, inet_rtm_getroute, NULL,
3693-
RTNL_FLAG_DOIT_UNLOCKED);
3697+
rtnl_register_many(ip_rt_rtnl_msg_handlers);
36943698

36953699
#ifdef CONFIG_SYSCTL
36963700
register_pernet_subsys(&sysctl_route_ops);

0 commit comments

Comments
 (0)