* [PATCH net-next v5 0/5] net: Improve netns handling in RTNL and ip_tunnel
@ 2024-12-09 14:01 Xiao Liang
2024-12-09 14:01 ` [PATCH net-next v5 1/5] net: ip_tunnel: Build flow in underlay net namespace Xiao Liang
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Xiao Liang @ 2024-12-09 14:01 UTC (permalink / raw)
To: netdev, linux-kselftest, Kuniyuki Iwashima, Jakub Kicinski,
Donald Hunter
Cc: David S. Miller, David Ahern, Eric Dumazet, Paolo Abeni,
Ido Schimmel, Andrew Lunn, Simon Horman, Shuah Khan, Jiri Pirko,
Hangbin Liu, linux-rdma, linux-can, osmocom-net-gprs, bpf,
linux-ppp, wireguard, linux-wireless, b.a.t.m.a.n, bridge,
linux-wpan, linux-kernel
This patch series includes some netns-related improvements and fixes for
RTNL and ip_tunnel, to make link creation more intuitive:
- Creating link in another net namespace doesn't conflict with link names
in current one.
- Refector rtnetlink link creation. Create link in target namespace
directly. Pass both source and link netns to drivers via newlink()
callback.
So that
# ip link add netns ns1 link-netns ns2 tun0 type gre ...
will create tun0 in ns1, rather than create it in ns2 and move to ns1.
And don't conflict with another interface named "tun0" in current netns.
---
v5:
- Fix function doc in batman-adv.
- Include peer_net in rtnl newlink parameters.
v4:
link: https://lore.kernel.org/all/20241118143244.1773-1-shaw.leon@gmail.com/
- Pack newlink() parameters to a single struct.
- Use ynl async_msg_queue.empty() in selftest.
v3:
link: https://lore.kernel.org/all/20241113125715.150201-1-shaw.leon@gmail.com/
- Drop "netns_atomic" flag and module parameter. Add netns parameter to
newlink() instead, and convert drivers accordingly.
- Move python NetNSEnter helper to net selftest lib.
v2:
link: https://lore.kernel.org/all/20241107133004.7469-1-shaw.leon@gmail.com/
- Check NLM_F_EXCL to ensure only link creation is affected.
- Add self tests for link name/ifindex conflict and notifications
in different netns.
- Changes in dummy driver and ynl in order to add the test case.
v1:
link: https://lore.kernel.org/all/20241023023146.372653-1-shaw.leon@gmail.com/
Xiao Liang (5):
net: ip_tunnel: Build flow in underlay net namespace
rtnetlink: Lookup device in target netns when creating link
rtnetlink: Decouple net namespaces in rtnl_newlink_create()
selftests: net: Add python context manager for netns entering
selftests: net: Add two test cases for link netns
drivers/infiniband/ulp/ipoib/ipoib_netlink.c | 11 +++--
drivers/net/amt.c | 13 +++---
drivers/net/bareudp.c | 11 +++--
drivers/net/bonding/bond_netlink.c | 8 ++--
drivers/net/can/dev/netlink.c | 4 +-
drivers/net/can/vxcan.c | 9 ++--
.../ethernet/qualcomm/rmnet/rmnet_config.c | 11 +++--
drivers/net/geneve.c | 11 +++--
drivers/net/gtp.c | 9 ++--
drivers/net/ipvlan/ipvlan.h | 4 +-
drivers/net/ipvlan/ipvlan_main.c | 11 +++--
drivers/net/ipvlan/ipvtap.c | 7 ++-
drivers/net/macsec.c | 11 +++--
drivers/net/macvlan.c | 8 ++--
drivers/net/macvtap.c | 8 ++--
drivers/net/netkit.c | 9 ++--
drivers/net/pfcp.c | 8 ++--
drivers/net/ppp/ppp_generic.c | 10 +++--
drivers/net/team/team_core.c | 7 +--
drivers/net/veth.c | 9 ++--
drivers/net/vrf.c | 7 +--
drivers/net/vxlan/vxlan_core.c | 11 +++--
drivers/net/wireguard/device.c | 8 ++--
drivers/net/wireless/virtual/virt_wifi.c | 10 +++--
drivers/net/wwan/wwan_core.c | 15 +++++--
include/net/ip_tunnels.h | 5 ++-
include/net/rtnetlink.h | 44 ++++++++++++++++---
net/8021q/vlan_netlink.c | 11 +++--
net/batman-adv/soft-interface.c | 12 ++---
net/bridge/br_netlink.c | 8 ++--
net/caif/chnl_net.c | 6 +--
net/core/rtnetlink.c | 35 ++++++++-------
net/hsr/hsr_netlink.c | 14 +++---
net/ieee802154/6lowpan/core.c | 9 ++--
net/ipv4/ip_gre.c | 27 ++++++++----
net/ipv4/ip_tunnel.c | 16 ++++---
net/ipv4/ip_vti.c | 10 +++--
net/ipv4/ipip.c | 10 +++--
net/ipv6/ip6_gre.c | 28 +++++++-----
net/ipv6/ip6_tunnel.c | 16 +++----
net/ipv6/ip6_vti.c | 15 +++----
net/ipv6/sit.c | 16 +++----
net/xfrm/xfrm_interface_core.c | 14 +++---
tools/testing/selftests/net/Makefile | 1 +
.../testing/selftests/net/lib/py/__init__.py | 2 +-
tools/testing/selftests/net/lib/py/netns.py | 18 ++++++++
tools/testing/selftests/net/netns-name.sh | 10 +++++
tools/testing/selftests/net/netns_atomic.py | 39 ++++++++++++++++
48 files changed, 385 insertions(+), 211 deletions(-)
create mode 100755 tools/testing/selftests/net/netns_atomic.py
--
2.47.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v5 1/5] net: ip_tunnel: Build flow in underlay net namespace
2024-12-09 14:01 [PATCH net-next v5 0/5] net: Improve netns handling in RTNL and ip_tunnel Xiao Liang
@ 2024-12-09 14:01 ` Xiao Liang
2024-12-09 14:01 ` [PATCH net-next v5 5/5] selftests: net: Add two test cases for link netns Xiao Liang
[not found] ` <20241209140151.231257-4-shaw.leon@gmail.com>
2 siblings, 0 replies; 6+ messages in thread
From: Xiao Liang @ 2024-12-09 14:01 UTC (permalink / raw)
To: netdev, linux-kselftest, Kuniyuki Iwashima, Jakub Kicinski,
Donald Hunter
Cc: David S. Miller, David Ahern, Eric Dumazet, Paolo Abeni,
Ido Schimmel, Andrew Lunn, Simon Horman, Shuah Khan, Jiri Pirko,
Hangbin Liu, linux-rdma, linux-can, osmocom-net-gprs, bpf,
linux-ppp, wireguard, linux-wireless, b.a.t.m.a.n, bridge,
linux-wpan, linux-kernel
Build IPv4 flow in underlay net namespace, where encapsulated packets
are routed.
Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
---
net/ipv4/ip_tunnel.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index 25505f9b724c..09b73acf037a 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -294,7 +294,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev)
ip_tunnel_init_flow(&fl4, iph->protocol, iph->daddr,
iph->saddr, tunnel->parms.o_key,
- iph->tos & INET_DSCP_MASK, dev_net(dev),
+ iph->tos & INET_DSCP_MASK, tunnel->net,
tunnel->parms.link, tunnel->fwmark, 0, 0);
rt = ip_route_output_key(tunnel->net, &fl4);
@@ -611,7 +611,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
}
ip_tunnel_init_flow(&fl4, proto, key->u.ipv4.dst, key->u.ipv4.src,
tunnel_id_to_key32(key->tun_id),
- tos & INET_DSCP_MASK, dev_net(dev), 0, skb->mark,
+ tos & INET_DSCP_MASK, tunnel->net, 0, skb->mark,
skb_get_hash(skb), key->flow_flags);
if (!tunnel_hlen)
@@ -774,7 +774,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
ip_tunnel_init_flow(&fl4, protocol, dst, tnl_params->saddr,
tunnel->parms.o_key, tos & INET_DSCP_MASK,
- dev_net(dev), READ_ONCE(tunnel->parms.link),
+ tunnel->net, READ_ONCE(tunnel->parms.link),
tunnel->fwmark, skb_get_hash(skb), 0);
if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0)
--
2.47.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v5 5/5] selftests: net: Add two test cases for link netns
2024-12-09 14:01 [PATCH net-next v5 0/5] net: Improve netns handling in RTNL and ip_tunnel Xiao Liang
2024-12-09 14:01 ` [PATCH net-next v5 1/5] net: ip_tunnel: Build flow in underlay net namespace Xiao Liang
@ 2024-12-09 14:01 ` Xiao Liang
[not found] ` <4a2fe99a-772d-4df1-a8ef-14338682b69e@redhat.com>
[not found] ` <20241209140151.231257-4-shaw.leon@gmail.com>
2 siblings, 1 reply; 6+ messages in thread
From: Xiao Liang @ 2024-12-09 14:01 UTC (permalink / raw)
To: netdev, linux-kselftest, Kuniyuki Iwashima, Jakub Kicinski,
Donald Hunter
Cc: David S. Miller, David Ahern, Eric Dumazet, Paolo Abeni,
Ido Schimmel, Andrew Lunn, Simon Horman, Shuah Khan, Jiri Pirko,
Hangbin Liu, linux-rdma, linux-can, osmocom-net-gprs, bpf,
linux-ppp, wireguard, linux-wireless, b.a.t.m.a.n, bridge,
linux-wpan, linux-kernel
- Add test for creating link in another netns when a link of the same
name and ifindex exists in current netns.
- Add test for link netns atomicity - create link directly in target
netns, and no notifications should be generated in current netns.
Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
---
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/netns-name.sh | 10 ++++++
tools/testing/selftests/net/netns_atomic.py | 39 +++++++++++++++++++++
3 files changed, 50 insertions(+)
create mode 100755 tools/testing/selftests/net/netns_atomic.py
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index cb2fc601de66..f9f7a765d645 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -34,6 +34,7 @@ TEST_PROGS += gre_gso.sh
TEST_PROGS += cmsg_so_mark.sh
TEST_PROGS += cmsg_time.sh cmsg_ipv6.sh
TEST_PROGS += netns-name.sh
+TEST_PROGS += netns_atomic.py
TEST_PROGS += nl_netdev.py
TEST_PROGS += srv6_end_dt46_l3vpn_test.sh
TEST_PROGS += srv6_end_dt4_l3vpn_test.sh
diff --git a/tools/testing/selftests/net/netns-name.sh b/tools/testing/selftests/net/netns-name.sh
index 6974474c26f3..0be1905d1f2f 100755
--- a/tools/testing/selftests/net/netns-name.sh
+++ b/tools/testing/selftests/net/netns-name.sh
@@ -78,6 +78,16 @@ ip -netns $NS link show dev $ALT_NAME 2> /dev/null &&
fail "Can still find alt-name after move"
ip -netns $test_ns link del $DEV || fail
+#
+# Test no conflict of the same name/ifindex in different netns
+#
+ip -netns $NS link add name $DEV index 100 type dummy || fail
+ip -netns $NS link add netns $test_ns name $DEV index 100 type dummy ||
+ fail "Can create in netns without moving"
+ip -netns $test_ns link show dev $DEV >> /dev/null || fail "Device not found"
+ip -netns $NS link del $DEV || fail
+ip -netns $test_ns link del $DEV || fail
+
echo -ne "$(basename $0) \t\t\t\t"
if [ $RET_CODE -eq 0 ]; then
echo "[ OK ]"
diff --git a/tools/testing/selftests/net/netns_atomic.py b/tools/testing/selftests/net/netns_atomic.py
new file mode 100755
index 000000000000..d350a3fc0a91
--- /dev/null
+++ b/tools/testing/selftests/net/netns_atomic.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import time
+
+from lib.py import ksft_run, ksft_exit, ksft_true
+from lib.py import ip
+from lib.py import NetNS, NetNSEnter
+from lib.py import RtnlFamily
+
+
+def test_event(ns1, ns2) -> None:
+ with NetNSEnter(str(ns1)):
+ rtnl = RtnlFamily()
+
+ rtnl.ntf_subscribe("rtnlgrp-link")
+
+ ip(f"netns set {ns1} 0", ns=str(ns2))
+
+ ip(f"link add netns {ns2} link-netnsid 0 dummy1 type dummy")
+ ip(f"link add netns {ns2} dummy2 type dummy", ns=str(ns1))
+
+ ip("link del dummy1", ns=str(ns2))
+ ip("link del dummy2", ns=str(ns2))
+
+ time.sleep(1)
+ rtnl.check_ntf()
+ ksft_true(rtnl.async_msg_queue.empty(),
+ "Received unexpected link notification")
+
+
+def main() -> None:
+ with NetNS() as ns1, NetNS() as ns2:
+ ksft_run([test_event], args=(ns1, ns2))
+ ksft_exit()
+
+
+if __name__ == "__main__":
+ main()
--
2.47.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v5 3/5] rtnetlink: Decouple net namespaces in rtnl_newlink_create()
[not found] ` <20241209140151.231257-4-shaw.leon@gmail.com>
@ 2024-12-12 9:27 ` Paolo Abeni
2024-12-12 12:41 ` Xiao Liang
0 siblings, 1 reply; 6+ messages in thread
From: Paolo Abeni @ 2024-12-12 9:27 UTC (permalink / raw)
To: Xiao Liang, netdev, linux-kselftest, Kuniyuki Iwashima,
Jakub Kicinski, Donald Hunter
Cc: David S. Miller, David Ahern, Eric Dumazet, Ido Schimmel,
Andrew Lunn, Simon Horman, Shuah Khan, Jiri Pirko, Hangbin Liu,
linux-rdma, linux-can, osmocom-net-gprs, bpf, linux-ppp,
wireguard, linux-wireless, b.a.t.m.a.n, bridge, linux-wpan,
linux-kernel
On 12/9/24 15:01, Xiao Liang wrote:
> 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.
>
> +------------+-------------------+---------+---------+
> | 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. This has some side effects, including extra ifindex allocation,
> ifname validation and link notifications. There's also an extra step to
> move the device to target netns. These could be avoided if we create it
> in target netns at the beginning.
>
> On the other hand, the meaning of src_net 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.
>
> This patch refactors netns handling by packing newlink() parameters into
> a struct, and passing source, link and peer netns as is through this
> struct. Fallback logic is implemented in helper functions -
> rtnl_newlink_link_net() and rtnl_newlink_peer_net(). If is not set, peer
> netns falls back to link netns, and link netns falls back to source netns.
> rtnl_newlink_create() now creates devices in target netns directly,
> so dev_net is always target netns.
>
> For drivers that use dev_net as fallback of link_netns, current behavior
> is kept for compatibility.
>
> Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
I must admit this patch is way too huge for me to allow any reasonable
review except that this has the potential of breaking a lot of things.
I think you should be splitted to make it more palatable; i.e.
- a patch just add the params struct with no semantic changes.
- a patch making the dev_change_net_namespace() conditional on net !=
tge_net[1]
- many per-device patches creating directly the device in the target
namespace.
- a patch reverting [1]
Other may have different opinions, I'd love to hear them.
> diff --git a/drivers/net/amt.c b/drivers/net/amt.c
> index 98c6205ed19f..2f7bf50e05d2 100644
> --- a/drivers/net/amt.c
> +++ b/drivers/net/amt.c
> @@ -3161,14 +3161,17 @@ static int amt_validate(struct nlattr *tb[], struct nlattr *data[],
> return 0;
> }
>
> -static int amt_newlink(struct net *net, struct net_device *dev,
> - struct nlattr *tb[], struct nlattr *data[],
> - struct netlink_ext_ack *extack)
> +static int amt_newlink(struct rtnl_newlink_params *params)
> {
> + struct net_device *dev = params->dev;
> + struct nlattr **tb = params->tb;
> + struct nlattr **data = params->data;
> + struct netlink_ext_ack *extack = params->extack;
> + struct net *link_net = rtnl_newlink_link_net(params);
> struct amt_dev *amt = netdev_priv(dev);
> int err = -EINVAL;
Minor nit: here and and many other places, please respect the reverse
xmas tree order.
Thanks,
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v5 3/5] rtnetlink: Decouple net namespaces in rtnl_newlink_create()
2024-12-12 9:27 ` [PATCH net-next v5 3/5] rtnetlink: Decouple net namespaces in rtnl_newlink_create() Paolo Abeni
@ 2024-12-12 12:41 ` Xiao Liang
0 siblings, 0 replies; 6+ messages in thread
From: Xiao Liang @ 2024-12-12 12:41 UTC (permalink / raw)
To: Paolo Abeni
Cc: netdev, linux-kselftest, Kuniyuki Iwashima, Jakub Kicinski,
Donald Hunter, David S. Miller, David Ahern, Eric Dumazet,
Ido Schimmel, Andrew Lunn, Simon Horman, Shuah Khan, Jiri Pirko,
Hangbin Liu, linux-rdma, linux-can, osmocom-net-gprs, bpf,
linux-ppp, wireguard, linux-wireless, b.a.t.m.a.n, bridge,
linux-wpan, linux-kernel
On Thu, Dec 12, 2024 at 5:27 PM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On 12/9/24 15:01, Xiao Liang wrote:
> > 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.
> >
> > +------------+-------------------+---------+---------+
> > | 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. This has some side effects, including extra ifindex allocation,
> > ifname validation and link notifications. There's also an extra step to
> > move the device to target netns. These could be avoided if we create it
> > in target netns at the beginning.
> >
> > On the other hand, the meaning of src_net 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.
> >
> > This patch refactors netns handling by packing newlink() parameters into
> > a struct, and passing source, link and peer netns as is through this
> > struct. Fallback logic is implemented in helper functions -
> > rtnl_newlink_link_net() and rtnl_newlink_peer_net(). If is not set, peer
> > netns falls back to link netns, and link netns falls back to source netns.
> > rtnl_newlink_create() now creates devices in target netns directly,
> > so dev_net is always target netns.
> >
> > For drivers that use dev_net as fallback of link_netns, current behavior
> > is kept for compatibility.
> >
> > Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
>
> I must admit this patch is way too huge for me to allow any reasonable
> review except that this has the potential of breaking a lot of things.
>
> I think you should be splitted to make it more palatable; i.e.
> - a patch just add the params struct with no semantic changes.
> - a patch making the dev_change_net_namespace() conditional on net !=
> tge_net[1]
> - many per-device patches creating directly the device in the target
> namespace.
> - a patch reverting [1]
>
> Other may have different opinions, I'd love to hear them.
Thanks. I understand your concern. Since the device is created in common
code, how about splitting the patch this way:
1) make the params struct contain both current src_net and other netns:
struct rtnl_newlink_params {
struct net *net; // renamed from current src_net
struct net *src_net; // real src_net
struct net *link_net;
...
};
2) convert each driver to use the accurate netns,
3) remove "net", which is not used now, from params struct,
4) change rtnl_newlink_create() to create device in target netns
directly.
So 1) will be a big one but has no semantic changes.
And I will send Patch 1 in this series to the net tree instead.
>
> > diff --git a/drivers/net/amt.c b/drivers/net/amt.c
> > index 98c6205ed19f..2f7bf50e05d2 100644
> > --- a/drivers/net/amt.c
> > +++ b/drivers/net/amt.c
> > @@ -3161,14 +3161,17 @@ static int amt_validate(struct nlattr *tb[], struct nlattr *data[],
> > return 0;
> > }
> >
> > -static int amt_newlink(struct net *net, struct net_device *dev,
> > - struct nlattr *tb[], struct nlattr *data[],
> > - struct netlink_ext_ack *extack)
> > +static int amt_newlink(struct rtnl_newlink_params *params)
> > {
> > + struct net_device *dev = params->dev;
> > + struct nlattr **tb = params->tb;
> > + struct nlattr **data = params->data;
> > + struct netlink_ext_ack *extack = params->extack;
> > + struct net *link_net = rtnl_newlink_link_net(params);
> > struct amt_dev *amt = netdev_priv(dev);
> > int err = -EINVAL;
>
> Minor nit: here and and many other places, please respect the reverse
> xmas tree order.
Will fix this.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v5 5/5] selftests: net: Add two test cases for link netns
[not found] ` <4a2fe99a-772d-4df1-a8ef-14338682b69e@redhat.com>
@ 2024-12-12 13:06 ` Xiao Liang
0 siblings, 0 replies; 6+ messages in thread
From: Xiao Liang @ 2024-12-12 13:06 UTC (permalink / raw)
To: Paolo Abeni
Cc: netdev, linux-kselftest, Kuniyuki Iwashima, Jakub Kicinski,
Donald Hunter, David S. Miller, David Ahern, Eric Dumazet,
Ido Schimmel, Andrew Lunn, Simon Horman, Shuah Khan, Jiri Pirko,
Hangbin Liu, linux-rdma, linux-can, osmocom-net-gprs, bpf,
linux-ppp, wireguard, linux-wireless, b.a.t.m.a.n, bridge,
linux-wpan, linux-kernel
On Thu, Dec 12, 2024 at 5:40 PM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On 12/9/24 15:01, Xiao Liang wrote:
> > - Add test for creating link in another netns when a link of the same
> > name and ifindex exists in current netns.
> > - Add test for link netns atomicity - create link directly in target
> > netns, and no notifications should be generated in current netns.
> >
> > Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
> > ---
> > tools/testing/selftests/net/Makefile | 1 +
> > tools/testing/selftests/net/netns-name.sh | 10 ++++++
> > tools/testing/selftests/net/netns_atomic.py | 39 +++++++++++++++++++++
> > 3 files changed, 50 insertions(+)
> > create mode 100755 tools/testing/selftests/net/netns_atomic.py
> >
> > diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
> > index cb2fc601de66..f9f7a765d645 100644
> > --- a/tools/testing/selftests/net/Makefile
> > +++ b/tools/testing/selftests/net/Makefile
> > @@ -34,6 +34,7 @@ TEST_PROGS += gre_gso.sh
> > TEST_PROGS += cmsg_so_mark.sh
> > TEST_PROGS += cmsg_time.sh cmsg_ipv6.sh
> > TEST_PROGS += netns-name.sh
> > +TEST_PROGS += netns_atomic.py
> > TEST_PROGS += nl_netdev.py
> > TEST_PROGS += srv6_end_dt46_l3vpn_test.sh
> > TEST_PROGS += srv6_end_dt4_l3vpn_test.sh
> > diff --git a/tools/testing/selftests/net/netns-name.sh b/tools/testing/selftests/net/netns-name.sh
> > index 6974474c26f3..0be1905d1f2f 100755
> > --- a/tools/testing/selftests/net/netns-name.sh
> > +++ b/tools/testing/selftests/net/netns-name.sh
> > @@ -78,6 +78,16 @@ ip -netns $NS link show dev $ALT_NAME 2> /dev/null &&
> > fail "Can still find alt-name after move"
> > ip -netns $test_ns link del $DEV || fail
> >
> > +#
> > +# Test no conflict of the same name/ifindex in different netns
> > +#
> > +ip -netns $NS link add name $DEV index 100 type dummy || fail
> > +ip -netns $NS link add netns $test_ns name $DEV index 100 type dummy ||
> > + fail "Can create in netns without moving"
> > +ip -netns $test_ns link show dev $DEV >> /dev/null || fail "Device not found"
> > +ip -netns $NS link del $DEV || fail
> > +ip -netns $test_ns link del $DEV || fail
> > +
> > echo -ne "$(basename $0) \t\t\t\t"
> > if [ $RET_CODE -eq 0 ]; then
> > echo "[ OK ]"
> > diff --git a/tools/testing/selftests/net/netns_atomic.py b/tools/testing/selftests/net/netns_atomic.py
> > new file mode 100755
> > index 000000000000..d350a3fc0a91
> > --- /dev/null
> > +++ b/tools/testing/selftests/net/netns_atomic.py
> > @@ -0,0 +1,39 @@
> > +#!/usr/bin/env python3
> > +# SPDX-License-Identifier: GPL-2.0
> > +
> > +import time
> > +
> > +from lib.py import ksft_run, ksft_exit, ksft_true
> > +from lib.py import ip
> > +from lib.py import NetNS, NetNSEnter
> > +from lib.py import RtnlFamily
> > +
> > +
> > +def test_event(ns1, ns2) -> None:
> > + with NetNSEnter(str(ns1)):
> > + rtnl = RtnlFamily()
> > +
> > + rtnl.ntf_subscribe("rtnlgrp-link")
> > +
> > + ip(f"netns set {ns1} 0", ns=str(ns2))
> > +
> > + ip(f"link add netns {ns2} link-netnsid 0 dummy1 type dummy")
> > + ip(f"link add netns {ns2} dummy2 type dummy", ns=str(ns1))
> > +
> > + ip("link del dummy1", ns=str(ns2))
> > + ip("link del dummy2", ns=str(ns2))
> > +
> > + time.sleep(1)
> > + rtnl.check_ntf()
> > + ksft_true(rtnl.async_msg_queue.empty(),
> > + "Received unexpected link notification")
>
> I think we need a much larger coverage here, possibly testing all the
> update drivers and more 'netns', 'link-netnsid', 'peer netns'
> permutations for the devices that allow them.
OK, I will add more cases. But I'm afraid I don't know how to build
valid parameters for all of them, and some seem to require hardware.
>
> Thanks,
>
> Paolo
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-05-21 16:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-09 14:01 [PATCH net-next v5 0/5] net: Improve netns handling in RTNL and ip_tunnel Xiao Liang
2024-12-09 14:01 ` [PATCH net-next v5 1/5] net: ip_tunnel: Build flow in underlay net namespace Xiao Liang
2024-12-09 14:01 ` [PATCH net-next v5 5/5] selftests: net: Add two test cases for link netns Xiao Liang
[not found] ` <4a2fe99a-772d-4df1-a8ef-14338682b69e@redhat.com>
2024-12-12 13:06 ` Xiao Liang
[not found] ` <20241209140151.231257-4-shaw.leon@gmail.com>
2024-12-12 9:27 ` [PATCH net-next v5 3/5] rtnetlink: Decouple net namespaces in rtnl_newlink_create() Paolo Abeni
2024-12-12 12:41 ` Xiao Liang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).