diff mbox series

[bpf-next,1/3] selftests/bpf: tc_helpers: Add create_and_open_tid_ns()

Message ID 20250217-tc_links-v1-1-27f7965e3dcd@bootlin.com (mailing list archive)
State New
Headers show
Series selftests/bpf: tc_links/tc_opts: Unserialize tests | expand

Commit Message

Bastien Curutchet (eBPF Foundation) Feb. 17, 2025, 12:37 p.m. UTC
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 mbox series

Patch

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 */