samples/bpf/test_map_in_map.bpf.c
Source file repositories/reference/linux-study-clean/samples/bpf/test_map_in_map.bpf.c
File Facts
- System
- Linux kernel
- Corpus path
samples/bpf/test_map_in_map.bpf.c- Extension
.c- Size
- 3884 bytes
- Lines
- 173
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- 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
vmlinux.hlinux/version.hbpf/bpf_helpers.hbpf/bpf_tracing.hbpf/bpf_core_read.h
Detected Declarations
struct inner_astruct inner_hfunction do_reg_lookupfunction do_inline_array_lookupfunction do_inline_hash_lookupfunction BPF_KSYSCALL
Annotated Snippet
struct inner_a {
__uint(type, BPF_MAP_TYPE_ARRAY);
__type(key, u32);
__type(value, int);
__uint(max_entries, MAX_NR_PORTS);
} port_a SEC(".maps");
/* map #1 */
struct inner_h {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, u32);
__type(value, int);
__uint(max_entries, 1);
} port_h SEC(".maps");
/* map #2 */
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, u32);
__type(value, int);
__uint(max_entries, 1);
} reg_result_h SEC(".maps");
/* map #3 */
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, u32);
__type(value, int);
__uint(max_entries, 1);
} inline_result_h SEC(".maps");
/* map #4 */ /* Test case #0 */
struct {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(max_entries, MAX_NR_PORTS);
__uint(key_size, sizeof(u32));
__array(values, struct inner_a); /* use inner_a as inner map */
} a_of_port_a SEC(".maps");
/* map #5 */ /* Test case #1 */
struct {
__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
__uint(max_entries, 1);
__uint(key_size, sizeof(u32));
__array(values, struct inner_a); /* use inner_a as inner map */
} h_of_port_a SEC(".maps");
/* map #6 */ /* Test case #2 */
struct {
__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
__uint(max_entries, 1);
__uint(key_size, sizeof(u32));
__array(values, struct inner_h); /* use inner_h as inner map */
} h_of_port_h SEC(".maps");
static __always_inline int do_reg_lookup(void *inner_map, u32 port)
{
int *result;
result = bpf_map_lookup_elem(inner_map, &port);
return result ? *result : -ENOENT;
}
static __always_inline int do_inline_array_lookup(void *inner_map, u32 port)
{
int *result;
if (inner_map != &port_a)
return -EINVAL;
result = bpf_map_lookup_elem(&port_a, &port);
return result ? *result : -ENOENT;
}
static __always_inline int do_inline_hash_lookup(void *inner_map, u32 port)
{
int *result;
if (inner_map != &port_h)
return -EINVAL;
result = bpf_map_lookup_elem(&port_h, &port);
return result ? *result : -ENOENT;
}
SEC("ksyscall/connect")
int BPF_KSYSCALL(trace_sys_connect, unsigned int fd, struct sockaddr_in6 *in6, int addrlen)
{
u16 test_case, port, dst6[8];
int ret, inline_ret, ret_key = 0;
Annotation
- Immediate include surface: `vmlinux.h`, `linux/version.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf/bpf_core_read.h`.
- Detected declarations: `struct inner_a`, `struct inner_h`, `function do_reg_lookup`, `function do_inline_array_lookup`, `function do_inline_hash_lookup`, `function BPF_KSYSCALL`.
- Atlas domain: Support Tooling And Documentation / samples.
- 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.