summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/sock_iter_batch.c
diff options
context:
space:
mode:
authorJordan Rife <jordan@jrife.io>2025-07-14 11:09:15 -0700
committerMartin KaFai Lau <martin.lau@kernel.org>2025-07-14 15:12:54 -0700
commit8fc0c5a82d04e1582b666e3c407340e66493608f (patch)
treebb12be6d89722750f2a31ef544847b410337cb99 /tools/testing/selftests/bpf/progs/sock_iter_batch.c
parent07ebabbbfe9b4c95e8f1f144f21c07fe830fa501 (diff)
selftests/bpf: Create iter_tcp_destroy test program
Prepare for bucket resume tests for established TCP sockets by creating a program to immediately destroy and remove sockets from the TCP ehash table, since close() is not deterministic. 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>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/sock_iter_batch.c')
-rw-r--r--tools/testing/selftests/bpf/progs/sock_iter_batch.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/sock_iter_batch.c b/tools/testing/selftests/bpf/progs/sock_iter_batch.c
index a36361e4a5ded..77966ded54678 100644
--- a/tools/testing/selftests/bpf/progs/sock_iter_batch.c
+++ b/tools/testing/selftests/bpf/progs/sock_iter_batch.c
@@ -70,6 +70,27 @@ int iter_tcp_soreuse(struct bpf_iter__tcp *ctx)
return 0;
}
+volatile const __u64 destroy_cookie;
+
+SEC("iter/tcp")
+int iter_tcp_destroy(struct bpf_iter__tcp *ctx)
+{
+ struct sock_common *sk_common = (struct sock_common *)ctx->sk_common;
+ __u64 sock_cookie;
+
+ if (!sk_common)
+ return 0;
+
+ sock_cookie = bpf_get_socket_cookie(sk_common);
+ if (sock_cookie != destroy_cookie)
+ return 0;
+
+ bpf_sock_destroy(sk_common);
+ bpf_seq_write(ctx->meta->seq, &sock_cookie, sizeof(sock_cookie));
+
+ return 0;
+}
+
#define udp_sk(ptr) container_of(ptr, struct udp_sock, inet.sk)
SEC("iter/udp")