rtnetlink: make the "split" NLM_DONE handling generic
Subsystems (3)
Jakub Kicinski
maintainerPATCH v3 1/1 rtnetlink: make the "split" NLM_DONE handling generic
Jaroslav reports Dell's OMSA Systems Management Data Engine expects NLM_DONE in a separate recvmsg(), both for rtnl_dump_ifinfo() and inet_dump_ifaddr(). We already added a similar fix previously in commit 460b0d33cf10 ("inet: bring NLM_DONE out to a separate recv() again")
Instead of modifying all the dump handlers, and making them look different than modern for_each_netdev_dump()-based dump handlers - put the workaround in rtnetlink code. This will also help us move the custom rtnl-locking from af_netlink in the future (in net-next).
Note that this change is not touching rtnl_dump_all(). rtnl_dump_all() is different kettle of fish and a potential problem. We now mix families in a single recvmsg(), but NLM_DONE is not coalesced.
Tested:
./cli.py --dbg-small-recv 4096 --spec netlink/specs/rt_addr.yaml \
--dump getaddr --json '{"ifa-family": 2}'
./cli.py --dbg-small-recv 4096 --spec netlink/specs/rt_route.yaml \
--dump getroute --json '{"rtm-family": 2}'
./cli.py --dbg-small-recv 4096 --spec netlink/specs/rt_link.yaml \
--dump getlink---
v3:
- change the approach to centralized handling + flag
v2:
- adjust the comment in the kdoc
- add getlink
--- include/net/rtnetlink.h | 1 + net/core/rtnetlink.c | 44 +++++++++++++++++++++++++++++++++++++++-- net/ipv4/devinet.c | 2 +- net/ipv4/fib_frontend.c | 7 +------ 4 files changed, 45 insertions(+), 9 deletions(-)
include/net/rtnetlink.h +1 -0
@@ -13,6 +13,7 @@ enum rtnl_link_flags {RTNL_FLAG_DOIT_UNLOCKED =BIT (0 ),RTNL_FLAG_BULK_DEL_SUPPORTED =BIT (1 ),RTNL_FLAG_DUMP_UNLOCKED =BIT (2 ), + RTNL_FLAG_DUMP_SPLIT_NLM_DONE = BIT(3), /* legacy behavior */ }; enum rtnl_kinds {
net/core/rtnetlink.c +42 -2
62 lines not on this page · raw message
net/ipv4/devinet.c +1 -1
@@ -2805,7 +2805,7 @@ void __init devinet_init(void)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_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 );
net/ipv4/fib_frontend.c +1 -6
@@ -1050,11 +1050,6 @@ static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) e++; } } - -/* Don't let NLM_DONE coalesce into a message, even if it could. -* Some user space expects NLM_DONE in a separate recv(). -*/ - err = skb->len; out: cb->args[1 ] = e;
@@ -1665,5 +1660,5 @@ void __init ip_fib_init(void)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_UNLOCKED |RTNL_FLAG_DUMP_SPLIT_NLM_DONE ); }
Signature · 1 line
2.45.1
Quoted 26 lines · Jakub Kicinski
Jaroslav reports Dell's OMSA Systems Management Data Engine expects
NLM_DONEin a separaterecvmsg(), both forrtnl_dump_ifinfo()andinet_dump_ifaddr(). We already added a similar fix previously in commit460b0d33cf10("inet: bringNLM_DONEout to a separaterecv()again")Instead of modifying all the dump handlers, and making them look different than modern for_each_netdev_dump()-based dump handlers - put the workaround in rtnetlink code. This will also help us move the custom rtnl-locking from
af_netlinkin the future (in net-next).Note that this change is not touching
rtnl_dump_all().rtnl_dump_all()is different kettle of fish and a potential problem. We now mix families in a singlerecvmsg(), butNLM_DONEis not coalesced.Tested:
./cli.py --dbg-small-recv 4096 --spec netlink/specs/rt_addr.yaml \ --dump getaddr --json '{"ifa-family": 2}' ./cli.py --dbg-small-recv 4096 --spec netlink/specs/rt_route.yaml \ --dump getroute --json '{"rtm-family": 2}' ./cli.py --dbg-small-recv 4096 --spec netlink/specs/rt_link.yaml \ --dump getlink
Quoted 5 lines
Fixes 3e41af90767d ("rtnetlink: use xarray iterator to implement rtnl_dump_ifinfo()")Fixes cdb2f80f1c10 ("inet: use xa_array iterator to implement inet_dump_ifaddr()")Reported-by Jaroslav Pulchart <[email protected]>Link https://lore.kernel.org/all/CAK8fFZ7MKoFSEzMBDAOjoUt+vTZRRQgLDNXEOfdCCXSoXXKE0g@mail.gmail.com open hereSigned-off-by Jakub Kicinski <[email protected]>
Very nice, thanks a lot for taking care of this Jakub.
David Ahern
maintainerQuoted 39 lines · Jakub Kicinski
net/core/rtnetlink.c +1
-1@@ -6694,7 +6734,7 @@ void __init rtnetlink_init(void)register_netdevice_notifier (&rtnetlink_dev_notifier);rtnl_register (PF_UNSPEC ,RTM_GETLINK , rtnl_getlink, - rtnl_dump_ifinfo,0 ); + 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 );net/ipv4/devinet.c +1
-1@@ -2805,7 +2805,7 @@ void __init devinet_init(void)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_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 );net/ipv4/fib_frontend.c +0
-5@@ -1050,11 +1050,6 @@ static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) e++; } } - -/* Don't let NLM_DONE coalesce into a message, even if it could. -* Some user space expects NLM_DONE in a separate recv(). -*/ - err = skb->len; out: cb->args[1 ] = e;
net/ipv4/fib_frontend.c void __init ip_fib_init(void) · line 1664
Quoted 6 lines
net/ipv4/fib_frontend.c +1
-1@@ -1665,5 +1660,5 @@ void __init ip_fib_init(void)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_UNLOCKED |RTNL_FLAG_DUMP_SPLIT_NLM_DONE ); }
You are using the legacy way for route, link and address dumps with the option to quickly add the others as needed (meaning when a regression is reported). If those 3 need the workaround, I think there are high odds all of the other rtnl_register users will need it. So, if there is not going to be a per-app opt-in to a new way, you might as well make this the default for all rtnl families - sadly.
Jakub Kicinski
maintainerQuoted 6 lines · On Mon, 3 Jun 2024 20:33:50 -0600 David Ahern wrote:
You are using the legacy way for route, link and address dumps with the option to quickly add the others as needed (meaning when a regression is reported). If those 3 need the workaround, I think there are high odds all of the other
rtnl_registerusers will need it. So, if there is not going to be a per-app opt-in to a new way, you might as well make this the default for all rtnl families - sadly.
I prefer the default (for new code) to be "modern".
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 11 lines · On Mon, 3 Jun 2024 11:48:26 -0700 you wrote:
Jaroslav reports Dell's OMSA Systems Management Data Engine expects
NLM_DONEin a separaterecvmsg(), both forrtnl_dump_ifinfo()andinet_dump_ifaddr(). We already added a similar fix previously in commit460b0d33cf10("inet: bringNLM_DONEout to a separaterecv()again")Instead of modifying all the dump handlers, and making them look different than modern for_each_netdev_dump()-based dump handlers - put the workaround in rtnetlink code. This will also help us move the custom rtnl-locking from
af_netlinkin the future (in net-next).[...]
Here is the summary with links:
- [net,v3] rtnetlink: make the "split" NLM_DONE handling generic
https://git.kernel.org/netdev/net/c/5b4b62a169e1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html