BPF List
 help / color / mirror / Atom feed
From: "Bastien Curutchet (eBPF Foundation)" <bastien.curutchet@bootlin.com>
To: Alexei Starovoitov <ast@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	 Martin KaFai Lau <martin.lau@linux.dev>,
	 Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	 Yonghong Song <yonghong.song@linux.dev>,
	 John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	 Stanislav Fomichev <sdf@fomichev.me>,
	Hao Luo <haoluo@google.com>,  Jiri Olsa <jolsa@kernel.org>,
	Mykola Lysenko <mykolal@fb.com>,  Shuah Khan <shuah@kernel.org>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	 Alexis Lothore <alexis.lothore@bootlin.com>,
	bpf@vger.kernel.org,  linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	 "Bastien Curutchet (eBPF Foundation)"
	<bastien.curutchet@bootlin.com>
Subject: [PATCH bpf-next 1/3] selftests/bpf: tc_helpers: Add create_and_open_tid_ns()
Date: Mon, 17 Feb 2025 13:37:38 +0100	[thread overview]
Message-ID: <20250217-tc_links-v1-1-27f7965e3dcd@bootlin.com> (raw)
In-Reply-To: <20250217-tc_links-v1-0-27f7965e3dcd@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) <bastien.curutchet@bootlin.com>
---
 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 <test_progs.h>
+#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 */

-- 
2.48.1


  reply	other threads:[~2025-02-17 12:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-17 12:37 [PATCH bpf-next 0/3] selftests/bpf: tc_links/tc_opts: Unserialize tests Bastien Curutchet (eBPF Foundation)
2025-02-17 12:37 ` Bastien Curutchet (eBPF Foundation) [this message]
2025-02-17 12:37 ` [PATCH bpf-next 2/3] selftests/bpf: tc_link/tc_opts: Use unique namespace Bastien Curutchet (eBPF Foundation)
2025-02-17 12:37 ` [PATCH bpf-next 3/3] selftests/bpf: tc_links/tc_opts: Serialize tests Bastien Curutchet (eBPF Foundation)
2025-02-18 21:22 ` [PATCH bpf-next 0/3] selftests/bpf: tc_links/tc_opts: Unserialize tests Stanislav Fomichev
2025-02-19  3:40   ` Alexei Starovoitov
2025-02-19  7:44     ` Bastien Curutchet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250217-tc_links-v1-1-27f7965e3dcd@bootlin.com \
    --to=bastien.curutchet@bootlin.com \
    --cc=alexis.lothore@bootlin.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox