From patchwork Mon Feb 17 12:37:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Bastien Curutchet (eBPF Foundation)" X-Patchwork-Id: 13977709 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39C711A5BA4; Mon, 17 Feb 2025 12:37:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739795866; cv=none; b=VDxBODCIUHeAVy/mqwpX3XKAJ3WVEOIhAhD7kV/yu5t/Qy+DKOY619s/OvPKqQ7zbYFqy1xOQsNd2dAvjHQ1GrD18q90THnVYsxporWBRITzU6L+JswKLFe7F6jkbA/7lK6os+HtWn/puHwIASesbJjEmDdcFkHNzciWW9jTGG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739795866; c=relaxed/simple; bh=mZzKihe2R4AeNltn5V5ya+wh7hY4j98NTVDIxiw5HPA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KbK6kvSw6N9h0tETb3c0lExD+v9tLBaaAmILNaeb3phWmjV0QPdONqcAPHE1QHX+nTUzADS9R0ObAMJu8iwoIqF0ioGKIamhqrr4MNkj0x3GxiK/HV07hdrdh2Mk0Kb7zgb7Fi67+NAHeVwgoeUhqR0nJw3me2HMlS/wo95155o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=eBgdJQEz; arc=none smtp.client-ip=217.70.183.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="eBgdJQEz" Received: by mail.gandi.net (Postfix) with ESMTPSA id 51CA8442DF; Mon, 17 Feb 2025 12:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739795861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6+tzLfaFZqkqHQMe4gTyO4D+W5I8sg9zaCereRpJS2A=; b=eBgdJQEzBthDRYbwStmJVO+wxfYFnnGavpQgDiKis0qd3QfD4EPlnNAuYQWubK832uyodd GOXZ+y3PVL0YoDgixgJtCIpLb2m2MwAtLmgKoWG5p045ikdaMwINhKYloU3p+0HjB2tlhw rTJtq7G8FuVqGK0jfqgYpbdOt6P6uakKeAj+udypIt9hz1Doi2To33YMei9UotIKaJGQEA GL9r/HdiAIPzpV+T233TqZp1ZB7GgGGBHiHGs2rl6UrQYVqT+LRCrrShts0zMhrVEIj3A7 jrJK5d24N1nWlxgJTC1lHaxzOYUs3RbfBj71i8XtTT8bZUwRd9UJqtvVD+UdGg== From: "Bastien Curutchet (eBPF Foundation)" Date: Mon, 17 Feb 2025 13:37:38 +0100 Subject: [PATCH bpf-next 1/3] selftests/bpf: tc_helpers: Add create_and_open_tid_ns() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-tc_links-v1-1-27f7965e3dcd@bootlin.com> References: <20250217-tc_links-v1-0-27f7965e3dcd@bootlin.com> In-Reply-To: <20250217-tc_links-v1-0-27f7965e3dcd@bootlin.com> To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan Cc: Thomas Petazzoni , Alexis Lothore , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Bastien Curutchet (eBPF Foundation)" X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdehkeegvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpedfuegrshhtihgvnhcuvehurhhuthgthhgvthculdgvuefrhfcuhfhouhhnuggrthhiohhnmddfuceosggrshhtihgvnhdrtghurhhuthgthhgvthessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepgeefudfhuedttdeiffetffeljeffkeevveeiuddtgeejleeftdejgedtjedttdfhnecukfhppeeltddrkeelrdduieefrdduvdejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledtrdekledrudeifedruddvjedphhgvlhhopegludelvddrudeikedrtddrudegngdpmhgrihhlfhhrohhmpegsrghsthhivghnrdgtuhhruhhttghhvghtsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvtddprhgtphhtthhopehshhhurghhsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehsohhngheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprghstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrdgtohhmpdhrtghpthhtoheprghnughri hhisehkvghrnhgvlhdrohhrghdprhgtphhtthhopehsughfsehfohhmihgthhgvvhdrmhgvpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhugidruggvvhdprhgtphhtthhopegvugguhiiikeejsehgmhgrihhlrdgtohhm X-GND-Sasl: bastien.curutchet@bootlin.com Add a create_and_open_tid_ns() helper that creates a new network namespace and open it. Use the append_tid() helper to ensure the uniqueness of the namespace name. Signed-off-by: Bastien Curutchet (eBPF Foundation) --- tools/testing/selftests/bpf/prog_tests/tc_helpers.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/tc_helpers.h b/tools/testing/selftests/bpf/prog_tests/tc_helpers.h index 924d0e25320c71691998d6fce4d0aae367457862..8689ecd88fa89f4e622729d4f1b6d33c25fa89d8 100644 --- a/tools/testing/selftests/bpf/prog_tests/tc_helpers.h +++ b/tools/testing/selftests/bpf/prog_tests/tc_helpers.h @@ -3,6 +3,7 @@ #ifndef TC_HELPERS #define TC_HELPERS #include +#include "network_helpers.h" #ifndef loopback # define loopback 1 @@ -75,4 +76,15 @@ static inline void tc_skel_reset_all_seen(struct test_tc_link *skel) memset(skel->bss, 0, sizeof(*skel->bss)); } +static inline struct netns_obj *create_and_open_tid_ns(char *ns_name, size_t sz) +{ + if (!ns_name) + return NULL; + + if (append_tid(ns_name, sz)) + return NULL; + + return netns_new(ns_name, true); +} + #endif /* TC_HELPERS */