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.curutc...@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 via email to