tools/testing/selftests/net/tcp_fastopen_backup_key.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/tcp_fastopen_backup_key.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/tcp_fastopen_backup_key.c- Extension
.c- Size
- 8520 bytes
- Lines
- 334
- 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
arpa/inet.herrno.herror.hstdbool.hstdio.hstdlib.hstring.hsys/epoll.hunistd.hnetinet/tcp.hfcntl.htime.hkselftest.h
Detected Declarations
function get_keysfunction set_keysfunction build_rcv_fdfunction connect_and_sendfunction is_listen_fdfunction rotate_keyfunction run_one_testfunction parse_optsfunction main
Annotated Snippet
if (iter == 0) {
for (i = 0; i < ARRAY_SIZE(new_key); i++)
new_key[i] = rand();
}
get_keys(fd, keys);
memcpy(keys + 4, new_key, KEY_LENGTH);
set_keys(fd, keys);
} else {
/* swap the keys */
get_keys(fd, keys);
memcpy(tmp_key, keys + 4, KEY_LENGTH);
memcpy(keys + 4, keys, KEY_LENGTH);
memcpy(keys, tmp_key, KEY_LENGTH);
set_keys(fd, keys);
}
if (++iter >= (N_LISTEN * 2))
iter = 0;
}
static void run_one_test(int family)
{
struct epoll_event ev;
int i, send_fd;
int n_loops = 10000;
int rotate_key_fd = 0;
int key_rotate_interval = 50;
int fd, epfd;
char buf[1];
build_rcv_fd(family, SOCK_STREAM, rcv_fds);
epfd = epoll_create(1);
if (epfd < 0)
error(1, errno, "failed to create epoll");
ev.events = EPOLLIN;
for (i = 0; i < N_LISTEN; i++) {
ev.data.fd = rcv_fds[i];
if (epoll_ctl(epfd, EPOLL_CTL_ADD, rcv_fds[i], &ev))
error(1, errno, "failed to register sock epoll");
}
while (n_loops--) {
send_fd = connect_and_send(family, SOCK_STREAM);
if (do_rotate && ((n_loops % key_rotate_interval) == 0)) {
rotate_key(rcv_fds[rotate_key_fd]);
if (++rotate_key_fd >= N_LISTEN)
rotate_key_fd = 0;
}
while (1) {
i = epoll_wait(epfd, &ev, 1, -1);
if (i < 0)
error(1, errno, "epoll_wait failed");
if (is_listen_fd(ev.data.fd)) {
fd = accept(ev.data.fd, NULL, NULL);
if (fd < 0)
error(1, errno, "failed to accept");
ev.data.fd = fd;
if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev))
error(1, errno, "failed epoll add");
continue;
}
i = recv(ev.data.fd, buf, sizeof(buf), 0);
if (i != 1)
error(1, errno, "failed recv data");
if (epoll_ctl(epfd, EPOLL_CTL_DEL, ev.data.fd, NULL))
error(1, errno, "failed epoll del");
close(ev.data.fd);
break;
}
close(send_fd);
}
for (i = 0; i < N_LISTEN; i++)
close(rcv_fds[i]);
}
static void parse_opts(int argc, char **argv)
{
int c;
while ((c = getopt(argc, argv, "46sr")) != -1) {
switch (c) {
case '4':
do_ipv6 = false;
break;
case '6':
do_ipv6 = true;
break;
case 's':
do_sockopt = true;
break;
case 'r':
do_rotate = true;
Annotation
- Immediate include surface: `arpa/inet.h`, `errno.h`, `error.h`, `stdbool.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/epoll.h`.
- Detected declarations: `function get_keys`, `function set_keys`, `function build_rcv_fd`, `function connect_and_send`, `function is_listen_fd`, `function rotate_key`, `function run_one_test`, `function parse_opts`, `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.