tools/testing/selftests/bpf/progs/test_sockmap_kern.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/test_sockmap_kern.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/test_sockmap_kern.h- Extension
.h- Size
- 7738 bytes
- Lines
- 323
- 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
stddef.hstring.hlinux/bpf.hlinux/if_ether.hlinux/if_packet.hlinux/ip.hlinux/ipv6.hlinux/in.hlinux/udp.hlinux/tcp.hlinux/pkt_cls.hsys/socket.hbpf/bpf_helpers.hbpf/bpf_endian.hbpf_misc.h
Detected Declarations
function bpf_prog1function bpf_prog2function bpf_sockmapfunction bpf_prog4function bpf_prog6function bpf_prog8function bpf_prog9function bpf_prog10
Annotated Snippet
if (lport == 10000) {
ret = 1;
#ifdef SOCKMAP
bpf_sock_map_update(skops, &sock_map, &ret,
BPF_NOEXIST);
#else
bpf_sock_hash_update(skops, &sock_map, &ret,
BPF_NOEXIST);
#endif
}
break;
case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
lport = skops->local_port;
rport = skops->remote_port;
if (bpf_ntohl(rport) == 10001) {
ret = 10;
#ifdef SOCKMAP
bpf_sock_map_update(skops, &sock_map, &ret,
BPF_NOEXIST);
#else
bpf_sock_hash_update(skops, &sock_map, &ret,
BPF_NOEXIST);
#endif
}
break;
default:
break;
}
return 0;
}
SEC("sk_msg")
int bpf_prog4(struct sk_msg_md *msg)
{
int *bytes, zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5;
int *start, *end, *start_push, *end_push, *start_pop, *pop, err = 0;
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
if (bytes)
bpf_msg_apply_bytes(msg, *bytes);
bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
if (bytes)
bpf_msg_cork_bytes(msg, *bytes);
start = bpf_map_lookup_elem(&sock_bytes, &zero);
end = bpf_map_lookup_elem(&sock_bytes, &one);
if (start && end)
bpf_msg_pull_data(msg, *start, *end, 0);
start_push = bpf_map_lookup_elem(&sock_bytes, &two);
end_push = bpf_map_lookup_elem(&sock_bytes, &three);
if (start_push && end_push) {
err = bpf_msg_push_data(msg, *start_push, *end_push, 0);
if (err)
return SK_DROP;
}
start_pop = bpf_map_lookup_elem(&sock_bytes, &four);
pop = bpf_map_lookup_elem(&sock_bytes, &five);
if (start_pop && pop)
bpf_msg_pop_data(msg, *start_pop, *pop, 0);
return SK_PASS;
}
SEC("sk_msg")
int bpf_prog6(struct sk_msg_md *msg)
{
int zero = 0, one = 1, two = 2, three = 3, four = 4, five = 5, key = 0;
int *bytes, *start, *end, *start_push, *end_push, *start_pop, *pop, *f;
int err = 0;
__u64 flags = 0;
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
if (bytes)
bpf_msg_apply_bytes(msg, *bytes);
bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
if (bytes)
bpf_msg_cork_bytes(msg, *bytes);
start = bpf_map_lookup_elem(&sock_bytes, &zero);
end = bpf_map_lookup_elem(&sock_bytes, &one);
if (start && end)
bpf_msg_pull_data(msg, *start, *end, 0);
start_push = bpf_map_lookup_elem(&sock_bytes, &two);
end_push = bpf_map_lookup_elem(&sock_bytes, &three);
if (start_push && end_push) {
err = bpf_msg_push_data(msg, *start_push, *end_push, 0);
if (err)
return SK_DROP;
}
Annotation
- Immediate include surface: `stddef.h`, `string.h`, `linux/bpf.h`, `linux/if_ether.h`, `linux/if_packet.h`, `linux/ip.h`, `linux/ipv6.h`, `linux/in.h`.
- Detected declarations: `function bpf_prog1`, `function bpf_prog2`, `function bpf_sockmap`, `function bpf_prog4`, `function bpf_prog6`, `function bpf_prog8`, `function bpf_prog9`, `function bpf_prog10`.
- 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.