]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Monitor traffic for tc_redirect.
authorKui-Feng Lee <thinker.li@gmail.com>
Thu, 15 Aug 2024 05:32:52 +0000 (22:32 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 15 Aug 2024 19:26:56 +0000 (12:26 -0700)
Enable traffic monitoring for the test case tc_redirect.

Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
Link: https://lore.kernel.org/r/20240815053254.470944-5-thinker.li@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/testing/selftests/bpf/prog_tests/tc_redirect.c

index 53b8ffc943dce9ff11215b499a875966b1154b23..974f9d6269c94f96c7d4c61fa3a0c02a2bdb9d97 100644 (file)
@@ -68,6 +68,7 @@
                __FILE__, __LINE__, strerror(errno), ##__VA_ARGS__)
 
 static const char * const namespaces[] = {NS_SRC, NS_FWD, NS_DST, NULL};
+static struct netns_obj *netns_objs[3];
 
 static int write_file(const char *path, const char *newval)
 {
@@ -87,27 +88,41 @@ static int write_file(const char *path, const char *newval)
 
 static int netns_setup_namespaces(const char *verb)
 {
+       struct netns_obj **ns_obj = netns_objs;
        const char * const *ns = namespaces;
-       char cmd[128];
 
        while (*ns) {
-               snprintf(cmd, sizeof(cmd), "ip netns %s %s", verb, *ns);
-               if (!ASSERT_OK(system(cmd), cmd))
-                       return -1;
+               if (strcmp(verb, "add") == 0) {
+                       *ns_obj = netns_new(*ns, false);
+                       if (!ASSERT_OK_PTR(*ns_obj, "netns_new"))
+                               return -1;
+               } else {
+                       if (!ASSERT_OK_PTR(*ns_obj, "netns_obj is NULL"))
+                               return -1;
+                       netns_free(*ns_obj);
+                       *ns_obj = NULL;
+               }
                ns++;
+               ns_obj++;
        }
        return 0;
 }
 
 static void netns_setup_namespaces_nofail(const char *verb)
 {
+       struct netns_obj **ns_obj = netns_objs;
        const char * const *ns = namespaces;
-       char cmd[128];
 
        while (*ns) {
-               snprintf(cmd, sizeof(cmd), "ip netns %s %s > /dev/null 2>&1", verb, *ns);
-               system(cmd);
+               if (strcmp(verb, "add") == 0) {
+                       *ns_obj = netns_new(*ns, false);
+               } else {
+                       if (*ns_obj)
+                               netns_free(*ns_obj);
+                       *ns_obj = NULL;
+               }
                ns++;
+               ns_obj++;
        }
 }