tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c- Extension
.c- Size
- 4375 bytes
- Lines
- 173
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
test_progs.hcgroup_helpers.hnetwork_helpers.hsockopt_inherit.skel.h
Detected Declarations
function verify_sockoptfunction custom_cbfunction run_testfunction test_sockopt_inherit
Annotated Snippet
if (err) {
log_err("Failed to call setsockopt(%d)", i);
return -1;
}
}
return 0;
}
static void run_test(int cgroup_fd)
{
struct bpf_link *link_getsockopt = NULL;
struct bpf_link *link_setsockopt = NULL;
struct network_helper_opts opts = {
.post_socket_cb = custom_cb,
};
int server_fd = -1, client_fd;
struct sockaddr_in addr = {
.sin_family = AF_INET,
.sin_addr.s_addr = htonl(INADDR_LOOPBACK),
};
struct sockopt_inherit *obj;
void *server_err;
pthread_t tid;
int err;
obj = sockopt_inherit__open_and_load();
if (!ASSERT_OK_PTR(obj, "skel-load"))
return;
obj->bss->page_size = sysconf(_SC_PAGESIZE);
link_getsockopt = bpf_program__attach_cgroup(obj->progs._getsockopt,
cgroup_fd);
if (!ASSERT_OK_PTR(link_getsockopt, "cg-attach-getsockopt"))
goto close_bpf_object;
link_setsockopt = bpf_program__attach_cgroup(obj->progs._setsockopt,
cgroup_fd);
if (!ASSERT_OK_PTR(link_setsockopt, "cg-attach-setsockopt"))
goto close_bpf_object;
server_fd = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr,
sizeof(addr), &opts);
if (!ASSERT_GE(server_fd, 0, "start_server"))
goto close_bpf_object;
pthread_mutex_lock(&server_started_mtx);
if (!ASSERT_OK(pthread_create(&tid, NULL, server_thread,
(void *)&server_fd), "pthread_create")) {
pthread_mutex_unlock(&server_started_mtx);
goto close_server_fd;
}
pthread_cond_wait(&server_started, &server_started_mtx);
pthread_mutex_unlock(&server_started_mtx);
client_fd = connect_to_fd(server_fd, 0);
if (!ASSERT_GE(client_fd, 0, "connect_to_server"))
goto close_server_fd;
ASSERT_OK(verify_sockopt(client_fd, CUSTOM_INHERIT1, "connect", 0), "verify_sockopt1");
ASSERT_OK(verify_sockopt(client_fd, CUSTOM_INHERIT2, "connect", 0), "verify_sockopt2");
ASSERT_OK(verify_sockopt(client_fd, CUSTOM_LISTENER, "connect", 0), "verify_sockopt ener");
pthread_join(tid, &server_err);
err = (int)(long)server_err;
ASSERT_OK(err, "pthread_join retval");
close(client_fd);
close_server_fd:
close(server_fd);
close_bpf_object:
bpf_link__destroy(link_getsockopt);
bpf_link__destroy(link_setsockopt);
sockopt_inherit__destroy(obj);
}
void test_sockopt_inherit(void)
{
int cgroup_fd;
cgroup_fd = test__join_cgroup("/sockopt_inherit");
if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup"))
return;
run_test(cgroup_fd);
close(cgroup_fd);
Annotation
- Immediate include surface: `test_progs.h`, `cgroup_helpers.h`, `network_helpers.h`, `sockopt_inherit.skel.h`.
- Detected declarations: `function verify_sockopt`, `function custom_cb`, `function run_test`, `function test_sockopt_inherit`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.