tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/sockmap_listen.c- Extension
.c- Size
- 32171 bytes
- Lines
- 1441
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/compiler.herrno.herror.hlimits.hnetinet/in.hpthread.hstdlib.hstring.hsys/select.hunistd.hlinux/vm_sockets.hbpf/bpf.hbpf/libbpf.hbpf_util.htest_progs.htest_sockmap_listen.skel.hsockmap_helpers.h
Detected Declarations
struct connect_accept_ctxenum redir_modefunction test_insert_invalidfunction test_insert_openedfunction test_insert_boundfunction test_insertfunction test_delete_after_insertfunction test_delete_after_closefunction test_lookup_after_insertfunction test_lookup_after_deletefunction test_lookup_32_bit_valuefunction test_update_existingfunction acceptfunction test_destroy_orphan_childfunction test_clone_after_deletefunction test_accept_after_deletefunction test_accept_before_deletefunction is_thread_donefunction test_syn_recv_insert_deletefunction test_race_insert_listenfunction zero_verdict_countfunction redir_to_connectedfunction test_skb_redir_to_connectedfunction test_msg_redir_to_connectedfunction test_msg_redir_to_connected_with_linkfunction redir_to_listeningfunction test_skb_redir_to_listeningfunction test_msg_redir_to_listeningfunction test_msg_redir_to_listening_with_linkfunction redir_partialfunction test_skb_redir_partialfunction test_reuseport_select_listeningfunction test_reuseport_select_connectedfunction test_reuseport_mixed_groupsfunction test_ops_cleanupfunction test_opsfunction test_redirfunction test_reuseportfunction run_testsfunction serial_test_sockmap_listen
Annotated Snippet
struct connect_accept_ctx {
int sockfd;
unsigned int done;
unsigned int nr_iter;
};
static bool is_thread_done(struct connect_accept_ctx *ctx)
{
return READ_ONCE(ctx->done);
}
static void *connect_accept_thread(void *arg)
{
struct connect_accept_ctx *ctx = arg;
struct sockaddr_storage addr;
int family, socktype;
socklen_t len;
int err, i, s;
s = ctx->sockfd;
len = sizeof(addr);
err = xgetsockname(s, sockaddr(&addr), &len);
if (err)
goto done;
len = sizeof(family);
err = xgetsockopt(s, SOL_SOCKET, SO_DOMAIN, &family, &len);
if (err)
goto done;
len = sizeof(socktype);
err = xgetsockopt(s, SOL_SOCKET, SO_TYPE, &socktype, &len);
if (err)
goto done;
for (i = 0; i < ctx->nr_iter; i++) {
int c, p;
c = xsocket(family, socktype, 0);
if (c < 0)
break;
err = xconnect(c, (struct sockaddr *)&addr, sizeof(addr));
if (err) {
xclose(c);
break;
}
p = xaccept_nonblock(s, NULL, NULL);
if (p < 0) {
xclose(c);
break;
}
xclose(p);
xclose(c);
}
done:
WRITE_ONCE(ctx->done, 1);
return NULL;
}
static void test_syn_recv_insert_delete(struct test_sockmap_listen *skel __always_unused,
int family, int sotype, int mapfd)
{
struct connect_accept_ctx ctx = { 0 };
struct sockaddr_storage addr;
socklen_t len;
u32 zero = 0;
pthread_t t;
int err, s;
u64 value;
s = socket_loopback(family, sotype | SOCK_NONBLOCK);
if (s < 0)
return;
len = sizeof(addr);
err = xgetsockname(s, sockaddr(&addr), &len);
if (err)
goto close;
ctx.sockfd = s;
ctx.nr_iter = 1000;
err = xpthread_create(&t, NULL, connect_accept_thread, &ctx);
if (err)
goto close;
Annotation
- Immediate include surface: `linux/compiler.h`, `errno.h`, `error.h`, `limits.h`, `netinet/in.h`, `pthread.h`, `stdlib.h`, `string.h`.
- Detected declarations: `struct connect_accept_ctx`, `enum redir_mode`, `function test_insert_invalid`, `function test_insert_opened`, `function test_insert_bound`, `function test_insert`, `function test_delete_after_insert`, `function test_delete_after_close`, `function test_lookup_after_insert`, `function test_lookup_after_delete`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.