tools/testing/selftests/net/tcp_ao/lib/setup.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/tcp_ao/lib/setup.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/tcp_ao/lib/setup.c
Extension
.c
Size
8389 bytes
Lines
369
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

struct dlist_t {
	void (*destruct)(void);
	struct dlist_t *next;
};
static struct dlist_t *destructors_list;

void test_add_destructor(void (*d)(void))
{
	struct dlist_t *p;

	p = malloc(sizeof(struct dlist_t));
	if (p == NULL)
		test_error("malloc() failed");

	p->next = destructors_list;
	p->destruct = d;
	destructors_list = p;
}

static void test_destructor(void) __attribute__((destructor));
static void test_destructor(void)
{
	while (destructors_list) {
		struct dlist_t *p = destructors_list->next;

		destructors_list->destruct();
		free(destructors_list);
		destructors_list = p;
	}
	test_exit();
}

static void sig_int(int signo)
{
	test_error("Caught SIGINT - exiting");
}

int open_netns(void)
{
	const char *netns_path = "/proc/thread-self/ns/net";
	int fd;

	fd = open(netns_path, O_RDONLY);
	if (fd < 0)
		test_error("open(%s)", netns_path);
	return fd;
}

int unshare_open_netns(void)
{
	if (unshare(CLONE_NEWNET) != 0)
		test_error("unshare()");

	return open_netns();
}

void switch_ns(int fd)
{
	if (setns(fd, CLONE_NEWNET))
		test_error("setns()");
}

int switch_save_ns(int new_ns)
{
	int ret = open_netns();

	switch_ns(new_ns);
	return ret;
}

void switch_close_ns(int fd)
{
	if (setns(fd, CLONE_NEWNET))
		test_error("setns()");
	close(fd);
}

static int nsfd_outside	= -1;
static int nsfd_parent	= -1;
static int nsfd_child	= -1;
const char veth_name[]	= "ktst-veth";

static void init_namespaces(void)
{
	nsfd_outside = open_netns();
	nsfd_parent = unshare_open_netns();
	nsfd_child = unshare_open_netns();
}

static void link_init(const char *veth, int family, uint8_t prefix,

Annotation

Implementation Notes