samples/bpf/test_map_in_map_user.c
Source file repositories/reference/linux-study-clean/samples/bpf/test_map_in_map_user.c
File Facts
- System
- Linux kernel
- Corpus path
samples/bpf/test_map_in_map_user.c- Extension
.c- Size
- 4357 bytes
- Lines
- 169
- 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
sys/socket.harpa/inet.hstdint.hassert.herrno.hstdlib.hstdio.hbpf/bpf.hbpf/libbpf.hbpf_util.h
Detected Declarations
function check_map_idfunction populate_mapfunction test_map_in_mapfunction main
Annotated Snippet
if (result != magic_result || inline_result != magic_result) {
printf("Error. result:%d inline_result:%d\n",
result, inline_result);
exit(1);
}
bpf_map_delete_elem(REG_RESULT_H, &result_key);
bpf_map_delete_elem(INLINE_RESULT_H, &result_key);
printf("Pass\n");
}
}
int main(int argc, char **argv)
{
struct bpf_link *link = NULL;
struct bpf_program *prog;
struct bpf_object *obj;
char filename[256];
snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]);
obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj)) {
fprintf(stderr, "ERROR: opening BPF object file failed\n");
return 0;
}
prog = bpf_object__find_program_by_name(obj, "trace_sys_connect");
if (!prog) {
printf("finding a prog in obj file failed\n");
goto cleanup;
}
/* load BPF program */
if (bpf_object__load(obj)) {
fprintf(stderr, "ERROR: loading BPF object file failed\n");
goto cleanup;
}
map_fd[0] = bpf_object__find_map_fd_by_name(obj, "port_a");
map_fd[1] = bpf_object__find_map_fd_by_name(obj, "port_h");
map_fd[2] = bpf_object__find_map_fd_by_name(obj, "reg_result_h");
map_fd[3] = bpf_object__find_map_fd_by_name(obj, "inline_result_h");
map_fd[4] = bpf_object__find_map_fd_by_name(obj, "a_of_port_a");
map_fd[5] = bpf_object__find_map_fd_by_name(obj, "h_of_port_a");
map_fd[6] = bpf_object__find_map_fd_by_name(obj, "h_of_port_h");
if (map_fd[0] < 0 || map_fd[1] < 0 || map_fd[2] < 0 ||
map_fd[3] < 0 || map_fd[4] < 0 || map_fd[5] < 0 || map_fd[6] < 0) {
fprintf(stderr, "ERROR: finding a map in obj file failed\n");
goto cleanup;
}
link = bpf_program__attach(prog);
if (libbpf_get_error(link)) {
fprintf(stderr, "ERROR: bpf_program__attach failed\n");
link = NULL;
goto cleanup;
}
test_map_in_map();
cleanup:
bpf_link__destroy(link);
bpf_object__close(obj);
return 0;
}
Annotation
- Immediate include surface: `sys/socket.h`, `arpa/inet.h`, `stdint.h`, `assert.h`, `errno.h`, `stdlib.h`, `stdio.h`, `bpf/bpf.h`.
- Detected declarations: `function check_map_id`, `function populate_map`, `function test_map_in_map`, `function main`.
- 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.