tools/testing/selftests/bpf/prog_tests/socket_helpers.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/socket_helpers.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/socket_helpers.h- Extension
.h- Size
- 12766 bytes
- Lines
- 474
- 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
sys/un.hlinux/vm_sockets.h
Detected Declarations
function close_fdfunction init_addr_loopback4function init_addr_loopback6function init_addr_loopback_unixfunction init_addr_loopback_vsockfunction init_addr_loopbackfunction enable_reuseportfunction socket_loopback_reuseportfunction socket_loopbackfunction poll_connectfunction poll_readfunction accept_timeoutfunction recv_timeoutfunction create_pairfunction create_socket_pairs
Annotated Snippet
if (errno != EINPROGRESS) {
FAIL_ERRNO("connect");
return err;
}
err = poll_connect(c, IO_TIMEOUT_SEC);
if (err) {
FAIL_ERRNO("poll_connect");
return err;
}
}
switch (sotype & SOCK_TYPE_MASK) {
case SOCK_DGRAM:
err = xgetsockname(c, sockaddr(&addr), &len);
if (err)
return err;
err = xconnect(s, sockaddr(&addr), len);
if (err)
return err;
*p0 = take_fd(s);
break;
case SOCK_STREAM:
case SOCK_SEQPACKET:
p = xaccept_nonblock(s, NULL, NULL);
if (p < 0)
return p;
*p0 = take_fd(p);
break;
default:
FAIL("Unsupported socket type %#x", sotype);
return -EOPNOTSUPP;
}
*p1 = take_fd(c);
return 0;
}
static inline int create_socket_pairs(int family, int sotype, int *c0, int *c1,
int *p0, int *p1)
{
int err;
err = create_pair(family, sotype, c0, p0);
if (err)
return err;
err = create_pair(family, sotype, c1, p1);
if (err) {
close(*c0);
close(*p0);
}
return err;
}
static inline const char *socket_kind_to_str(int sock_fd)
{
socklen_t opt_len;
int domain, type;
opt_len = sizeof(domain);
if (getsockopt(sock_fd, SOL_SOCKET, SO_DOMAIN, &domain, &opt_len))
FAIL_ERRNO("getsockopt(SO_DOMAIN)");
opt_len = sizeof(type);
if (getsockopt(sock_fd, SOL_SOCKET, SO_TYPE, &type, &opt_len))
FAIL_ERRNO("getsockopt(SO_TYPE)");
switch (domain) {
case AF_INET:
switch (type) {
case SOCK_STREAM:
return "tcp4";
case SOCK_DGRAM:
return "udp4";
}
break;
case AF_INET6:
switch (type) {
case SOCK_STREAM:
return "tcp6";
case SOCK_DGRAM:
return "udp6";
}
break;
case AF_UNIX:
Annotation
- Immediate include surface: `sys/un.h`, `linux/vm_sockets.h`.
- Detected declarations: `function close_fd`, `function init_addr_loopback4`, `function init_addr_loopback6`, `function init_addr_loopback_unix`, `function init_addr_loopback_vsock`, `function init_addr_loopback`, `function enable_reuseport`, `function socket_loopback_reuseport`, `function socket_loopback`, `function poll_connect`.
- 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.