* [PATCH v1 net-next 01/11] rtnetlink: Panic when __rtnl_register_many() fails for builtin callers.
2024-10-11 22:05 [PATCH v1 net-next 00/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
@ 2024-10-11 22:05 ` Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 02/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
` (9 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-11 22:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
We will replace all rtnl_register() and rtnl_register_module() with
rtnl_register_many().
Currently, rtnl_register() returns nothing and prints an error message
when it fails to register a rtnetlink message type and handlers.
The failure happens only when rtnl_register_internal() fails to allocate
rtnl_msg_handlers[protocol][msgtype], but it's unlikely for built-in
callers on boot time.
rtnl_register_many() unwinds the previous successful registrations on
failure and returns an error, but it will be useless for built-in callers,
especially some subsystems that do not have the legacy ioctl() interface
and do not work without rtnetlink.
Instead of booting up without rtnetlink functionality, let's panic on
failure for built-in rtnl_register_many() callers.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
net/core/rtnetlink.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index edcb6d43723e..8f2cdb0de4a9 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -464,6 +464,10 @@ int __rtnl_register_many(const struct rtnl_msg_handler *handlers, int n)
handler->msgtype, handler->doit,
handler->dumpit, handler->flags);
if (err) {
+ if (!handler->owner)
+ panic("Unable to register rtnetlink message "
+ "handlers, %pS\n", handlers);
+
__rtnl_unregister_many(handlers, i);
break;
}
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 02/11] rtnetlink: Use rtnl_register_many().
2024-10-11 22:05 [PATCH v1 net-next 00/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 01/11] rtnetlink: Panic when __rtnl_register_many() fails for builtin callers Kuniyuki Iwashima
@ 2024-10-11 22:05 ` Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 03/11] neighbour: " Kuniyuki Iwashima
` (8 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-11 22:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
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>
---
net/core/rtnetlink.c | 57 +++++++++++++++++++++-----------------------
1 file changed, 27 insertions(+), 30 deletions(-)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 8f2cdb0de4a9..edaafdcd24ad 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -6843,6 +6843,32 @@ static struct pernet_operations rtnetlink_net_ops = {
.exit = rtnetlink_net_exit,
};
+static const struct rtnl_msg_handler rtnetlink_rtnl_msg_handlers[] = {
+ {NULL, PF_UNSPEC, RTM_NEWLINK, rtnl_newlink, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_DELLINK, rtnl_dellink, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_GETLINK, rtnl_getlink, rtnl_dump_ifinfo,
+ RTNL_FLAG_DUMP_SPLIT_NLM_DONE},
+ {NULL, PF_UNSPEC, RTM_SETLINK, rtnl_setlink, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_GETADDR, NULL, rtnl_dump_all, 0},
+ {NULL, PF_UNSPEC, RTM_GETROUTE, NULL, rtnl_dump_all, 0},
+ {NULL, PF_UNSPEC, RTM_GETNETCONF, NULL, rtnl_dump_all, 0},
+ {NULL, PF_UNSPEC, RTM_GETSTATS, rtnl_stats_get, rtnl_stats_dump, 0},
+ {NULL, PF_UNSPEC, RTM_SETSTATS, rtnl_stats_set, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_NEWLINKPROP, rtnl_newlinkprop, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_DELLINKPROP, rtnl_dellinkprop, NULL, 0},
+ {NULL, PF_BRIDGE, RTM_GETLINK, NULL, rtnl_bridge_getlink, 0},
+ {NULL, PF_BRIDGE, RTM_DELLINK, rtnl_bridge_dellink, NULL, 0},
+ {NULL, PF_BRIDGE, RTM_SETLINK, rtnl_bridge_setlink, NULL, 0},
+ {NULL, PF_BRIDGE, RTM_NEWNEIGH, rtnl_fdb_add, NULL, 0},
+ {NULL, PF_BRIDGE, RTM_DELNEIGH, rtnl_fdb_del, NULL,
+ RTNL_FLAG_BULK_DEL_SUPPORTED},
+ {NULL, PF_BRIDGE, RTM_GETNEIGH, rtnl_fdb_get, rtnl_fdb_dump, 0},
+ {NULL, PF_BRIDGE, RTM_NEWMDB, rtnl_mdb_add, NULL, 0},
+ {NULL, PF_BRIDGE, RTM_DELMDB, rtnl_mdb_del, NULL,
+ RTNL_FLAG_BULK_DEL_SUPPORTED},
+ {NULL, PF_BRIDGE, RTM_GETMDB, rtnl_mdb_get, rtnl_mdb_dump, 0},
+};
+
void __init rtnetlink_init(void)
{
if (register_pernet_subsys(&rtnetlink_net_ops))
@@ -6850,34 +6876,5 @@ void __init rtnetlink_init(void)
register_netdevice_notifier(&rtnetlink_dev_notifier);
- rtnl_register(PF_UNSPEC, RTM_GETLINK, rtnl_getlink,
- rtnl_dump_ifinfo, RTNL_FLAG_DUMP_SPLIT_NLM_DONE);
- rtnl_register(PF_UNSPEC, RTM_SETLINK, rtnl_setlink, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_NEWLINK, rtnl_newlink, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_DELLINK, rtnl_dellink, NULL, 0);
-
- rtnl_register(PF_UNSPEC, RTM_GETADDR, NULL, rtnl_dump_all, 0);
- rtnl_register(PF_UNSPEC, RTM_GETROUTE, NULL, rtnl_dump_all, 0);
- rtnl_register(PF_UNSPEC, RTM_GETNETCONF, NULL, rtnl_dump_all, 0);
-
- rtnl_register(PF_UNSPEC, RTM_NEWLINKPROP, rtnl_newlinkprop, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_DELLINKPROP, rtnl_dellinkprop, NULL, 0);
-
- rtnl_register(PF_BRIDGE, RTM_NEWNEIGH, rtnl_fdb_add, NULL, 0);
- rtnl_register(PF_BRIDGE, RTM_DELNEIGH, rtnl_fdb_del, NULL,
- RTNL_FLAG_BULK_DEL_SUPPORTED);
- rtnl_register(PF_BRIDGE, RTM_GETNEIGH, rtnl_fdb_get, rtnl_fdb_dump, 0);
-
- rtnl_register(PF_BRIDGE, RTM_GETLINK, NULL, rtnl_bridge_getlink, 0);
- rtnl_register(PF_BRIDGE, RTM_DELLINK, rtnl_bridge_dellink, NULL, 0);
- rtnl_register(PF_BRIDGE, RTM_SETLINK, rtnl_bridge_setlink, NULL, 0);
-
- rtnl_register(PF_UNSPEC, RTM_GETSTATS, rtnl_stats_get, rtnl_stats_dump,
- 0);
- rtnl_register(PF_UNSPEC, RTM_SETSTATS, rtnl_stats_set, NULL, 0);
-
- rtnl_register(PF_BRIDGE, RTM_GETMDB, rtnl_mdb_get, rtnl_mdb_dump, 0);
- rtnl_register(PF_BRIDGE, RTM_NEWMDB, rtnl_mdb_add, NULL, 0);
- rtnl_register(PF_BRIDGE, RTM_DELMDB, rtnl_mdb_del, NULL,
- RTNL_FLAG_BULK_DEL_SUPPORTED);
+ rtnl_register_many(rtnetlink_rtnl_msg_handlers);
}
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 03/11] neighbour: Use rtnl_register_many().
2024-10-11 22:05 [PATCH v1 net-next 00/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 01/11] rtnetlink: Panic when __rtnl_register_many() fails for builtin callers Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 02/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
@ 2024-10-11 22:05 ` Kuniyuki Iwashima
2024-10-14 8:01 ` Eric Dumazet
2024-10-11 22:05 ` [PATCH v1 net-next 04/11] net: sched: " Kuniyuki Iwashima
` (7 subsequent siblings)
10 siblings, 1 reply; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-11 22:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
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>
---
net/core/neighbour.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 77b819cd995b..f6137ee80965 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -3886,17 +3886,18 @@ EXPORT_SYMBOL(neigh_sysctl_unregister);
#endif /* CONFIG_SYSCTL */
+static const struct rtnl_msg_handler neigh_rtnl_msg_handlers[] = {
+ {NULL, PF_UNSPEC, RTM_NEWNEIGH, neigh_add, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_DELNEIGH, neigh_delete, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_GETNEIGH, neigh_get, neigh_dump_info,
+ RTNL_FLAG_DUMP_UNLOCKED},
+ {NULL, PF_UNSPEC, RTM_GETNEIGHTBL, NULL, neightbl_dump_info, 0},
+ {NULL, PF_UNSPEC, RTM_SETNEIGHTBL, neightbl_set, NULL, 0},
+};
+
static int __init neigh_init(void)
{
- rtnl_register(PF_UNSPEC, RTM_NEWNEIGH, neigh_add, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_DELNEIGH, neigh_delete, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_GETNEIGH, neigh_get, neigh_dump_info,
- RTNL_FLAG_DUMP_UNLOCKED);
-
- rtnl_register(PF_UNSPEC, RTM_GETNEIGHTBL, NULL, neightbl_dump_info,
- 0);
- rtnl_register(PF_UNSPEC, RTM_SETNEIGHTBL, neightbl_set, NULL, 0);
-
+ rtnl_register_many(neigh_rtnl_msg_handlers);
return 0;
}
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v1 net-next 03/11] neighbour: Use rtnl_register_many().
2024-10-11 22:05 ` [PATCH v1 net-next 03/11] neighbour: " Kuniyuki Iwashima
@ 2024-10-14 8:01 ` Eric Dumazet
2024-10-14 17:35 ` Kuniyuki Iwashima
0 siblings, 1 reply; 14+ messages in thread
From: Eric Dumazet @ 2024-10-14 8:01 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, Kuniyuki Iwashima,
netdev
On Sat, Oct 12, 2024 at 12:06 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> 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>
> ---
> net/core/neighbour.c | 19 ++++++++++---------
> 1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/net/core/neighbour.c b/net/core/neighbour.c
> index 77b819cd995b..f6137ee80965 100644
> --- a/net/core/neighbour.c
> +++ b/net/core/neighbour.c
> @@ -3886,17 +3886,18 @@ EXPORT_SYMBOL(neigh_sysctl_unregister);
>
> #endif /* CONFIG_SYSCTL */
>
> +static const struct rtnl_msg_handler neigh_rtnl_msg_handlers[] = {
> + {NULL, PF_UNSPEC, RTM_NEWNEIGH, neigh_add, NULL, 0},
> + {NULL, PF_UNSPEC, RTM_DELNEIGH, neigh_delete, NULL, 0},
> + {NULL, PF_UNSPEC, RTM_GETNEIGH, neigh_get, neigh_dump_info,
> + RTNL_FLAG_DUMP_UNLOCKED},
> + {NULL, PF_UNSPEC, RTM_GETNEIGHTBL, NULL, neightbl_dump_info, 0},
> + {NULL, PF_UNSPEC, RTM_SETNEIGHTBL, neightbl_set, NULL, 0},
> +};
> +
Please add __initconst qualifier.
Also C99 initializations look better to me.
+static const struct rtnl_msg_handler neigh_rtnl_msg_handlers[] __initconst = {
+ {.msgtype = RTM_NEWNEIGH, .doit = neigh_add},
+ {.msgtype = RTM_DELNEIGH, .doit = neigh_delete},
+ {.msgtype = RTM_GETNEIGH, .doit = neigh_get,
+ .dumpit = neigh_dump_info, .flags = RTNL_FLAG_DUMP_UNLOCKED},
+ {.msgtype = RTM_GETNEIGHTBL, .dumpit = neightbl_dump_info},
+ {.msgtype = RTM_SETNEIGHTBL, .doit = neightbl_set},
+};
+
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v1 net-next 03/11] neighbour: Use rtnl_register_many().
2024-10-14 8:01 ` Eric Dumazet
@ 2024-10-14 17:35 ` Kuniyuki Iwashima
0 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-14 17:35 UTC (permalink / raw)
To: edumazet; +Cc: davem, kuba, kuni1840, kuniyu, netdev, pabeni
From: Eric Dumazet <edumazet@google.com>
Date: Mon, 14 Oct 2024 10:01:54 +0200
> > +static const struct rtnl_msg_handler neigh_rtnl_msg_handlers[] = {
> > + {NULL, PF_UNSPEC, RTM_NEWNEIGH, neigh_add, NULL, 0},
> > + {NULL, PF_UNSPEC, RTM_DELNEIGH, neigh_delete, NULL, 0},
> > + {NULL, PF_UNSPEC, RTM_GETNEIGH, neigh_get, neigh_dump_info,
> > + RTNL_FLAG_DUMP_UNLOCKED},
> > + {NULL, PF_UNSPEC, RTM_GETNEIGHTBL, NULL, neightbl_dump_info, 0},
> > + {NULL, PF_UNSPEC, RTM_SETNEIGHTBL, neightbl_set, NULL, 0},
> > +};
> > +
>
> Please add __initconst qualifier.
Sure, will add it for other built-in files too.
>
> Also C99 initializations look better to me.
Exactly, I just double-checked PF_UNSPEC is 0 :)
For some modules that already have the older style,
I'll change them to C99 style when I convert each handlers.
Thanks!
>
> +static const struct rtnl_msg_handler neigh_rtnl_msg_handlers[] __initconst = {
> + {.msgtype = RTM_NEWNEIGH, .doit = neigh_add},
> + {.msgtype = RTM_DELNEIGH, .doit = neigh_delete},
> + {.msgtype = RTM_GETNEIGH, .doit = neigh_get,
> + .dumpit = neigh_dump_info, .flags = RTNL_FLAG_DUMP_UNLOCKED},
> + {.msgtype = RTM_GETNEIGHTBL, .dumpit = neightbl_dump_info},
> + {.msgtype = RTM_SETNEIGHTBL, .doit = neightbl_set},
> +};
> +
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v1 net-next 04/11] net: sched: Use rtnl_register_many().
2024-10-11 22:05 [PATCH v1 net-next 00/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
` (2 preceding siblings ...)
2024-10-11 22:05 ` [PATCH v1 net-next 03/11] neighbour: " Kuniyuki Iwashima
@ 2024-10-11 22:05 ` Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 05/11] net: " Kuniyuki Iwashima
` (6 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-11 22:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev, Jamal Hadi Salim,
Cong Wang, Jiri Pirko
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>
---
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Jiri Pirko <jiri@resnulli.us>
---
net/sched/act_api.c | 12 +++++++-----
net/sched/cls_api.c | 24 +++++++++++++-----------
net/sched/sch_api.c | 18 ++++++++++--------
3 files changed, 30 insertions(+), 24 deletions(-)
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 2714c4ed928e..1caaeef90684 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -2243,13 +2243,15 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
return skb->len;
}
+static const struct rtnl_msg_handler tc_action_rtnl_msg_handlers[] = {
+ {NULL, PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action, 0},
+};
+
static int __init tc_action_init(void)
{
- rtnl_register(PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action,
- 0);
-
+ rtnl_register_many(tc_action_rtnl_msg_handlers);
return 0;
}
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 17d97bbe890f..2d9961e6b019 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -4055,6 +4055,18 @@ static struct pernet_operations tcf_net_ops = {
.size = sizeof(struct tcf_net),
};
+static const struct rtnl_msg_handler tc_filter_rtnl_msg_handlers[] = {
+ {NULL, PF_UNSPEC, RTM_NEWTFILTER, tc_new_tfilter, NULL,
+ RTNL_FLAG_DOIT_UNLOCKED},
+ {NULL, PF_UNSPEC, RTM_DELTFILTER, tc_del_tfilter, NULL,
+ RTNL_FLAG_DOIT_UNLOCKED},
+ {NULL, PF_UNSPEC, RTM_GETTFILTER, tc_get_tfilter, tc_dump_tfilter,
+ RTNL_FLAG_DOIT_UNLOCKED},
+ {NULL, PF_UNSPEC, RTM_NEWCHAIN, tc_ctl_chain, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_DELCHAIN, tc_ctl_chain, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_GETCHAIN, tc_ctl_chain, tc_dump_chain, 0},
+};
+
static int __init tc_filter_init(void)
{
int err;
@@ -4068,17 +4080,7 @@ static int __init tc_filter_init(void)
goto err_register_pernet_subsys;
xa_init_flags(&tcf_exts_miss_cookies_xa, XA_FLAGS_ALLOC1);
-
- rtnl_register(PF_UNSPEC, RTM_NEWTFILTER, tc_new_tfilter, NULL,
- RTNL_FLAG_DOIT_UNLOCKED);
- rtnl_register(PF_UNSPEC, RTM_DELTFILTER, tc_del_tfilter, NULL,
- RTNL_FLAG_DOIT_UNLOCKED);
- rtnl_register(PF_UNSPEC, RTM_GETTFILTER, tc_get_tfilter,
- tc_dump_tfilter, RTNL_FLAG_DOIT_UNLOCKED);
- rtnl_register(PF_UNSPEC, RTM_NEWCHAIN, tc_ctl_chain, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_DELCHAIN, tc_ctl_chain, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_GETCHAIN, tc_ctl_chain,
- tc_dump_chain, 0);
+ rtnl_register_many(tc_filter_rtnl_msg_handlers);
return 0;
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 2eefa4783879..e475f767bcfb 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -2420,6 +2420,15 @@ static struct pernet_operations psched_net_ops = {
DEFINE_STATIC_KEY_FALSE(tc_skip_wrapper);
#endif
+static const struct rtnl_msg_handler psched_rtnl_msg_handlers[] = {
+ {NULL, PF_UNSPEC, RTM_NEWQDISC, tc_modify_qdisc, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_DELQDISC, tc_get_qdisc, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_GETQDISC, tc_get_qdisc, tc_dump_qdisc, 0},
+ {NULL, PF_UNSPEC, RTM_NEWTCLASS, tc_ctl_tclass, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_DELTCLASS, tc_ctl_tclass, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_GETTCLASS, tc_ctl_tclass, tc_dump_tclass, 0},
+};
+
static int __init pktsched_init(void)
{
int err;
@@ -2438,14 +2447,7 @@ static int __init pktsched_init(void)
register_qdisc(&mq_qdisc_ops);
register_qdisc(&noqueue_qdisc_ops);
- rtnl_register(PF_UNSPEC, RTM_NEWQDISC, tc_modify_qdisc, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_DELQDISC, tc_get_qdisc, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_GETQDISC, tc_get_qdisc, tc_dump_qdisc,
- 0);
- rtnl_register(PF_UNSPEC, RTM_NEWTCLASS, tc_ctl_tclass, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_DELTCLASS, tc_ctl_tclass, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_GETTCLASS, tc_ctl_tclass, tc_dump_tclass,
- 0);
+ rtnl_register_many(psched_rtnl_msg_handlers);
tc_wrapper_init();
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 05/11] net: Use rtnl_register_many().
2024-10-11 22:05 [PATCH v1 net-next 00/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
` (3 preceding siblings ...)
2024-10-11 22:05 ` [PATCH v1 net-next 04/11] net: sched: " Kuniyuki Iwashima
@ 2024-10-11 22:05 ` Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 06/11] ipv4: " Kuniyuki Iwashima
` (5 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-11 22:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
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>
---
net/core/net_namespace.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 0a86aff17f51..488ea2f9e6bc 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -1169,6 +1169,13 @@ static void __init netns_ipv4_struct_check(void)
}
#endif
+static const struct rtnl_msg_handler net_ns_rtnl_msg_handlers[] = {
+ {NULL, PF_UNSPEC, RTM_NEWNSID, rtnl_net_newid, NULL,
+ RTNL_FLAG_DOIT_UNLOCKED},
+ {NULL, PF_UNSPEC, RTM_GETNSID, rtnl_net_getid, rtnl_net_dumpid,
+ RTNL_FLAG_DOIT_UNLOCKED | RTNL_FLAG_DUMP_UNLOCKED },
+};
+
void __init net_ns_init(void)
{
struct net_generic *ng;
@@ -1206,11 +1213,7 @@ void __init net_ns_init(void)
if (register_pernet_subsys(&net_ns_ops))
panic("Could not register network namespace subsystems");
- rtnl_register(PF_UNSPEC, RTM_NEWNSID, rtnl_net_newid, NULL,
- RTNL_FLAG_DOIT_UNLOCKED);
- rtnl_register(PF_UNSPEC, RTM_GETNSID, rtnl_net_getid, rtnl_net_dumpid,
- RTNL_FLAG_DOIT_UNLOCKED |
- RTNL_FLAG_DUMP_UNLOCKED);
+ rtnl_register_many(net_ns_rtnl_msg_handlers);
}
static void free_exit_list(struct pernet_operations *ops, struct list_head *net_exit_list)
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 06/11] ipv4: Use rtnl_register_many().
2024-10-11 22:05 [PATCH v1 net-next 00/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
` (4 preceding siblings ...)
2024-10-11 22:05 ` [PATCH v1 net-next 05/11] net: " Kuniyuki Iwashima
@ 2024-10-11 22:05 ` Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 07/11] ipv6: " Kuniyuki Iwashima
` (4 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-11 22:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
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>
---
net/ipv4/devinet.c | 18 +++++++++++-------
net/ipv4/fib_frontend.c | 12 ++++++++----
net/ipv4/nexthop.c | 26 +++++++++++++-------------
net/ipv4/route.c | 8 ++++++--
4 files changed, 38 insertions(+), 26 deletions(-)
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 7c156f85b7d2..10119cc92a77 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -2797,6 +2797,16 @@ static struct rtnl_af_ops inet_af_ops __read_mostly = {
.set_link_af = inet_set_link_af,
};
+static const struct rtnl_msg_handler devinet_rtnl_msg_handlers[] = {
+ {NULL, PF_INET, RTM_NEWADDR, inet_rtm_newaddr, NULL, 0},
+ {NULL, PF_INET, RTM_DELADDR, inet_rtm_deladdr, NULL, 0},
+ {NULL, PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr,
+ RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE},
+ {NULL, PF_INET, RTM_GETNETCONF,
+ inet_netconf_get_devconf, inet_netconf_dump_devconf,
+ RTNL_FLAG_DOIT_UNLOCKED | RTNL_FLAG_DUMP_UNLOCKED},
+};
+
void __init devinet_init(void)
{
register_pernet_subsys(&devinet_ops);
@@ -2804,11 +2814,5 @@ void __init devinet_init(void)
rtnl_af_register(&inet_af_ops);
- rtnl_register(PF_INET, RTM_NEWADDR, inet_rtm_newaddr, NULL, 0);
- rtnl_register(PF_INET, RTM_DELADDR, inet_rtm_deladdr, NULL, 0);
- rtnl_register(PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr,
- RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE);
- rtnl_register(PF_INET, RTM_GETNETCONF, inet_netconf_get_devconf,
- inet_netconf_dump_devconf,
- RTNL_FLAG_DOIT_UNLOCKED | RTNL_FLAG_DUMP_UNLOCKED);
+ rtnl_register_many(devinet_rtnl_msg_handlers);
}
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index 8353518b110a..f710cb99df02 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -1649,6 +1649,13 @@ static struct pernet_operations fib_net_ops = {
.exit_batch = fib_net_exit_batch,
};
+static const struct rtnl_msg_handler fib_rtnl_msg_handlers[] = {
+ {NULL, PF_INET, RTM_NEWROUTE, inet_rtm_newroute, NULL, 0},
+ {NULL, PF_INET, RTM_DELROUTE, inet_rtm_delroute, NULL, 0},
+ {NULL, PF_INET, RTM_GETROUTE, NULL, inet_dump_fib,
+ RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE},
+};
+
void __init ip_fib_init(void)
{
fib_trie_init();
@@ -1658,8 +1665,5 @@ void __init ip_fib_init(void)
register_netdevice_notifier(&fib_netdev_notifier);
register_inetaddr_notifier(&fib_inetaddr_notifier);
- rtnl_register(PF_INET, RTM_NEWROUTE, inet_rtm_newroute, NULL, 0);
- rtnl_register(PF_INET, RTM_DELROUTE, inet_rtm_delroute, NULL, 0);
- rtnl_register(PF_INET, RTM_GETROUTE, NULL, inet_dump_fib,
- RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE);
+ rtnl_register_many(fib_rtnl_msg_handlers);
}
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 93aaea0006ba..925602f722fc 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -4042,25 +4042,25 @@ static struct pernet_operations nexthop_net_ops = {
.exit_batch_rtnl = nexthop_net_exit_batch_rtnl,
};
+static const struct rtnl_msg_handler nexthop_rtnl_msg_handlers[] = {
+ {NULL, PF_UNSPEC, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_DELNEXTHOP, rtm_del_nexthop, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_GETNEXTHOP, rtm_get_nexthop, rtm_dump_nexthop, 0},
+ {NULL, PF_UNSPEC, RTM_GETNEXTHOPBUCKET,
+ rtm_get_nexthop_bucket, rtm_dump_nexthop_bucket, 0},
+ {NULL, PF_INET, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0},
+ {NULL, PF_INET, RTM_GETNEXTHOP, NULL, rtm_dump_nexthop, 0},
+ {NULL, PF_INET6, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0},
+ {NULL, PF_INET6, RTM_GETNEXTHOP, NULL, rtm_dump_nexthop, 0},
+};
+
static int __init nexthop_init(void)
{
register_pernet_subsys(&nexthop_net_ops);
register_netdevice_notifier(&nh_netdev_notifier);
- rtnl_register(PF_UNSPEC, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_DELNEXTHOP, rtm_del_nexthop, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_GETNEXTHOP, rtm_get_nexthop,
- rtm_dump_nexthop, 0);
-
- rtnl_register(PF_INET, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0);
- rtnl_register(PF_INET, RTM_GETNEXTHOP, NULL, rtm_dump_nexthop, 0);
-
- rtnl_register(PF_INET6, RTM_NEWNEXTHOP, rtm_new_nexthop, NULL, 0);
- rtnl_register(PF_INET6, RTM_GETNEXTHOP, NULL, rtm_dump_nexthop, 0);
-
- rtnl_register(PF_UNSPEC, RTM_GETNEXTHOPBUCKET, rtm_get_nexthop_bucket,
- rtm_dump_nexthop_bucket, 0);
+ rtnl_register_many(nexthop_rtnl_msg_handlers);
return 0;
}
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index a0b091a7df87..63269870b6fc 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -3632,6 +3632,11 @@ static __net_initdata struct pernet_operations ipv4_inetpeer_ops = {
struct ip_rt_acct __percpu *ip_rt_acct __read_mostly;
#endif /* CONFIG_IP_ROUTE_CLASSID */
+static const struct rtnl_msg_handler ip_rt_rtnl_msg_handlers[] = {
+ {NULL, PF_INET, RTM_GETROUTE, inet_rtm_getroute, NULL,
+ RTNL_FLAG_DOIT_UNLOCKED},
+};
+
int __init ip_rt_init(void)
{
void *idents_hash;
@@ -3689,8 +3694,7 @@ int __init ip_rt_init(void)
xfrm_init();
xfrm4_init();
#endif
- rtnl_register(PF_INET, RTM_GETROUTE, inet_rtm_getroute, NULL,
- RTNL_FLAG_DOIT_UNLOCKED);
+ rtnl_register_many(ip_rt_rtnl_msg_handlers);
#ifdef CONFIG_SYSCTL
register_pernet_subsys(&sysctl_route_ops);
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 07/11] ipv6: Use rtnl_register_many().
2024-10-11 22:05 [PATCH v1 net-next 00/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
` (5 preceding siblings ...)
2024-10-11 22:05 ` [PATCH v1 net-next 06/11] ipv4: " Kuniyuki Iwashima
@ 2024-10-11 22:05 ` Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 08/11] ipmr: " Kuniyuki Iwashima
` (3 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-11 22:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
We will remove rtnl_register_module() in favour of rtnl_register_many().
rtnl_register_many() will unwind the previous successful registrations
on failure and simplify module error handling.
Let's use rtnl_register_many() instead.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
net/core/fib_rules.c | 24 ++++++++++++--------
net/ipv6/addrconf.c | 52 +++++++++++++++-----------------------------
net/ipv6/addrlabel.c | 27 +++++++++--------------
net/ipv6/ip6_fib.c | 9 +++++---
net/ipv6/route.c | 21 +++++++-----------
5 files changed, 57 insertions(+), 76 deletions(-)
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 154a2681f55c..7ed6f9928604 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -1289,17 +1289,24 @@ static struct pernet_operations fib_rules_net_ops = {
.exit = fib_rules_net_exit,
};
+static const struct rtnl_msg_handler fib_rules_rtnl_msg_handlers[] = {
+ {NULL, PF_UNSPEC, RTM_NEWRULE, fib_nl_newrule, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_DELRULE, fib_nl_delrule, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_GETRULE, NULL, fib_nl_dumprule,
+ RTNL_FLAG_DUMP_UNLOCKED},
+};
+
static int __init fib_rules_init(void)
{
int err;
- rtnl_register(PF_UNSPEC, RTM_NEWRULE, fib_nl_newrule, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_DELRULE, fib_nl_delrule, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_GETRULE, NULL, fib_nl_dumprule,
- RTNL_FLAG_DUMP_UNLOCKED);
+
+ err = rtnl_register_many(fib_rules_rtnl_msg_handlers);
+ if (err)
+ goto fail_rtnl;
err = register_pernet_subsys(&fib_rules_net_ops);
if (err < 0)
- goto fail;
+ goto fail_pernet;
err = register_netdevice_notifier(&fib_rules_notifier);
if (err < 0)
@@ -1309,10 +1316,9 @@ static int __init fib_rules_init(void)
fail_unregister:
unregister_pernet_subsys(&fib_rules_net_ops);
-fail:
- rtnl_unregister(PF_UNSPEC, RTM_NEWRULE);
- rtnl_unregister(PF_UNSPEC, RTM_DELRULE);
- rtnl_unregister(PF_UNSPEC, RTM_GETRULE);
+fail_pernet:
+ rtnl_unregister_many(fib_rules_rtnl_msg_handlers);
+fail_rtnl:
return err;
}
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index f31528d4f694..020519362b33 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -7406,6 +7406,22 @@ static struct rtnl_af_ops inet6_ops __read_mostly = {
.set_link_af = inet6_set_link_af,
};
+static const struct rtnl_msg_handler addrconf_rtnl_msg_handlers[] = {
+ {THIS_MODULE, PF_INET6, RTM_GETLINK, NULL, inet6_dump_ifinfo,
+ RTNL_FLAG_DUMP_UNLOCKED},
+ {THIS_MODULE, PF_INET6, RTM_NEWADDR, inet6_rtm_newaddr, NULL, 0},
+ {THIS_MODULE, PF_INET6, RTM_DELADDR, inet6_rtm_deladdr, NULL, 0},
+ {THIS_MODULE, PF_INET6, RTM_GETADDR, inet6_rtm_getaddr, inet6_dump_ifaddr,
+ RTNL_FLAG_DOIT_UNLOCKED | RTNL_FLAG_DUMP_UNLOCKED},
+ {THIS_MODULE, PF_INET6, RTM_GETMULTICAST, NULL, inet6_dump_ifmcaddr,
+ RTNL_FLAG_DUMP_UNLOCKED},
+ {THIS_MODULE, PF_INET6, RTM_GETANYCAST, NULL, inet6_dump_ifacaddr,
+ RTNL_FLAG_DUMP_UNLOCKED},
+ {THIS_MODULE, PF_INET6, RTM_GETNETCONF,
+ inet6_netconf_get_devconf, inet6_netconf_dump_devconf,
+ RTNL_FLAG_DOIT_UNLOCKED | RTNL_FLAG_DUMP_UNLOCKED},
+};
+
/*
* Init / cleanup code
*/
@@ -7449,42 +7465,10 @@ int __init addrconf_init(void)
rtnl_af_register(&inet6_ops);
- err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETLINK,
- NULL, inet6_dump_ifinfo, RTNL_FLAG_DUMP_UNLOCKED);
- if (err < 0)
+ err = rtnl_register_many(addrconf_rtnl_msg_handlers);
+ if (err)
goto errout;
- err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_NEWADDR,
- inet6_rtm_newaddr, NULL, 0);
- if (err < 0)
- goto errout;
- err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_DELADDR,
- inet6_rtm_deladdr, NULL, 0);
- if (err < 0)
- goto errout;
- err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETADDR,
- inet6_rtm_getaddr, inet6_dump_ifaddr,
- RTNL_FLAG_DOIT_UNLOCKED |
- RTNL_FLAG_DUMP_UNLOCKED);
- if (err < 0)
- goto errout;
- err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETMULTICAST,
- NULL, inet6_dump_ifmcaddr,
- RTNL_FLAG_DUMP_UNLOCKED);
- if (err < 0)
- goto errout;
- err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETANYCAST,
- NULL, inet6_dump_ifacaddr,
- RTNL_FLAG_DUMP_UNLOCKED);
- if (err < 0)
- goto errout;
- err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETNETCONF,
- inet6_netconf_get_devconf,
- inet6_netconf_dump_devconf,
- RTNL_FLAG_DOIT_UNLOCKED |
- RTNL_FLAG_DUMP_UNLOCKED);
- if (err < 0)
- goto errout;
err = ipv6_addr_label_rtnl_register();
if (err < 0)
goto errout;
diff --git a/net/ipv6/addrlabel.c b/net/ipv6/addrlabel.c
index acd70b5992a7..b31738761b0b 100644
--- a/net/ipv6/addrlabel.c
+++ b/net/ipv6/addrlabel.c
@@ -634,23 +634,16 @@ static int ip6addrlbl_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
return err;
}
+static const struct rtnl_msg_handler ipv6_adddr_label_rtnl_msg_handlers[] = {
+ {THIS_MODULE, PF_INET6, RTM_NEWADDRLABEL, ip6addrlbl_newdel, NULL,
+ RTNL_FLAG_DOIT_UNLOCKED},
+ {THIS_MODULE, PF_INET6, RTM_DELADDRLABEL, ip6addrlbl_newdel, NULL,
+ RTNL_FLAG_DOIT_UNLOCKED},
+ {THIS_MODULE, PF_INET6, RTM_GETADDRLABEL, ip6addrlbl_get, ip6addrlbl_dump,
+ RTNL_FLAG_DOIT_UNLOCKED | RTNL_FLAG_DUMP_UNLOCKED},
+};
+
int __init ipv6_addr_label_rtnl_register(void)
{
- int ret;
-
- ret = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_NEWADDRLABEL,
- ip6addrlbl_newdel,
- NULL, RTNL_FLAG_DOIT_UNLOCKED);
- if (ret < 0)
- return ret;
- ret = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_DELADDRLABEL,
- ip6addrlbl_newdel,
- NULL, RTNL_FLAG_DOIT_UNLOCKED);
- if (ret < 0)
- return ret;
- ret = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETADDRLABEL,
- ip6addrlbl_get,
- ip6addrlbl_dump, RTNL_FLAG_DOIT_UNLOCKED |
- RTNL_FLAG_DUMP_UNLOCKED);
- return ret;
+ return rtnl_register_many(ipv6_adddr_label_rtnl_msg_handlers);
}
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index eb111d20615c..b28259f23960 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -2500,6 +2500,11 @@ static struct pernet_operations fib6_net_ops = {
.exit = fib6_net_exit,
};
+static const struct rtnl_msg_handler fib6_rtnl_msg_handlers[] = {
+ {THIS_MODULE, PF_INET6, RTM_GETROUTE, NULL, inet6_dump_fib,
+ RTNL_FLAG_DUMP_UNLOCKED | RTNL_FLAG_DUMP_SPLIT_NLM_DONE},
+};
+
int __init fib6_init(void)
{
int ret = -ENOMEM;
@@ -2513,9 +2518,7 @@ int __init fib6_init(void)
if (ret)
goto out_kmem_cache_create;
- ret = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETROUTE, NULL,
- inet6_dump_fib, RTNL_FLAG_DUMP_UNLOCKED |
- RTNL_FLAG_DUMP_SPLIT_NLM_DONE);
+ ret = rtnl_register_many(fib6_rtnl_msg_handlers);
if (ret)
goto out_unregister_subsys;
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index b4251915585f..6f617c0f3db4 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -6680,6 +6680,13 @@ static void bpf_iter_unregister(void)
#endif
#endif
+static const struct rtnl_msg_handler ip6_route_rtnl_msg_handlers[] = {
+ {THIS_MODULE, PF_INET6, RTM_NEWROUTE, inet6_rtm_newroute, NULL, 0},
+ {THIS_MODULE, PF_INET6, RTM_DELROUTE, inet6_rtm_delroute, NULL, 0},
+ {THIS_MODULE, PF_INET6, RTM_GETROUTE, inet6_rtm_getroute, NULL,
+ RTNL_FLAG_DOIT_UNLOCKED},
+};
+
int __init ip6_route_init(void)
{
int ret;
@@ -6722,19 +6729,7 @@ int __init ip6_route_init(void)
if (ret)
goto fib6_rules_init;
- ret = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_NEWROUTE,
- inet6_rtm_newroute, NULL, 0);
- if (ret < 0)
- goto out_register_late_subsys;
-
- ret = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_DELROUTE,
- inet6_rtm_delroute, NULL, 0);
- if (ret < 0)
- goto out_register_late_subsys;
-
- ret = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETROUTE,
- inet6_rtm_getroute, NULL,
- RTNL_FLAG_DOIT_UNLOCKED);
+ ret = rtnl_register_many(ip6_route_rtnl_msg_handlers);
if (ret < 0)
goto out_register_late_subsys;
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 08/11] ipmr: Use rtnl_register_many().
2024-10-11 22:05 [PATCH v1 net-next 00/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
` (6 preceding siblings ...)
2024-10-11 22:05 ` [PATCH v1 net-next 07/11] ipv6: " Kuniyuki Iwashima
@ 2024-10-11 22:05 ` Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 09/11] dcb: " Kuniyuki Iwashima
` (2 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-11 22:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
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>
---
net/ipv4/ipmr.c | 19 ++++++++++---------
net/ipv6/ip6mr.c | 12 ++++++++----
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 089864c6a35e..2a5a6927229f 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -3139,6 +3139,14 @@ static struct pernet_operations ipmr_net_ops = {
.exit_batch = ipmr_net_exit_batch,
};
+static const struct rtnl_msg_handler ipmr_rtnl_msg_handlers[] = {
+ {NULL, RTNL_FAMILY_IPMR, RTM_GETLINK, NULL, ipmr_rtm_dumplink, 0},
+ {NULL, RTNL_FAMILY_IPMR, RTM_NEWROUTE, ipmr_rtm_route, NULL, 0},
+ {NULL, RTNL_FAMILY_IPMR, RTM_DELROUTE, ipmr_rtm_route, NULL, 0},
+ {NULL, RTNL_FAMILY_IPMR, RTM_GETROUTE,
+ ipmr_rtm_getroute, ipmr_rtm_dumproute, 0},
+};
+
int __init ip_mr_init(void)
{
int err;
@@ -3159,15 +3167,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
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 2ce4ae0d8dc3..8bb7bf4346f0 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -1369,6 +1369,11 @@ static struct pernet_operations ip6mr_net_ops = {
.exit_batch = ip6mr_net_exit_batch,
};
+static const struct rtnl_msg_handler ip6mr_rtnl_msg_handlers[] = {
+ {THIS_MODULE, RTNL_FAMILY_IP6MR, RTM_GETROUTE,
+ ip6mr_rtm_getroute, ip6mr_rtm_dumproute, 0},
+};
+
int __init ip6_mr_init(void)
{
int err;
@@ -1391,9 +1396,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
@@ -1410,7 +1414,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
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 09/11] dcb: Use rtnl_register_many().
2024-10-11 22:05 [PATCH v1 net-next 00/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
` (7 preceding siblings ...)
2024-10-11 22:05 ` [PATCH v1 net-next 08/11] ipmr: " Kuniyuki Iwashima
@ 2024-10-11 22:05 ` Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 10/11] can: gw: " Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 11/11] rtnetlink: Remove rtnl_register() and rtnl_register_module() Kuniyuki Iwashima
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-11 22:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
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>
---
net/dcb/dcbnl.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index 2e6b8c8fd2de..c05d8400e616 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -2408,6 +2408,11 @@ static struct notifier_block dcbnl_nb __read_mostly = {
.notifier_call = dcbnl_netdevice_event,
};
+static const struct rtnl_msg_handler dcbnl_rtnl_msg_handlers[] = {
+ {NULL, PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, 0},
+ {NULL, PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, 0},
+};
+
static int __init dcbnl_init(void)
{
int err;
@@ -2416,8 +2421,7 @@ static int __init dcbnl_init(void)
if (err)
return err;
- rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, 0);
- rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, 0);
+ rtnl_register_many(dcbnl_rtnl_msg_handlers);
return 0;
}
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 10/11] can: gw: Use rtnl_register_many().
2024-10-11 22:05 [PATCH v1 net-next 00/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
` (8 preceding siblings ...)
2024-10-11 22:05 ` [PATCH v1 net-next 09/11] dcb: " Kuniyuki Iwashima
@ 2024-10-11 22:05 ` Kuniyuki Iwashima
2024-10-11 22:05 ` [PATCH v1 net-next 11/11] rtnetlink: Remove rtnl_register() and rtnl_register_module() Kuniyuki Iwashima
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-11 22:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev, Oliver Hartkopp,
Marc Kleine-Budde
We will remove rtnl_register_module() in favour of rtnl_register_many().
rtnl_register_many() will unwind the previous successful registrations
on failure and simplify module error handling.
Let's use rtnl_register_many() instead.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
---
net/can/gw.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/net/can/gw.c b/net/can/gw.c
index 37528826935e..34d6b8c37b92 100644
--- a/net/can/gw.c
+++ b/net/can/gw.c
@@ -1265,6 +1265,12 @@ static struct pernet_operations cangw_pernet_ops = {
.exit_batch = cangw_pernet_exit_batch,
};
+static const struct rtnl_msg_handler cgw_rtnl_msg_handlers[] = {
+ {THIS_MODULE, PF_CAN, RTM_NEWROUTE, cgw_create_job, NULL, 0},
+ {THIS_MODULE, PF_CAN, RTM_DELROUTE, cgw_remove_job, NULL, 0},
+ {THIS_MODULE, PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, 0},
+};
+
static __init int cgw_module_init(void)
{
int ret;
@@ -1290,27 +1296,13 @@ static __init int cgw_module_init(void)
if (ret)
goto out_register_notifier;
- ret = rtnl_register_module(THIS_MODULE, PF_CAN, RTM_GETROUTE,
- NULL, cgw_dump_jobs, 0);
- if (ret)
- goto out_rtnl_register1;
-
- ret = rtnl_register_module(THIS_MODULE, PF_CAN, RTM_NEWROUTE,
- cgw_create_job, NULL, 0);
- if (ret)
- goto out_rtnl_register2;
- ret = rtnl_register_module(THIS_MODULE, PF_CAN, RTM_DELROUTE,
- cgw_remove_job, NULL, 0);
+ ret = rtnl_register_many(cgw_rtnl_msg_handlers);
if (ret)
- goto out_rtnl_register3;
+ goto out_rtnl_register;
return 0;
-out_rtnl_register3:
- rtnl_unregister(PF_CAN, RTM_NEWROUTE);
-out_rtnl_register2:
- rtnl_unregister(PF_CAN, RTM_GETROUTE);
-out_rtnl_register1:
+out_rtnl_register:
unregister_netdevice_notifier(¬ifier);
out_register_notifier:
kmem_cache_destroy(cgw_cache);
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 11/11] rtnetlink: Remove rtnl_register() and rtnl_register_module().
2024-10-11 22:05 [PATCH v1 net-next 00/11] rtnetlink: Use rtnl_register_many() Kuniyuki Iwashima
` (9 preceding siblings ...)
2024-10-11 22:05 ` [PATCH v1 net-next 10/11] can: gw: " Kuniyuki Iwashima
@ 2024-10-11 22:05 ` Kuniyuki Iwashima
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2024-10-11 22:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Kuniyuki Iwashima, Kuniyuki Iwashima, netdev
No one uses rtnl_register() and rtnl_register_module().
Let's remove them.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
include/net/rtnetlink.h | 15 ++++++---
net/core/rtnetlink.c | 74 ++++++++++++-----------------------------
2 files changed, 31 insertions(+), 58 deletions(-)
diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
index 2d3eb7cb4dff..bb49c5708ce7 100644
--- a/include/net/rtnetlink.h
+++ b/include/net/rtnetlink.h
@@ -29,6 +29,16 @@ static inline enum rtnl_kinds rtnl_msgtype_kind(int msgtype)
return msgtype & RTNL_KIND_MASK;
}
+/**
+ * struct rtnl_msg_handler - rtnetlink message type and handlers
+ *
+ * @owner: NULL for built-in, THIS_MODULE for module
+ * @protocol: Protocol family or PF_UNSPEC
+ * @msgtype: rtnetlink message type
+ * @doit: Function pointer called for each request message
+ * @dumpit: Function pointer called for each dump request (NLM_F_DUMP) message
+ * @flags: rtnl_link_flags to modify behaviour of doit/dumpit functions
+ */
struct rtnl_msg_handler {
struct module *owner;
int protocol;
@@ -38,11 +48,6 @@ struct rtnl_msg_handler {
int flags;
};
-void rtnl_register(int protocol, int msgtype,
- rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
-int rtnl_register_module(struct module *owner, int protocol, int msgtype,
- rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
-int rtnl_unregister(int protocol, int msgtype);
void rtnl_unregister_all(int protocol);
int __rtnl_register_many(const struct rtnl_msg_handler *handlers, int n);
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index edaafdcd24ad..dc4fef1e05cc 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -338,57 +338,6 @@ static int rtnl_register_internal(struct module *owner,
return ret;
}
-/**
- * rtnl_register_module - Register a rtnetlink message type
- *
- * @owner: module registering the hook (THIS_MODULE)
- * @protocol: Protocol family or PF_UNSPEC
- * @msgtype: rtnetlink message type
- * @doit: Function pointer called for each request message
- * @dumpit: Function pointer called for each dump request (NLM_F_DUMP) message
- * @flags: rtnl_link_flags to modify behaviour of doit/dumpit functions
- *
- * Like rtnl_register, but for use by removable modules.
- */
-int rtnl_register_module(struct module *owner,
- int protocol, int msgtype,
- rtnl_doit_func doit, rtnl_dumpit_func dumpit,
- unsigned int flags)
-{
- return rtnl_register_internal(owner, protocol, msgtype,
- doit, dumpit, flags);
-}
-EXPORT_SYMBOL_GPL(rtnl_register_module);
-
-/**
- * rtnl_register - Register a rtnetlink message type
- * @protocol: Protocol family or PF_UNSPEC
- * @msgtype: rtnetlink message type
- * @doit: Function pointer called for each request message
- * @dumpit: Function pointer called for each dump request (NLM_F_DUMP) message
- * @flags: rtnl_link_flags to modify behaviour of doit/dumpit functions
- *
- * Registers the specified function pointers (at least one of them has
- * to be non-NULL) to be called whenever a request message for the
- * specified protocol family and message type is received.
- *
- * The special protocol family PF_UNSPEC may be used to define fallback
- * function pointers for the case when no entry for the specific protocol
- * family exists.
- */
-void rtnl_register(int protocol, int msgtype,
- rtnl_doit_func doit, rtnl_dumpit_func dumpit,
- unsigned int flags)
-{
- int err;
-
- err = rtnl_register_internal(NULL, protocol, msgtype, doit, dumpit,
- flags);
- if (err)
- pr_err("Unable to register rtnetlink message handler, "
- "protocol = %d, message type = %d\n", protocol, msgtype);
-}
-
/**
* rtnl_unregister - Unregister a rtnetlink message type
* @protocol: Protocol family or PF_UNSPEC
@@ -396,7 +345,7 @@ void rtnl_register(int protocol, int msgtype,
*
* Returns 0 on success or a negative error code.
*/
-int rtnl_unregister(int protocol, int msgtype)
+static int rtnl_unregister(int protocol, int msgtype)
{
struct rtnl_link __rcu **tab;
struct rtnl_link *link;
@@ -419,7 +368,6 @@ int rtnl_unregister(int protocol, int msgtype)
return 0;
}
-EXPORT_SYMBOL_GPL(rtnl_unregister);
/**
* rtnl_unregister_all - Unregister all rtnetlink message type of a protocol
@@ -454,6 +402,26 @@ void rtnl_unregister_all(int protocol)
}
EXPORT_SYMBOL_GPL(rtnl_unregister_all);
+/**
+ * __rtnl_register_many - Register rtnetlink message types
+ * @handlers: Array of struct rtnl_msg_handlers
+ * @n: The length of @handlers
+ *
+ * Registers the specified function pointers (at least one of them has
+ * to be non-NULL) to be called whenever a request message for the
+ * specified protocol family and message type is received.
+ *
+ * The special protocol family PF_UNSPEC may be used to define fallback
+ * function pointers for the case when no entry for the specific protocol
+ * family exists.
+ *
+ * When one element of @handlers fails to register,
+ * 1) built-in: panics.
+ * 2) modules : the previous successful registrations are unwinded
+ * and an error is returned.
+ *
+ * Use rtnl_register_many().
+ */
int __rtnl_register_many(const struct rtnl_msg_handler *handlers, int n)
{
const struct rtnl_msg_handler *handler;
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 14+ messages in thread