samples/bpf/ibumad_user.c
Source file repositories/reference/linux-study-clean/samples/bpf/ibumad_user.c
File Facts
- System
- Linux kernel
- Corpus path
samples/bpf/ibumad_user.c- Extension
.c- Size
- 3439 bytes
- Lines
- 159
- 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
linux/bpf.hsignal.hstdio.hstdlib.hstring.hunistd.hsys/types.hlimits.hgetopt.hnet/if.hbpf/bpf.hbpf_util.hbpf/libbpf.h
Detected Declarations
function dump_countsfunction dump_all_countsfunction dump_exitfunction usagefunction mainfunction bpf_object__for_each_program
Annotated Snippet
if (bpf_map_lookup_elem(fd, &key, &value)) {
printf("failed to read key %u\n", key);
continue;
}
if (value)
printf("0x%02x : %llu\n", key, value);
}
}
static void dump_all_counts(void)
{
printf("Read 'Class : count'\n");
dump_counts(map_fd[0]);
printf("Write 'Class : count'\n");
dump_counts(map_fd[1]);
}
static void dump_exit(int sig)
{
dump_all_counts();
/* Detach tracepoints */
while (tp_cnt)
bpf_link__destroy(tp_links[--tp_cnt]);
bpf_object__close(obj);
exit(0);
}
static const struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"delay", required_argument, NULL, 'd'},
};
static void usage(char *cmd)
{
printf("eBPF test program to count packets from various IP addresses\n"
"Usage: %s <options>\n"
" --help, -h this menu\n"
" --delay, -d <delay> wait <delay> sec between prints [1 - 1000000]\n"
, cmd
);
}
int main(int argc, char **argv)
{
struct bpf_program *prog;
unsigned long delay = 5;
char filename[256];
int longindex = 0;
int opt, err = -1;
while ((opt = getopt_long(argc, argv, "hd:rSw",
long_options, &longindex)) != -1) {
switch (opt) {
case 'd':
delay = strtoul(optarg, NULL, 0);
if (delay == ULONG_MAX || delay < 0 ||
delay > 1000000) {
fprintf(stderr, "ERROR: invalid delay : %s\n",
optarg);
usage(argv[0]);
return 1;
}
break;
default:
case 'h':
usage(argv[0]);
return 1;
}
}
/* Do one final dump when exiting */
signal(SIGINT, dump_exit);
signal(SIGTERM, dump_exit);
snprintf(filename, sizeof(filename), "%s_kern.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 err;
}
/* 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, "read_count");
map_fd[1] = bpf_object__find_map_fd_by_name(obj, "write_count");
Annotation
- Immediate include surface: `linux/bpf.h`, `signal.h`, `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `sys/types.h`, `limits.h`.
- Detected declarations: `function dump_counts`, `function dump_all_counts`, `function dump_exit`, `function usage`, `function main`, `function bpf_object__for_each_program`.
- 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.