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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
fcntl.hpthread.hsched.hsignal.haolib.hkselftest.h
Detected Declarations
struct dlist_tstruct new_pthread_argfunction __test_msgfunction __test_okfunction __test_failfunction __test_xfailfunction __test_errorfunction __test_skipfunction test_failedfunction test_exitfunction test_add_destructorfunction test_destructorfunction sig_intfunction open_netnsfunction unshare_open_netnsfunction switch_nsfunction switch_save_nsfunction switch_close_nsfunction init_namespacesfunction link_initfunction synchronize_threadsfunction __test_skip_allfunction __test_initfunction is_optmem_namespacedfunction test_get_optmemfunction __test_set_optmemfunction test_revert_optmemfunction test_set_optmem
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
- Immediate include surface: `fcntl.h`, `pthread.h`, `sched.h`, `signal.h`, `aolib.h`, `kselftest.h`.
- Detected declarations: `struct dlist_t`, `struct new_pthread_arg`, `function __test_msg`, `function __test_ok`, `function __test_fail`, `function __test_xfail`, `function __test_error`, `function __test_skip`, `function test_failed`, `function test_exit`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.