Skip to content

Commit 346066c

Browse files
jrifeMartin KaFai Lau
authored andcommitted
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 <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Stanislav Fomichev <[email protected]>
1 parent da1d987 commit 346066c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

tools/testing/selftests/bpf/prog_tests/sock_iter_batch.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ static void do_resume_test(struct test_case *tc)
416416
int err, iter_fd = -1;
417417
const char *addr;
418418
int *fds = NULL;
419-
int local_port;
420419

421420
counts = calloc(tc->max_socks, sizeof(*counts));
422421
if (!ASSERT_OK_PTR(counts, "counts"))
@@ -431,10 +430,8 @@ static void do_resume_test(struct test_case *tc)
431430
tc->init_socks);
432431
if (!ASSERT_OK_PTR(fds, "start_reuseport_server"))
433432
goto done;
434-
local_port = get_socket_local_port(*fds);
435-
if (!ASSERT_GE(local_port, 0, "get_socket_local_port"))
436-
goto done;
437-
skel->rodata->ports[0] = ntohs(local_port);
433+
skel->rodata->ports[0] = 0;
434+
skel->rodata->ports[1] = 0;
438435
skel->rodata->sf = tc->family;
439436

440437
err = sock_iter_batch__load(skel);

tools/testing/selftests/bpf/progs/sock_iter_batch.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ int iter_tcp_soreuse(struct bpf_iter__tcp *ctx)
5252
idx = 0;
5353
else if (sk->sk_num == ports[1])
5454
idx = 1;
55+
else if (!ports[0] && !ports[1])
56+
idx = 0;
5557
else
5658
return 0;
5759

@@ -92,6 +94,8 @@ int iter_udp_soreuse(struct bpf_iter__udp *ctx)
9294
idx = 0;
9395
else if (sk->sk_num == ports[1])
9496
idx = 1;
97+
else if (!ports[0] && !ports[1])
98+
idx = 0;
9599
else
96100
return 0;
97101

0 commit comments

Comments
 (0)