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.

Dependency Surface

Detected Declarations

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

Implementation Notes