Repository : ssh://git@diktynna/batman-adv On branches: main,main
commit c28b89950355684779209830f3f00b82a95f1dd4 Author: Xiao Liang shaw.leon@gmail.com Date: Wed Feb 19 20:50:28 2025 +0800
batman-adv: 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 [sven@narfation.org: add compat code] Signed-off-by: Sven Eckelmann sven@narfation.org
c28b89950355684779209830f3f00b82a95f1dd4 net/batman-adv/mesh-interface.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/net/batman-adv/mesh-interface.c b/net/batman-adv/mesh-interface.c index 6d3dc650..9d08b217 100644 --- a/net/batman-adv/mesh-interface.c +++ b/net/batman-adv/mesh-interface.c @@ -1082,19 +1082,25 @@ static int batadv_meshif_validate(struct nlattr *tb[], struct nlattr *data[],
/** * batadv_meshif_newlink() - pre-initialize and register new batadv link - * @src_net: the applicable net namespace * @dev: network device to register - * @tb: IFLA_INFO_DATA netlink attributes - * @data: enum batadv_ifla_attrs attributes + * @params: rtnl newlink parameters * @extack: extended ACK report struct * * Return: 0 if successful or error otherwise. */ +#if LINUX_VERSION_IS_GEQ(6, 15, 0) // UGLY_HACK_NEW +static int batadv_meshif_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, +#else // UGLY_HACK_OLD static int batadv_meshif_newlink(struct net *src_net, struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], +#endif // UGLY_HACK_STOP struct netlink_ext_ack *extack) { struct batadv_priv *bat_priv = netdev_priv(dev); +#if LINUX_VERSION_IS_GEQ(6, 15, 0) // UGLY_HACK_NEW + struct nlattr **data = params->data; +#endif // UGLY_HACK_STOP const char *algo_name; int err;