tools/testing/selftests/bpf/test_tcpnotify_user.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/test_tcpnotify_user.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/test_tcpnotify_user.c- Extension
.c- Size
- 3738 bytes
- Lines
- 169
- 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
pthread.hinttypes.hstdio.hstdlib.hunistd.hasm/types.hsys/syscall.herrno.hstring.hlinux/bpf.hsys/socket.hbpf/bpf.hbpf/libbpf.hsys/ioctl.hlinux/rtnetlink.hlinux/perf_event.hcgroup_helpers.htest_tcpnotify.htesting_helpers.h
Detected Declarations
function dummyfnfunction tcp_notifier_pollerfunction verify_resultfunction main
Annotated Snippet
if (err < 0 && err != -EINTR) {
printf("failed perf_buffer__poll: %d\n", err);
return;
}
}
}
static void *poller_thread(void *arg)
{
struct perf_buffer *pb = arg;
tcp_notifier_poller(pb);
return arg;
}
int verify_result(const struct tcpnotify_globals *result)
{
return (result->ncalls > 0 && result->ncalls == rx_callbacks ? 0 : 1);
}
int main(int argc, char **argv)
{
const char *file = "test_tcpnotify_kern.bpf.o";
struct bpf_map *perf_map, *global_map;
struct tcpnotify_globals g = {0};
struct perf_buffer *pb = NULL;
const char *cg_path = "/foo";
int prog_fd, rv, cg_fd = -1;
int error = EXIT_FAILURE;
struct bpf_object *obj;
char test_script[80];
__u32 key = 0;
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
cg_fd = cgroup_setup_and_join(cg_path);
if (cg_fd < 0)
goto err;
if (bpf_prog_test_load(file, BPF_PROG_TYPE_SOCK_OPS, &obj, &prog_fd)) {
printf("FAILED: load_bpf_file failed for: %s\n", file);
goto err;
}
rv = bpf_prog_attach(prog_fd, cg_fd, BPF_CGROUP_SOCK_OPS, 0);
if (rv) {
printf("FAILED: bpf_prog_attach: %d (%s)\n",
error, strerror(errno));
goto err;
}
perf_map = bpf_object__find_map_by_name(obj, "perf_event_map");
if (!perf_map) {
printf("FAIL:map '%s' not found\n", "perf_event_map");
goto err;
}
global_map = bpf_object__find_map_by_name(obj, "global_map");
if (!global_map) {
printf("FAIL:map '%s' not found\n", "global_map");
return -1;
}
pb = perf_buffer__new(bpf_map__fd(perf_map), 8, dummyfn, NULL, NULL, NULL);
if (!pb)
goto err;
pthread_create(&tid, NULL, poller_thread, pb);
sprintf(test_script,
"iptables -A INPUT -p tcp --dport %d -j DROP",
TESTPORT);
if (system(test_script)) {
printf("FAILED: execute command: %s, err %d\n", test_script, -errno);
goto err;
}
sprintf(test_script,
"nc 127.0.0.1 %d < /etc/passwd > /dev/null 2>&1 ",
TESTPORT);
if (system(test_script))
printf("execute command: %s, err %d\n", test_script, -errno);
sprintf(test_script,
"iptables -D INPUT -p tcp --dport %d -j DROP",
TESTPORT);
if (system(test_script)) {
printf("FAILED: execute command: %s, err %d\n", test_script, -errno);
goto err;
}
Annotation
- Immediate include surface: `pthread.h`, `inttypes.h`, `stdio.h`, `stdlib.h`, `unistd.h`, `asm/types.h`, `sys/syscall.h`, `errno.h`.
- Detected declarations: `function dummyfn`, `function tcp_notifier_poller`, `function verify_result`, `function main`.
- 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.