tools/testing/selftests/net/ipsec.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/ipsec.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/ipsec.c- Extension
.c- Size
- 56326 bytes
- Lines
- 2346
- 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.hasm/types.herrno.hfcntl.hlimits.hlinux/limits.hlinux/netlink.hlinux/random.hlinux/rtnetlink.hlinux/veth.hlinux/xfrm.hnetinet/in.hnet/if.hsched.hstdbool.hstdint.hstdio.hstdlib.hstring.hsys/mman.hsys/socket.hsys/stat.hsys/syscall.hsys/types.hsys/wait.htime.hunistd.hkselftest.h
Detected Declarations
struct xfrm_key_entrystruct nlmsgerrorstruct xfrm_descstruct test_descstruct test_resultenum desc_typeenum msg_typefunction randomize_bufferfunction unshare_openfunction switch_nsfunction init_namespacesfunction netlink_sockfunction rtattr_packfunction rtattr_endfunction veth_pack_peerbfunction netlink_check_answerfunction veth_addfunction ip4_addr_setfunction link_set_upfunction ip4_route_setfunction tunnel_set_routefunction init_childfunction write_test_resultfunction write_msgfunction read_msgfunction udp_ping_initfunction udp_ping_sendfunction udp_ping_replyfunction do_pingfunction xfrm_fill_keyfunction xfrm_state_pack_algofunction gen_spifunction xfrm_state_addfunction xfrm_usersa_foundfunction xfrm_state_checkfunction xfrm_setfunction xfrm_policy_addfunction xfrm_preparefunction xfrm_policy_delfunction xfrm_cleanupfunction xfrm_state_delfunction xfrm_deletefunction xfrm_state_allocspifunction netlink_sock_bindfunction xfrm_monitor_acquirefunction xfrm_expire_statefunction xfrm_expire_policyfunction xfrm_spdinfo_set_thresh
Annotated Snippet
struct xfrm_key_entry {
char algo_name[35];
int key_len;
};
struct xfrm_key_entry xfrm_key_entries[] = {
{"digest_null", 0},
{"ecb(cipher_null)", 0},
{"cbc(des)", 64},
{"hmac(md5)", 128},
{"cmac(aes)", 128},
{"xcbc(aes)", 128},
{"cbc(cast5)", 128},
{"cbc(serpent)", 128},
{"hmac(sha1)", 160},
{"cbc(des3_ede)", 192},
{"hmac(sha256)", 256},
{"cbc(aes)", 256},
{"cbc(camellia)", 256},
{"cbc(twofish)", 256},
{"rfc3686(ctr(aes))", 288},
{"hmac(sha384)", 384},
{"cbc(blowfish)", 448},
{"hmac(sha512)", 512},
{"rfc4106(gcm(aes))-128", 160},
{"rfc4543(gcm(aes))-128", 160},
{"rfc4309(ccm(aes))-128", 152},
{"rfc4106(gcm(aes))-192", 224},
{"rfc4543(gcm(aes))-192", 224},
{"rfc4309(ccm(aes))-192", 216},
{"rfc4106(gcm(aes))-256", 288},
{"rfc4543(gcm(aes))-256", 288},
{"rfc4309(ccm(aes))-256", 280},
{"rfc7539(chacha20,poly1305)-128", 0}
};
static void randomize_buffer(void *buf, size_t buflen)
{
int *p = (int *)buf;
size_t words = buflen / sizeof(int);
size_t leftover = buflen % sizeof(int);
if (!buflen)
return;
while (words--)
*p++ = rand();
if (leftover) {
int tmp = rand();
memcpy(buf + buflen - leftover, &tmp, leftover);
}
return;
}
static int unshare_open(void)
{
const char *netns_path = "/proc/self/ns/net";
int fd;
if (unshare(CLONE_NEWNET) != 0) {
pr_err("unshare()");
return -1;
}
fd = open(netns_path, O_RDONLY);
if (fd <= 0) {
pr_err("open(%s)", netns_path);
return -1;
}
return fd;
}
static int switch_ns(int fd)
{
if (setns(fd, CLONE_NEWNET)) {
pr_err("setns()");
return -1;
}
return 0;
}
/*
* Running the test inside a new parent net namespace to bother less
* about cleanup on error-path.
*/
static int init_namespaces(void)
Annotation
- Immediate include surface: `arpa/inet.h`, `asm/types.h`, `errno.h`, `fcntl.h`, `limits.h`, `linux/limits.h`, `linux/netlink.h`, `linux/random.h`.
- Detected declarations: `struct xfrm_key_entry`, `struct nlmsgerror`, `struct xfrm_desc`, `struct test_desc`, `struct test_result`, `enum desc_type`, `enum msg_type`, `function randomize_buffer`, `function unshare_open`, `function switch_ns`.
- 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.