From patchwork Wed Nov 13 12:57:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Liang X-Patchwork-Id: 18683 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id 9EB69840CE for ; Wed, 13 Nov 2024 14:06:12 +0100 (CET) ARC-Seal: i=2; cv=pass; a=rsa-sha256; d=open-mesh.org; s=20121; t=1731503172; b=21reG10JK2wXCF6+IaF/U8XhODXrEYVOsZEDyU72+THFohYcM06syvBlL0w+Bwv3+Jomd wCBFXJ2ovmVHUswwnq3BvulUU00UogecMNCvujrXnllea0MVwiDFBxUbjE1MyFhBjMZpDoA hgA1VK0xeu2ksmmvnRsLr43BgMeX3Os= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731503172; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=tqrrLk6+C692qIcVQOp9KatlJAZHjGryjisTBrwbzoI=; b=AeVROxn74NJT67CKAYm9Y/eRRoYCqfot/e2KeTLX8UxKzO8uAqM1kH7o86KkLJGJeqGHk T6t67kJPGZtURaxdWIfH7rdhtd57yAI+/4Ad2D0pp8HNyImrjWUQKH2rt7JRWz0z4avadCc J1lBkyNuaGLvgYITYaVzL3+81IrEnkk= ARC-Authentication-Results: i=2; open-mesh.org; dkim=pass header.d=gmail.com; arc=pass; dmarc=pass (Used From Domain Record) header.from=gmail.com policy.dmarc=quarantine Authentication-Results: open-mesh.org; dkim=pass header.d=gmail.com; arc=pass; dmarc=pass (Used From Domain Record) header.from=gmail.com policy.dmarc=quarantine Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by diktynna.open-mesh.org (Postfix) with ESMTPS id C4F708357C for ; Wed, 13 Nov 2024 13:58:28 +0100 (CET) ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1731502708; a=rsa-sha256; cv=none; b=vRrXCqWJCqU7hTF+yGEhuH5rNHaQpxfGPNt+rTbNUQywFTUoojfCX2x4IvhC5b9Oktq77U urzodTr20k/63vuyiY2yrlJSi3bNe0UJPuHigC8R9RHNWcT5ZF2VCRyP/X3KPFWWBI1pdm 2BAh8wtC8ZvmnWKOfqPEmh9JZs9ACpQ= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=pass header.d=gmail.com header.s=20230601 header.b=K9XLUMzT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (diktynna.open-mesh.org: domain of shaw.leon@gmail.com designates 2607:f8b0:4864:20::1029 as permitted sender) smtp.mailfrom=shaw.leon@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1731502708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tqrrLk6+C692qIcVQOp9KatlJAZHjGryjisTBrwbzoI=; b=n1NxZFLQJsRlJWSdzjhFtFwiVkNjKprIpfbriNWQ2p/q0goj3Ql/wy8Pv6gj2w0w+nV4ws bGyR4GC1yzUFqkqU03VFYBZEuv3WHGtb9Ua6HfsYuBSlqCxpXyO97TuI9eBCt1vfplMp4v 0hSb7Mbqlm557YrBDhY0Blo5PYo7ReI= Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-2e2eb9dde40so5533428a91.0 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.open-mesh.org; 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=K9XLUMzTXsj4ZgXcgDNzqpW2DTxsdViWCH2h9KVXlmBLmhK23A81pivW1+h+embJjZ F9liJtVqUl1WzJl9n61TEr5Xbr/qIAK0SavKGjVB0j93ABhKpDzMn8XvFbMpXey/WryP pSFBTHtJqigRuhxPqbxRmzJG4cziHY7rZNlNm3YjzJ/7DI6FzKts51MVdnuqq8V/4Pg9 ddfIhNQQ0BbDP0Owf+ECi7GrBYkNCCx9+EE3lCCUSICzdUfJpWgkNrIkrFUMxzbeF1BL krmZQq4HXCGhNjq2qv5A4VdkQkk/iP86PWv5NA+M7qYgIJXong/m7QtNnOgWr9tzq2zm pXPQ== 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=Euxltf/3XaFa+0FeW49RGv4FsOjpSGJljiiT2xo8vxj9ZtLocwhz/smbmyoOxAy3CP 7xeFKjLN8m0OwtpxKKOl4qos53XKfcg8Hvs8dNdEOfmjLZI4wX1w/9xrwzJHbR1zTbtG /A96wowBfhncfNy/BDBsotS4nE9W9lLpFZ4axtZ4baHsMtc+illlG3JxtLY6i0tVkf/E GCfqsnmcu1xBVmQSevIb+lxGVquiHA2VPJcHzZG5gkTW9XP9buSsyE8mnz6PvXz1/Cqw iX0xBLA/BByAltS4xSJ4F/LvHh2gzh7Q2IO0rYLY4cywk6yXaMnpiDrx0wQIXJjYhnMA MIVg== X-Forwarded-Encrypted: i=1; AJvYcCVpdp48FywFde73ypzZejEz/bB9KQNKPlmUQJf6P5p5ifIOdVcbKE+VN8SJgMU9ZSztSYVMkoEFUJq9GA==@lists.open-mesh.org X-Gm-Message-State: AOJu0YwPpFbnYJ/iOjSVzha5JkBvHAtjlxkcOuo4YKyFtBrnpxQqVJEn AWd33r80mKwsvtHXO1kkHIFK7JfYeaC+ETLLbEa8MpzaZK+Gvvpl 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 X-MailFrom: shaw.leon@gmail.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; header-match-b.a.t.m.a.n.lists.open-mesh.org-2 Message-ID-Hash: EW6CZU6Y26EOJMAWL5UKD4YF3LYG75PQ X-Message-ID-Hash: EW6CZU6Y26EOJMAWL5UKD4YF3LYG75PQ X-Mailman-Approved-At: Wed, 13 Nov 2024 14:00:42 +0100 X-Mailman-Version: 3.3.8 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: - 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()