Re: [PATCH net-next v9 06/11] net: ipv6: Use link netns in newlink() of rtnl_link_ops
From: Kuniyuki Iwashima
Date: Thu Feb 13 2025 - 02:06:16 EST
From: Xiao Liang <shaw.leon@xxxxxxxxx>
Date: Mon, 10 Feb 2025 21:29:57 +0800
> When link_net is set, use it as link netns instead of dev_net(). This
> prepares for rtnetlink core to create device in target netns directly,
> in which case the two namespaces may be different.
>
> Set correct netns in priv before registering device, and avoid
> overwriting it in ndo_init() path.
>
> Signed-off-by: Xiao Liang <shaw.leon@xxxxxxxxx>
> ---
> net/ipv6/ip6_gre.c | 20 ++++++++++----------
> net/ipv6/ip6_tunnel.c | 13 ++++++++-----
> net/ipv6/ip6_vti.c | 10 ++++++----
> net/ipv6/sit.c | 11 +++++++----
> 4 files changed, 31 insertions(+), 23 deletions(-)
>
> diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
> index 863852abe8ea..108600dc716f 100644
> --- a/net/ipv6/ip6_gre.c
> +++ b/net/ipv6/ip6_gre.c
> @@ -1498,7 +1498,8 @@ static int ip6gre_tunnel_init_common(struct net_device *dev)
> tunnel = netdev_priv(dev);
>
> tunnel->dev = dev;
> - tunnel->net = dev_net(dev);
> + if (!tunnel->net)
> + tunnel->net = dev_net(dev);
Same question as patch 5 for here and other parts.
Do we need this check and assignment ?
ip6gre_newlink_common
-> nt->net = dev_net(dev)
-> register_netdevice
-> ndo_init / ip6gre_tunnel_init()
-> ip6gre_tunnel_init_common
-> tunnel->net = dev_net(dev)