tools/testing/selftests/bpf/prog_tests/select_reuseport.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/select_reuseport.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/select_reuseport.c- Extension
.c- Size
- 22695 bytes
- Lines
- 861
- 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
stdlib.hunistd.hstdbool.hstring.herrno.hassert.hfcntl.hlinux/bpf.hlinux/err.hlinux/types.hlinux/if_ether.hsys/types.hsys/epoll.hsys/socket.hnetinet/in.hbpf/bpf.hbpf/libbpf.hbpf_util.htest_progs.htest_select_reuseport_common.h
Detected Declarations
function create_mapsfunction prepare_bpf_objfunction ss_init_loopbackfunction ss_init_inanyfunction read_int_sysctlfunction write_int_sysctlfunction enable_fastopenfunction enable_syncookiefunction disable_syncookiefunction get_linumfunction check_datafunction check_resultsfunction send_datafunction do_testfunction test_err_inner_mapfunction test_err_skb_datafunction test_err_sk_select_portfunction test_passfunction test_syncookiefunction test_pass_on_errfunction test_detach_bpffunction prepare_sk_fdsfunction setup_per_testfunction cleanup_per_testfunction cleanupfunction test_configfunction test_allfunction test_map_typefunction serial_test_select_reuseport
Annotated Snippet
if (results[i] != expected_results[i]) {
broken = i;
break;
}
}
if (i == NR_RESULTS)
return;
printf("unexpected result\n");
printf(" result: [");
printf("%u", results[0]);
for (i = 1; i < NR_RESULTS; i++)
printf(", %u", results[i]);
printf("]\n");
printf("expected: [");
printf("%u", expected_results[0]);
for (i = 1; i < NR_RESULTS; i++)
printf(", %u", expected_results[i]);
printf("]\n");
printf("mismatch on %s (bpf_prog_linum:%ld)\n", result_to_str(broken),
get_linum());
CHECK_FAIL(true);
}
static int send_data(int type, sa_family_t family, void *data, size_t len,
enum result expected)
{
struct sockaddr_storage cli_sa;
int fd, err;
fd = socket(family, type, 0);
RET_ERR(fd == -1, "socket()", "fd:%d errno:%d\n", fd, errno);
ss_init_loopback(&cli_sa, family);
err = bind(fd, (struct sockaddr *)&cli_sa, sizeof(cli_sa));
RET_ERR(fd == -1, "bind(cli_sa)", "err:%d errno:%d\n", err, errno);
err = sendto(fd, data, len, MSG_FASTOPEN, (struct sockaddr *)&srv_sa,
sizeof(srv_sa));
RET_ERR(err != len && expected >= PASS,
"sendto()", "family:%u err:%d errno:%d expected:%d\n",
family, err, errno, expected);
return fd;
}
static void do_test(int type, sa_family_t family, struct cmd *cmd,
enum result expected)
{
int nev, srv_fd, cli_fd;
struct epoll_event ev;
struct cmd rcv_cmd;
ssize_t nread;
cli_fd = send_data(type, family, cmd, cmd ? sizeof(*cmd) : 0,
expected);
if (cli_fd < 0)
return;
nev = epoll_wait(epfd, &ev, 1, expected >= PASS ? 5 : 0);
RET_IF((nev <= 0 && expected >= PASS) ||
(nev > 0 && expected < PASS),
"nev <> expected",
"nev:%d expected:%d type:%d family:%d data:(%d, %d)\n",
nev, expected, type, family,
cmd ? cmd->reuseport_index : -1,
cmd ? cmd->pass_on_failure : -1);
check_results();
check_data(type, family, cmd, cli_fd);
if (expected < PASS)
return;
RET_IF(expected != PASS_ERR_SK_SELECT_REUSEPORT &&
cmd->reuseport_index != ev.data.u32,
"check cmd->reuseport_index",
"cmd:(%u, %u) ev.data.u32:%u\n",
cmd->pass_on_failure, cmd->reuseport_index, ev.data.u32);
srv_fd = sk_fds[ev.data.u32];
if (type == SOCK_STREAM) {
int new_fd = accept(srv_fd, NULL, 0);
RET_IF(new_fd == -1, "accept(srv_fd)",
"ev.data.u32:%u new_fd:%d errno:%d\n",
ev.data.u32, new_fd, errno);
nread = recv(new_fd, &rcv_cmd, sizeof(rcv_cmd), MSG_DONTWAIT);
Annotation
- Immediate include surface: `stdlib.h`, `unistd.h`, `stdbool.h`, `string.h`, `errno.h`, `assert.h`, `fcntl.h`, `linux/bpf.h`.
- Detected declarations: `function create_maps`, `function prepare_bpf_obj`, `function ss_init_loopback`, `function ss_init_inany`, `function read_int_sysctl`, `function write_int_sysctl`, `function enable_fastopen`, `function enable_syncookie`, `function disable_syncookie`, `function get_linum`.
- 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.