tools/testing/selftests/bpf/prog_tests/flow_dissector_reattach.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/flow_dissector_reattach.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/flow_dissector_reattach.c- Extension
.c- Size
- 18448 bytes
- Lines
- 679
- 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
errno.hfcntl.hsched.hstdbool.hsys/stat.hunistd.hlinux/bpf.hbpf/bpf.htest_progs.h
Detected Declarations
struct testfunction query_attached_prog_idfunction prog_is_attachedfunction load_progfunction query_prog_idfunction unshare_netfunction test_prog_attach_prog_attachfunction test_link_create_link_createfunction test_prog_attach_link_createfunction test_link_create_prog_attachfunction test_link_create_prog_detachfunction test_prog_attach_detach_queryfunction test_link_create_close_queryfunction test_link_update_no_old_progfunction test_link_update_replace_old_progfunction test_link_update_same_progfunction test_link_update_invalid_optsfunction test_link_update_invalid_progfunction test_link_update_netns_gonefunction test_link_get_infofunction run_testsfunction serial_test_flow_dissector_reattach
Annotated Snippet
struct test {
const char *test_name;
void (*test_func)(int netns, int prog1, int prog2);
} tests[] = {
{ "prog attach, prog attach",
test_prog_attach_prog_attach },
{ "link create, link create",
test_link_create_link_create },
{ "prog attach, link create",
test_prog_attach_link_create },
{ "link create, prog attach",
test_link_create_prog_attach },
{ "link create, prog detach",
test_link_create_prog_detach },
{ "prog attach, detach, query",
test_prog_attach_detach_query },
{ "link create, close, query",
test_link_create_close_query },
{ "link update no old prog",
test_link_update_no_old_prog },
{ "link update with replace old prog",
test_link_update_replace_old_prog },
{ "link update with same prog",
test_link_update_same_prog },
{ "link update invalid opts",
test_link_update_invalid_opts },
{ "link update invalid prog",
test_link_update_invalid_prog },
{ "link update netns gone",
test_link_update_netns_gone },
{ "link get info",
test_link_get_info },
};
int i, progs[2] = { -1, -1 };
char test_name[80];
for (i = 0; i < ARRAY_SIZE(progs); i++) {
progs[i] = load_prog(BPF_PROG_TYPE_FLOW_DISSECTOR);
if (progs[i] < 0)
goto out_close;
}
for (i = 0; i < ARRAY_SIZE(tests); i++) {
snprintf(test_name, sizeof(test_name),
"flow dissector %s%s",
tests[i].test_name,
netns == init_net ? " (init_net)" : "");
if (test__start_subtest(test_name))
tests[i].test_func(netns, progs[0], progs[1]);
}
out_close:
for (i = 0; i < ARRAY_SIZE(progs); i++) {
if (progs[i] >= 0)
CHECK_FAIL(close(progs[i]));
}
}
void serial_test_flow_dissector_reattach(void)
{
int err, new_net, saved_net;
saved_net = open("/proc/self/ns/net", O_RDONLY);
if (CHECK_FAIL(saved_net < 0)) {
perror("open(/proc/self/ns/net");
return;
}
init_net = open("/proc/1/ns/net", O_RDONLY);
if (CHECK_FAIL(init_net < 0)) {
perror("open(/proc/1/ns/net)");
goto out_close;
}
err = setns(init_net, CLONE_NEWNET);
if (CHECK_FAIL(err)) {
perror("setns(/proc/1/ns/net)");
goto out_close;
}
if (prog_is_attached(init_net)) {
test__skip();
printf("Can't test with flow dissector attached to init_net\n");
goto out_setns;
}
/* First run tests in root network namespace */
run_tests(init_net);
/* Then repeat tests in a non-root namespace */
new_net = unshare_net(init_net);
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `sched.h`, `stdbool.h`, `sys/stat.h`, `unistd.h`, `linux/bpf.h`, `bpf/bpf.h`.
- Detected declarations: `struct test`, `function query_attached_prog_id`, `function prog_is_attached`, `function load_prog`, `function query_prog_id`, `function unshare_net`, `function test_prog_attach_prog_attach`, `function test_link_create_link_create`, `function test_prog_attach_link_create`, `function test_link_create_prog_attach`.
- 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.