tools/testing/selftests/bpf/prog_tests/sk_lookup.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/sk_lookup.c- Extension
.c- Size
- 35367 bytes
- Lines
- 1361
- 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.hassert.herrno.hfcntl.hsched.hstdio.hsys/types.hsys/stat.hunistd.hbpf/libbpf.hbpf/bpf.htest_progs.hbpf_util.hcgroup_helpers.hnetwork_helpers.htesting_helpers.htest_sk_lookup.skel.h
Detected Declarations
struct inet_addrstruct teststruct cb_optsstruct test_multi_progenum serverfunction is_ipv6function attach_reuseportfunction setsockoptsfunction make_serverfunction socket_cookiefunction fill_sk_lookup_ctxfunction send_bytefunction recv_bytefunction tcp_recv_sendfunction v4_to_v6function udp_recv_sendfunction tcp_echo_testfunction udp_echo_testfunction update_lookup_mapfunction query_lookup_progfunction run_lookup_progfunction test_redirect_lookupfunction drop_on_lookupfunction test_drop_on_lookupfunction drop_on_reuseportfunction test_drop_on_reuseportfunction run_sk_assignfunction run_sk_assign_v4function run_sk_assign_v6function run_sk_assign_connectedfunction test_sk_assign_helperfunction run_multi_prog_lookupfunction test_multi_prog_lookupfunction run_testsfunction switch_netnsfunction test_sk_lookup
Annotated Snippet
struct inet_addr {
const char *ip;
unsigned short port;
};
struct test {
const char *desc;
struct bpf_program *lookup_prog;
struct bpf_program *reuseport_prog;
struct bpf_map *sock_map;
int sotype;
struct inet_addr connect_to;
struct inet_addr listen_at;
enum server accept_on;
bool reuseport_has_conns; /* Add a connected socket to reuseport group */
};
struct cb_opts {
int family;
int sotype;
bool reuseport;
};
static __u32 duration; /* for CHECK macro */
static bool is_ipv6(const char *ip)
{
return !!strchr(ip, ':');
}
static int attach_reuseport(int sock_fd, struct bpf_program *reuseport_prog)
{
int err, prog_fd;
prog_fd = bpf_program__fd(reuseport_prog);
if (prog_fd < 0) {
errno = -prog_fd;
return -1;
}
err = setsockopt(sock_fd, SOL_SOCKET, SO_ATTACH_REUSEPORT_EBPF,
&prog_fd, sizeof(prog_fd));
if (err)
return -1;
return 0;
}
static int setsockopts(int fd, void *opts)
{
struct cb_opts *co = (struct cb_opts *)opts;
const int one = 1;
int err = 0;
/* Enabled for UDPv6 sockets for IPv4-mapped IPv6 to work. */
if (co->sotype == SOCK_DGRAM) {
err = setsockopt(fd, SOL_IP, IP_RECVORIGDSTADDR, &one,
sizeof(one));
if (CHECK(err, "setsockopt(IP_RECVORIGDSTADDR)", "failed\n")) {
log_err("failed to enable IP_RECVORIGDSTADDR");
goto fail;
}
}
if (co->sotype == SOCK_DGRAM && co->family == AF_INET6) {
err = setsockopt(fd, SOL_IPV6, IPV6_RECVORIGDSTADDR, &one,
sizeof(one));
if (CHECK(err, "setsockopt(IPV6_RECVORIGDSTADDR)", "failed\n")) {
log_err("failed to enable IPV6_RECVORIGDSTADDR");
goto fail;
}
}
if (co->sotype == SOCK_STREAM) {
err = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one,
sizeof(one));
if (CHECK(err, "setsockopt(SO_REUSEADDR)", "failed\n")) {
log_err("failed to enable SO_REUSEADDR");
goto fail;
}
}
if (co->reuseport) {
err = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one,
sizeof(one));
if (CHECK(err, "setsockopt(SO_REUSEPORT)", "failed\n")) {
log_err("failed to enable SO_REUSEPORT");
goto fail;
}
}
Annotation
- Immediate include surface: `arpa/inet.h`, `assert.h`, `errno.h`, `fcntl.h`, `sched.h`, `stdio.h`, `sys/types.h`, `sys/stat.h`.
- Detected declarations: `struct inet_addr`, `struct test`, `struct cb_opts`, `struct test_multi_prog`, `enum server`, `function is_ipv6`, `function attach_reuseport`, `function setsockopts`, `function make_server`, `function socket_cookie`.
- 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.