netlink: add an optional per-netns ROUTE multicast index
Subsystems (5)
PATCH 1/2 netlink: add an optional per-netns ROUTE multicast index
In reply to a message not in the archiveNETLINK_ROUTE broadcasts visit subscribers in unrelated network namespaces before checking whether they can receive a notification.
Maintain one ROUTE subscriber list per network namespace and one global LISTEN_ALL_NSID list. Select those candidate lists when the new net.core.netlink_route_mc_index sysctl is enabled. Exclude local sockets from the second list to avoid duplicate delivery.
Preserve do_one_broadcast and the existing broadcast initialization, locking, completion and error handling. Change only candidate selection inside netlink_broadcast_filtered; do not force function inlining or add separate broadcast setup, completion or indexed-walk helpers.
Use the existing table-grab protection for index maintenance at subscription, option and removal transitions. Keep both indexes populated while disabled so switching modes includes existing sockets immediately. The sysctl defaults to zero, is visible only in init_net and affects all network namespaces. Other Netlink protocols retain the original walk. Disabling the switch retains index maintenance and memory costs.
AI assistance: An LLM assisted with implementation adaptation and simplification.
--- Documentation/admin-guide/sysctl/net.rst | 27 ++++++ net/netlink/af_netlink.c | 109 ++++++++++++++++++++++- net/netlink/af_netlink.h | 4 + 3 files changed, 137 insertions(+), 3 deletions(-)
Documentation/admin-guide/sysctl/net.rst +27 -0
@@ -280,6 +280,33 @@ checksums. These messages are now emitted at KERN_DEBUG and can generally be enabled and controlled by the dynamic_debug facility. +netlink_route_mc_index +--------------------- + +Selects the multicast candidate lists used for NETLINK_ROUTE notifications. +This setting is available only in the initial network namespace and applies +to notifications originating in all network namespaces. + +Values: + + - 0 - walk the original global subscription list (default). + - 1 - walk the sender's network namespace subscription list and the + global NETLINK_LISTEN_ALL_NSID subscription list, regardless of the + number of subscribers. + +Both auxiliary indexes are maintained in either mode. +Existing sockets are therefore included immediately when the index is enabled. +Each broadcast reads the setting once and completes using its selected path; +changing the setting does not restart broadcasts already in progress. +Group membership, namespace, permission and socket filter checks still apply +in both modes. Other Netlink protocols continue to use their original lists. + +The indexed path can reduce notification costs when there are many ordinary +subscribers in other network namespaces. It may add overhead when most +subscribers are local or listen across network namespaces. Disabling the +indexed path does not remove its memory or subscription maintenance costs. +Without CONFIG_SYSCTL, the setting remains at its default value of 0. + netdev_budget -------------
net/netlink/af_netlink.c +106 -3
175 lines not on this page · raw message
net/netlink/af_netlink.h +4 -0
@@ -47,6 +47,10 @@ struct netlink_sock { unsigned long *groups);struct module *module; +/* NETLINK_ROUTE auxiliary multicast indexes; nl_table_lock protected. */ +struct hlist_node mc_net_node; +struct hlist_node mc_all_nsid_node; +struct rhash_head node;struct rcu_head rcu; };
PATCH 2/2 selftests: net: cover ROUTE multicast namespace and switch semantics
In reply to a message not in the archiveExercise local and cross-namespace delivery, permissions, group filters, subscription and option transitions, socket filters, overflow behaviour, compatibility mode and unaffected Netlink protocols. Include group memberships above 32. Validate live changes of the optional ROUTE index while existing sockets remain active and while subscriptions change.
Use unique namespace names and clean up sockets and namespaces on exit. Restore the sysctl after the switch test. Report missing privileges, iproute2, Python setns support or the optional sysctl as kselftest SKIP. The general semantic test also runs on kernels without the new switch. No function tracing, FRR or network access is required.
AI assistance: An LLM assisted with implementation adaptation.
--- tools/testing/selftests/net/Makefile | 2 + tools/testing/selftests/net/config | 1 + .../selftests/net/netlink_mcast_semantics.py | 420 ++++++++++++++++++ .../selftests/net/netlink_mcast_switch.py | 217 +++++++++ 4 files changed, 640 insertions(+) create mode 100755 tools/testing/selftests/net/netlink_mcast_semantics.py create mode 100755 tools/testing/selftests/net/netlink_mcast_switch.py
tools/testing/selftests/net/Makefile +2 -0
@@ -71,6 +71,8 @@ TEST_PROGS := \ netdev-l2addr.sh \ netdev_lock.py \ netdevice.sh \ + netlink_mcast_semantics.py \ + netlink_mcast_switch.py \ netns-name.sh \ netns-sysctl.sh \ nk_qlease.py \
tools/testing/selftests/net/config +1 -0
@@ -97,6 +97,7 @@ CONFIG_NET_IPGRE_DEMUX=m CONFIG_NET_IPIP=y CONFIG_NET_IPVTI=y CONFIG_NETKIT=y +CONFIG_NETLINK_DIAG=y CONFIG_NET_L3_MASTER_DEV=y CONFIG_NET_NS=y CONFIG_NET_PKTGEN=m
tools/testing/selftests/net/netlink_mcast_semantics.py new file +420 -0
420 lines not on this page · raw message
tools/testing/selftests/net/netlink_mcast_switch.py new file +217 -0
217 lines not on this page · raw message
Paolo Abeni
maintainerDocumentation/admin-guide/sysctl/net.rst checksums. · line 284
Quoted 10 lines · patrick
Documentation/admin-guide/sysctl/net.rst +2
-0@@ -280,6 +280,33 @@ checksums. These messages are now emitted at KERN_DEBUG and can generally be enabled and controlled by the dynamic_debug facility. +netlink_route_mc_index +---------------------
The above breaks kdoc
/P