Skip to content

Commit 3ac84e3

Browse files
q2venkuba-moo
authored andcommitted
ipmr: Use rtnl_register_many().
We will remove rtnl_register() and rtnl_register_module() in favour of rtnl_register_many(). When it succeeds for built-in callers, 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-9-kuniyu@amazon.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent a37b0e4 commit 3ac84e3

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

net/ipv4/ipmr.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,6 +3137,17 @@ static struct pernet_operations ipmr_net_ops = {
31373137
.exit_batch = ipmr_net_exit_batch,
31383138
};
31393139

3140+
static const struct rtnl_msg_handler ipmr_rtnl_msg_handlers[] __initconst = {
3141+
{.protocol = RTNL_FAMILY_IPMR, .msgtype = RTM_GETLINK,
3142+
.dumpit = ipmr_rtm_dumplink},
3143+
{.protocol = RTNL_FAMILY_IPMR, .msgtype = RTM_NEWROUTE,
3144+
.doit = ipmr_rtm_route},
3145+
{.protocol = RTNL_FAMILY_IPMR, .msgtype = RTM_DELROUTE,
3146+
.doit = ipmr_rtm_route},
3147+
{.protocol = RTNL_FAMILY_IPMR, .msgtype = RTM_GETROUTE,
3148+
.doit = ipmr_rtm_getroute, .dumpit = ipmr_rtm_dumproute},
3149+
};
3150+
31403151
int __init ip_mr_init(void)
31413152
{
31423153
int err;
@@ -3157,15 +3168,8 @@ int __init ip_mr_init(void)
31573168
goto add_proto_fail;
31583169
}
31593170
#endif
3160-
rtnl_register(RTNL_FAMILY_IPMR, RTM_GETROUTE,
3161-
ipmr_rtm_getroute, ipmr_rtm_dumproute, 0);
3162-
rtnl_register(RTNL_FAMILY_IPMR, RTM_NEWROUTE,
3163-
ipmr_rtm_route, NULL, 0);
3164-
rtnl_register(RTNL_FAMILY_IPMR, RTM_DELROUTE,
3165-
ipmr_rtm_route, NULL, 0);
3166-
3167-
rtnl_register(RTNL_FAMILY_IPMR, RTM_GETLINK,
3168-
NULL, ipmr_rtm_dumplink, 0);
3171+
rtnl_register_many(ipmr_rtnl_msg_handlers);
3172+
31693173
return 0;
31703174

31713175
#ifdef CONFIG_IP_PIMSM_V2

net/ipv6/ip6mr.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,12 @@ static struct pernet_operations ip6mr_net_ops = {
13671367
.exit_batch = ip6mr_net_exit_batch,
13681368
};
13691369

1370+
static const struct rtnl_msg_handler ip6mr_rtnl_msg_handlers[] __initconst_or_module = {
1371+
{.owner = THIS_MODULE, .protocol = RTNL_FAMILY_IP6MR,
1372+
.msgtype = RTM_GETROUTE,
1373+
.doit = ip6mr_rtm_getroute, .dumpit = ip6mr_rtm_dumproute},
1374+
};
1375+
13701376
int __init ip6_mr_init(void)
13711377
{
13721378
int err;
@@ -1389,9 +1395,8 @@ int __init ip6_mr_init(void)
13891395
goto add_proto_fail;
13901396
}
13911397
#endif
1392-
err = rtnl_register_module(THIS_MODULE, RTNL_FAMILY_IP6MR, RTM_GETROUTE,
1393-
ip6mr_rtm_getroute, ip6mr_rtm_dumproute, 0);
1394-
if (err == 0)
1398+
err = rtnl_register_many(ip6mr_rtnl_msg_handlers);
1399+
if (!err)
13951400
return 0;
13961401

13971402
#ifdef CONFIG_IPV6_PIMSM_V2
@@ -1408,7 +1413,7 @@ int __init ip6_mr_init(void)
14081413

14091414
void ip6_mr_cleanup(void)
14101415
{
1411-
rtnl_unregister(RTNL_FAMILY_IP6MR, RTM_GETROUTE);
1416+
rtnl_unregister_many(ip6mr_rtnl_msg_handlers);
14121417
#ifdef CONFIG_IPV6_PIMSM_V2
14131418
inet6_del_protocol(&pim6_protocol, IPPROTO_PIM);
14141419
#endif

0 commit comments

Comments
 (0)