Skip to content

Commit

Permalink
ipmr: Use rtnl_register_many().
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kuniyuki Iwashima authored and Jakub Kicinski committed Oct 16, 2024
1 parent a37b0e4 commit 3ac84e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
22 changes: 13 additions & 9 deletions net/ipv4/ipmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3137,6 +3137,17 @@ static struct pernet_operations ipmr_net_ops = {
.exit_batch = ipmr_net_exit_batch,
};

static const struct rtnl_msg_handler ipmr_rtnl_msg_handlers[] __initconst = {
{.protocol = RTNL_FAMILY_IPMR, .msgtype = RTM_GETLINK,
.dumpit = ipmr_rtm_dumplink},
{.protocol = RTNL_FAMILY_IPMR, .msgtype = RTM_NEWROUTE,
.doit = ipmr_rtm_route},
{.protocol = RTNL_FAMILY_IPMR, .msgtype = RTM_DELROUTE,
.doit = ipmr_rtm_route},
{.protocol = RTNL_FAMILY_IPMR, .msgtype = RTM_GETROUTE,
.doit = ipmr_rtm_getroute, .dumpit = ipmr_rtm_dumproute},
};

int __init ip_mr_init(void)
{
int err;
Expand All @@ -3157,15 +3168,8 @@ int __init ip_mr_init(void)
goto add_proto_fail;
}
#endif
rtnl_register(RTNL_FAMILY_IPMR, RTM_GETROUTE,
ipmr_rtm_getroute, ipmr_rtm_dumproute, 0);
rtnl_register(RTNL_FAMILY_IPMR, RTM_NEWROUTE,
ipmr_rtm_route, NULL, 0);
rtnl_register(RTNL_FAMILY_IPMR, RTM_DELROUTE,
ipmr_rtm_route, NULL, 0);

rtnl_register(RTNL_FAMILY_IPMR, RTM_GETLINK,
NULL, ipmr_rtm_dumplink, 0);
rtnl_register_many(ipmr_rtnl_msg_handlers);

return 0;

#ifdef CONFIG_IP_PIMSM_V2
Expand Down
13 changes: 9 additions & 4 deletions net/ipv6/ip6mr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,12 @@ static struct pernet_operations ip6mr_net_ops = {
.exit_batch = ip6mr_net_exit_batch,
};

static const struct rtnl_msg_handler ip6mr_rtnl_msg_handlers[] __initconst_or_module = {
{.owner = THIS_MODULE, .protocol = RTNL_FAMILY_IP6MR,
.msgtype = RTM_GETROUTE,
.doit = ip6mr_rtm_getroute, .dumpit = ip6mr_rtm_dumproute},
};

int __init ip6_mr_init(void)
{
int err;
Expand All @@ -1389,9 +1395,8 @@ int __init ip6_mr_init(void)
goto add_proto_fail;
}
#endif
err = rtnl_register_module(THIS_MODULE, RTNL_FAMILY_IP6MR, RTM_GETROUTE,
ip6mr_rtm_getroute, ip6mr_rtm_dumproute, 0);
if (err == 0)
err = rtnl_register_many(ip6mr_rtnl_msg_handlers);
if (!err)
return 0;

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

void ip6_mr_cleanup(void)
{
rtnl_unregister(RTNL_FAMILY_IP6MR, RTM_GETROUTE);
rtnl_unregister_many(ip6mr_rtnl_msg_handlers);
#ifdef CONFIG_IPV6_PIMSM_V2
inet6_del_protocol(&pim6_protocol, IPPROTO_PIM);
#endif
Expand Down

0 comments on commit 3ac84e3

Please sign in to comment.