selftests/bpf: Allow for iteration over multiple ports

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>
This commit is contained in:
Jordan Rife 2025-07-14 11:09:11 -07:00 committed by Martin KaFai Lau
parent da1d987d3b
commit 346066c327
2 changed files with 6 additions and 5 deletions

View 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);

View 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;