tools/bpf/bpftool/prog.c
Source file repositories/reference/linux-study-clean/tools/bpf/bpftool/prog.c
File Facts
- System
- Linux kernel
- Corpus path
tools/bpf/bpftool/prog.c- Extension
.c- Size
- 61383 bytes
- Lines
- 2619
- 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
errno.hfcntl.hsignal.hstdarg.hstdio.hstdlib.hstring.htime.hunistd.hnet/if.hsys/ioctl.hsys/types.hsys/stat.hsys/syscall.hdirent.hlinux/err.hlinux/perf_event.hlinux/sizes.hlinux/keyctl.hbpf/bpf.hbpf/btf.hbpf/hashmap.hbpf/libbpf.hbpf/libbpf_internal.hbpf/skel_internal.hcfg.hmain.hxlated_dumper.hprofiler.skel.h
Detected Declarations
struct map_replacestruct profile_metricenum dump_modeenum prog_tracelog_modefunction parse_attach_typefunction prep_prog_infofunction print_boot_timefunction show_prog_mapsfunction has_metadata_prefixfunction show_prog_metadatafunction print_prog_header_jsonfunction print_prog_jsonfunction print_prog_header_plainfunction print_prog_plainfunction show_progfunction do_show_subsetfunction do_showfunction prog_dumpfunction do_dumpfunction do_pinfunction map_replace_comparfunction parse_attach_detach_argsfunction do_attachfunction do_detachfunction prog_tracelog_streamfunction do_tracelog_anyfunction check_single_stdinfunction get_run_datafunction hex_printfunction print_run_outputfunction alloc_run_datafunction do_runfunction get_prog_type_by_namefunction auto_attach_programfunction auto_attach_programsfunction bpf_object__for_each_programfunction load_with_optionsfunction bpf_object__for_each_programfunction bpf_object__for_each_mapfunction count_open_fdsfunction try_loaderfunction do_loaderfunction do_loadfunction do_loadallfunction do_profilefunction profile_parse_metricsfunction profile_read_valuesfunction profile_print_readings_json
Annotated Snippet
struct map_replace {
int idx;
int fd;
char *name;
};
static int map_replace_compar(const void *p1, const void *p2)
{
const struct map_replace *a = p1, *b = p2;
return a->idx - b->idx;
}
static int parse_attach_detach_args(int argc, char **argv, int *progfd,
enum bpf_attach_type *attach_type,
int *mapfd)
{
if (!REQ_ARGS(3))
return -EINVAL;
*progfd = prog_parse_fd(&argc, &argv);
if (*progfd < 0)
return *progfd;
*attach_type = parse_attach_type(*argv);
if (*attach_type == __MAX_BPF_ATTACH_TYPE) {
p_err("invalid attach/detach type");
return -EINVAL;
}
if (*attach_type == BPF_FLOW_DISSECTOR) {
*mapfd = 0;
return 0;
}
NEXT_ARG();
if (!REQ_ARGS(2))
return -EINVAL;
*mapfd = map_parse_fd(&argc, &argv, 0);
if (*mapfd < 0)
return *mapfd;
return 0;
}
static int do_attach(int argc, char **argv)
{
enum bpf_attach_type attach_type;
int err, progfd;
int mapfd;
err = parse_attach_detach_args(argc, argv,
&progfd, &attach_type, &mapfd);
if (err)
return err;
err = bpf_prog_attach(progfd, mapfd, attach_type, 0);
if (err) {
p_err("failed prog attach to map");
return -EINVAL;
}
if (json_output)
jsonw_null(json_wtr);
return 0;
}
static int do_detach(int argc, char **argv)
{
enum bpf_attach_type attach_type;
int err, progfd;
int mapfd;
err = parse_attach_detach_args(argc, argv,
&progfd, &attach_type, &mapfd);
if (err)
return err;
err = bpf_prog_detach2(progfd, mapfd, attach_type);
if (err) {
p_err("failed prog detach from map");
return -EINVAL;
}
if (json_output)
jsonw_null(json_wtr);
return 0;
}
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `signal.h`, `stdarg.h`, `stdio.h`, `stdlib.h`, `string.h`, `time.h`.
- Detected declarations: `struct map_replace`, `struct profile_metric`, `enum dump_mode`, `enum prog_tracelog_mode`, `function parse_attach_type`, `function prep_prog_info`, `function print_boot_time`, `function show_prog_maps`, `function has_metadata_prefix`, `function show_prog_metadata`.
- 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.