From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.zx2c4.com (lists.zx2c4.com [165.227.139.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54E79D4923E for ; Mon, 18 Nov 2024 15:43:02 +0000 (UTC) Received: by lists.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 1ec62feb; Mon, 18 Nov 2024 12:45:34 +0000 (UTC) Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [2607:f8b0:4864:20::102a]) by lists.zx2c4.com (ZX2C4 Mail Server) with ESMTPS id 0a620ef8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 13 Nov 2024 12:58:28 +0000 (UTC) Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2e9e377aeadso1740151a91.1 for ; Wed, 13 Nov 2024 04:58:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731502707; x=1732107507; darn=lists.zx2c4.com; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tqrrLk6+C692qIcVQOp9KatlJAZHjGryjisTBrwbzoI=; b=P6AzMGt4g9ko1rfiZZM91s/qcXS1OlHy67fyM6rCOMPTvVelA9h8jI63nRykEYUAY+ pp2jz0WElnhVg732s7FFzciRgfBJJrI9T0wOfDcUtQwE4GzII11Ybr1i9weI9//fU/O1 mzi6ZLOMq0sX+kTJPwj6v/Vjhl7n1xQxgFtLqj3gz7ajGHOJrbPM17EiuShSH6ctW1Sr LNYxB1wiwSEuFNfnL3rNEZurZmoPVUQSHyZoqA1pKYipeNhHPB5XoFylogGZOVdqPz3X H2BkwMYN57A2vsMgzSu+Q+di7J5BDJ0FCU/VPyi8NSPbEv8bmYRpDwGi7gGyXTS0Rz4x iM3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731502707; x=1732107507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tqrrLk6+C692qIcVQOp9KatlJAZHjGryjisTBrwbzoI=; b=u5aWlcCrXSva1p9RkaNqRB9nIIZD8FM061vvChLmKXFkV1msbBKEj9qFe2piZFfKpk mkjKTfuGElNRTkl7FmsLU1j2xseozeCK/B+ZVq6bIjE5bwUHb40VzQ43Z4Rn9z6Zwykw 3njV7e9BnPmwx0Gi/X7VgXODWGhed4ZBewTwn3mcRdRA2z/cc9dr1c5DCAqEN73Xv4Ae aTm1a3NQ1xlw4zU19c6lvc/pz3/5hEcFnhsmSVTnDI8KBKQr9tsK/Tb8zGlmc6CVsQiV LRU67oCsgLiymmBRktAq7EKssZv3gLy0Kv0auYSLanH+R8q48UNeB7uiUILLYRfx4bDM EjdQ== X-Forwarded-Encrypted: i=1; AJvYcCXkLDqUA2zh9cRrOPj5WFH/OM+NIxuLYdqhker1i7RMYJucXKkpScdwTrhxoCoeoMMjWFXX6yJ/n50=@lists.zx2c4.com X-Gm-Message-State: AOJu0YyoC5HgG86RkZtYIhwzZNxYK7dyPyAuNV08tsbfh6yGaWV1e4EB iakgudb5Mor9j0w0zek9pYYWvACWUt1YQo/EMvZPXCimGu1KVYx1 X-Google-Smtp-Source: AGHT+IE/vtXg73mPc9UwMocIh3JnpJ4Nx9KNFh/J++F7E0J+l3pL2CaZbF6bhZwKtLiUviIv9q/4Rw== X-Received: by 2002:a17:90b:3c12:b0:2e2:b2ce:e41e with SMTP id 98e67ed59e1d1-2e9f2c78421mr3106773a91.13.1731502707231; Wed, 13 Nov 2024 04:58:27 -0800 (PST) Received: from nova-ws.. ([103.167.140.11]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9f3f8ed0esm1398632a91.40.2024.11.13.04.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2024 04:58:26 -0800 (PST) From: Xiao Liang To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, 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@vger.kernel.org, linux-can@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, bpf@vger.kernel.org, linux-ppp@vger.kernel.org, wireguard@lists.zx2c4.com, linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, bridge@lists.linux.dev, linux-wpan@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 6/6] selftests: net: Add two test cases for link netns Date: Wed, 13 Nov 2024 20:57:15 +0800 Message-ID: <20241113125715.150201-7-shaw.leon@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241113125715.150201-1-shaw.leon@gmail.com> References: <20241113125715.150201-1-shaw.leon@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 18 Nov 2024 12:44:56 +0000 X-BeenThere: wireguard@lists.zx2c4.com X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: Development discussion of WireGuard List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: wireguard-bounces@lists.zx2c4.com Sender: "WireGuard" - 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 --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/netns-name.sh | 10 ++++++ tools/testing/selftests/net/netns_atomic.py | 38 +++++++++++++++++++++ 3 files changed, 49 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 2b2a5ec7fa6a..4c15a115c251 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..e6c4147ef75e --- /dev/null +++ b/tools/testing/selftests/net/netns_atomic.py @@ -0,0 +1,38 @@ +#!/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(not rtnl.async_msg_queue, "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.0