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

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-7-thinker.li@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/testing/selftests/bpf/prog_tests/select_reuseport.c

index 64c5f5eb2994fff15da964ce7b3ada5e517fc7fd..036d4760d2c16ceb5e928f9347a51c6ea22206e3 100644 (file)
@@ -37,9 +37,7 @@ static int sk_fds[REUSEPORT_ARRAY_SIZE];
 static int reuseport_array = -1, outer_map = -1;
 static enum bpf_map_type inner_map_type;
 static int select_by_skb_data_prog;
-static int saved_tcp_syncookie = -1;
 static struct bpf_object *obj;
-static int saved_tcp_fo = -1;
 static __u32 index_zero;
 static int epfd;
 
@@ -193,14 +191,6 @@ static int write_int_sysctl(const char *sysctl, int v)
        return 0;
 }
 
-static void restore_sysctls(void)
-{
-       if (saved_tcp_fo != -1)
-               write_int_sysctl(TCP_FO_SYSCTL, saved_tcp_fo);
-       if (saved_tcp_syncookie != -1)
-               write_int_sysctl(TCP_SYNCOOKIE_SYSCTL, saved_tcp_syncookie);
-}
-
 static int enable_fastopen(void)
 {
        int fo;
@@ -793,6 +783,7 @@ static void test_config(int sotype, sa_family_t family, bool inany)
                TEST_INIT(test_pass_on_err),
                TEST_INIT(test_detach_bpf),
        };
+       struct netns_obj *netns;
        char s[MAX_TEST_NAME];
        const struct test *t;
 
@@ -808,9 +799,21 @@ static void test_config(int sotype, sa_family_t family, bool inany)
                if (!test__start_subtest(s))
                        continue;
 
+               netns = netns_new("select_reuseport", true);
+               if (!ASSERT_OK_PTR(netns, "netns_new"))
+                       continue;
+
+               if (CHECK_FAIL(enable_fastopen()))
+                       goto out;
+               if (CHECK_FAIL(disable_syncookie()))
+                       goto out;
+
                setup_per_test(sotype, family, inany, t->no_inner_map);
                t->fn(sotype, family);
                cleanup_per_test(t->no_inner_map);
+
+out:
+               netns_free(netns);
        }
 }
 
@@ -850,21 +853,7 @@ out:
 
 void serial_test_select_reuseport(void)
 {
-       saved_tcp_fo = read_int_sysctl(TCP_FO_SYSCTL);
-       if (saved_tcp_fo < 0)
-               goto out;
-       saved_tcp_syncookie = read_int_sysctl(TCP_SYNCOOKIE_SYSCTL);
-       if (saved_tcp_syncookie < 0)
-               goto out;
-
-       if (enable_fastopen())
-               goto out;
-       if (disable_syncookie())
-               goto out;
-
        test_map_type(BPF_MAP_TYPE_REUSEPORT_SOCKARRAY);
        test_map_type(BPF_MAP_TYPE_SOCKMAP);
        test_map_type(BPF_MAP_TYPE_SOCKHASH);
-out:
-       restore_sysctls();
 }