]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftests/bpf: Allow for iteration over multiple ports
authorJordan Rife <jordan@jrife.io>
Mon, 14 Jul 2025 18:09:11 +0000 (11:09 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Mon, 14 Jul 2025 19:09:09 +0000 (12:09 -0700)
Prepare to test TCP socket iteration over both listening and established
sockets by allowing the BPF iterator programs to skip the port check.

Signed-off-by: Jordan Rife <jordan@jrife.io>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
tools/testing/selftests/bpf/prog_tests/sock_iter_batch.c
tools/testing/selftests/bpf/progs/sock_iter_batch.c

index 2adacd91fdf894b15899b9c86ef94e854147f1e7..0d0f1b4debff56d2b5ab0d7dc377bd87a5362ecb 100644 (file)
@@ -416,7 +416,6 @@ static void do_resume_test(struct test_case *tc)
        int err, iter_fd = -1;
        const char *addr;
        int *fds = NULL;
-       int local_port;
 
        counts = calloc(tc->max_socks, sizeof(*counts));
        if (!ASSERT_OK_PTR(counts, "counts"))
@@ -431,10 +430,8 @@ static void do_resume_test(struct test_case *tc)
                                     tc->init_socks);
        if (!ASSERT_OK_PTR(fds, "start_reuseport_server"))
                goto done;
-       local_port = get_socket_local_port(*fds);
-       if (!ASSERT_GE(local_port, 0, "get_socket_local_port"))
-               goto done;
-       skel->rodata->ports[0] = ntohs(local_port);
+       skel->rodata->ports[0] = 0;
+       skel->rodata->ports[1] = 0;
        skel->rodata->sf = tc->family;
 
        err = sock_iter_batch__load(skel);
index 8f483337e103c955ea44d7109bb0ca90c4301de6..40dce6a38c30f9c9e871494c76de2cebd8741c78 100644 (file)
@@ -52,6 +52,8 @@ int iter_tcp_soreuse(struct bpf_iter__tcp *ctx)
                idx = 0;
        else if (sk->sk_num == ports[1])
                idx = 1;
+       else if (!ports[0] && !ports[1])
+               idx = 0;
        else
                return 0;
 
@@ -92,6 +94,8 @@ int iter_udp_soreuse(struct bpf_iter__udp *ctx)
                idx = 0;
        else if (sk->sk_num == ports[1])
                idx = 1;
+       else if (!ports[0] && !ports[1])
+               idx = 0;
        else
                return 0;