]> git.ipfire.org Git - thirdparty/linux.git/commit
rtnetlink: Pack newlink() params into struct
authorXiao Liang <shaw.leon@gmail.com>
Wed, 19 Feb 2025 12:50:28 +0000 (20:50 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 21 Feb 2025 23:28:02 +0000 (15:28 -0800)
commit69c7be1b903fca2835e80ec506bd1d75ce84fb4d
tree5f6511ed278c655e8198770b61ed0d43c5b61c26
parentec061546c6cffbb8929495bba3953f0cc5e177fa
rtnetlink: Pack newlink() params into struct

There are 4 net namespaces involved when creating links:

 - source netns - where the netlink socket resides,
 - target netns - where to put the device being created,
 - link netns - netns associated with the device (backend),
 - peer netns - netns of peer device.

Currently, two nets are passed to newlink() callback - "src_net"
parameter and "dev_net" (implicitly in net_device). They are set as
follows, depending on netlink attributes in the request.

 +------------+-------------------+---------+---------+
 | peer netns | IFLA_LINK_NETNSID | src_net | dev_net |
 +------------+-------------------+---------+---------+
 |            | absent            | source  | target  |
 | absent     +-------------------+---------+---------+
 |            | present           | link    | link    |
 +------------+-------------------+---------+---------+
 |            | absent            | peer    | target  |
 | present    +-------------------+---------+---------+
 |            | present           | peer    | link    |
 +------------+-------------------+---------+---------+

When IFLA_LINK_NETNSID is present, the device is created in link netns
first and then moved to target netns. This has some side effects,
including extra ifindex allocation, ifname validation and link events.
These could be avoided if we create it in target netns from
the beginning.

On the other hand, the meaning of src_net parameter is ambiguous. It
varies depending on how parameters are passed. It is the effective
link (or peer netns) by design, but some drivers ignore it and use
dev_net instead.

To provide more netns context for drivers, this patch packs existing
newlink() parameters, along with the source netns, link netns and peer
netns, into a struct. The old "src_net" is renamed to "net" to avoid
confusion with real source netns, and will be deprecated later. The use
of src_net are converted to params->net trivially.

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250219125039.18024-3-shaw.leon@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
42 files changed:
drivers/infiniband/ulp/ipoib/ipoib_netlink.c
drivers/net/amt.c
drivers/net/bareudp.c
drivers/net/bonding/bond_netlink.c
drivers/net/can/dev/netlink.c
drivers/net/can/vxcan.c
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
drivers/net/geneve.c
drivers/net/gtp.c
drivers/net/ipvlan/ipvlan.h
drivers/net/ipvlan/ipvlan_main.c
drivers/net/ipvlan/ipvtap.c
drivers/net/macsec.c
drivers/net/macvlan.c
drivers/net/macvtap.c
drivers/net/netkit.c
drivers/net/pfcp.c
drivers/net/ppp/ppp_generic.c
drivers/net/team/team_core.c
drivers/net/veth.c
drivers/net/vrf.c
drivers/net/vxlan/vxlan_core.c
drivers/net/wireguard/device.c
drivers/net/wireless/virtual/virt_wifi.c
drivers/net/wwan/wwan_core.c
include/linux/if_macvlan.h
include/net/rtnetlink.h
net/8021q/vlan_netlink.c
net/batman-adv/soft-interface.c
net/bridge/br_netlink.c
net/caif/chnl_net.c
net/core/rtnetlink.c
net/hsr/hsr_netlink.c
net/ieee802154/6lowpan/core.c
net/ipv4/ip_gre.c
net/ipv4/ip_vti.c
net/ipv4/ipip.c
net/ipv6/ip6_gre.c
net/ipv6/ip6_tunnel.c
net/ipv6/ip6_vti.c
net/ipv6/sit.c
net/xfrm/xfrm_interface_core.c