tools/lib/bpf/libbpf.h
Source file repositories/reference/linux-study-clean/tools/lib/bpf/libbpf.h
File Facts
- System
- Linux kernel
- Corpus path
tools/lib/bpf/libbpf.h- Extension
.h- Size
- 81460 bytes
- Lines
- 2086
- 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
stdarg.hstdio.hstdint.hstdbool.hsys/types.hlinux/bpf.hlibbpf_common.hlibbpf_legacy.h
Detected Declarations
struct bpf_objectstruct bpf_object_open_optsstruct btfstruct bpf_programstruct bpf_insnstruct bpf_linkstruct bpf_perf_event_optsstruct bpf_kprobe_optsstruct bpf_kprobe_multi_optsstruct bpf_uprobe_multi_optsstruct bpf_ksyscall_optsstruct bpf_tracing_multi_optsstruct bpf_uprobe_optsstruct bpf_usdt_optsstruct bpf_tracepoint_optsstruct bpf_raw_tracepoint_optsstruct bpf_trace_optsstruct bpf_netfilter_optsstruct bpf_tcx_optsstruct bpf_netkit_optsstruct bpf_cgroup_optsstruct bpf_mapstruct bpf_iter_attach_optsstruct bpf_prog_assoc_struct_ops_optsstruct bpf_xdp_set_link_optsstruct bpf_xdp_attach_optsstruct bpf_xdp_query_optsstruct bpf_tc_hookstruct bpf_tc_optsstruct ring_bufferstruct ringstruct user_ring_bufferstruct ring_buffer_optsstruct user_ring_buffer_optsstruct perf_bufferstruct perf_buffer_optsstruct perf_event_headerstruct perf_buffer_raw_optsstruct perf_event_attrstruct bpf_prog_linfostruct bpf_prog_infostruct bpf_map_skeletonstruct bpf_prog_skeletonstruct bpf_object_skeletonstruct bpf_var_skeletonstruct bpf_object_subskeletonstruct gen_loader_optsstruct bpf_linker_opts
Annotated Snippet
struct bpf_object_open_opts {
/* size of this struct, for forward/backward compatibility */
size_t sz;
/* object name override, if provided:
* - for object open from file, this will override setting object
* name from file path's base name;
* - for object open from memory buffer, this will specify an object
* name and will override default "<addr>-<buf-size>" name;
*/
const char *object_name;
/* parse map definitions non-strictly, allowing extra attributes/data */
bool relaxed_maps;
/* maps that set the 'pinning' attribute in their definition will have
* their pin_path attribute set to a file in this directory, and be
* auto-pinned to that path on load; defaults to "/sys/fs/bpf".
*/
const char *pin_root_path;
__u32 :32; /* stub out now removed attach_prog_fd */
/* Additional kernel config content that augments and overrides
* system Kconfig for CONFIG_xxx externs.
*/
const char *kconfig;
/* Path to the custom BTF to be used for BPF CO-RE relocations.
* This custom BTF completely replaces the use of vmlinux BTF
* for the purpose of CO-RE relocations.
* NOTE: any other BPF feature (e.g., fentry/fexit programs,
* struct_ops, etc) will need actual kernel BTF at /sys/kernel/btf/vmlinux.
*/
const char *btf_custom_path;
/* Pointer to a buffer for storing kernel logs for applicable BPF
* commands. Valid kernel_log_size has to be specified as well and are
* passed-through to bpf() syscall. Keep in mind that kernel might
* fail operation with -ENOSPC error if provided buffer is too small
* to contain entire log output.
* See the comment below for kernel_log_level for interaction between
* log_buf and log_level settings.
*
* If specified, this log buffer will be passed for:
* - each BPF progral load (BPF_PROG_LOAD) attempt, unless overridden
* with bpf_program__set_log() on per-program level, to get
* BPF verifier log output.
* - during BPF object's BTF load into kernel (BPF_BTF_LOAD) to get
* BTF sanity checking log.
*
* Each BPF command (BPF_BTF_LOAD or BPF_PROG_LOAD) will overwrite
* previous contents, so if you need more fine-grained control, set
* per-program buffer with bpf_program__set_log_buf() to preserve each
* individual program's verification log. Keep using kernel_log_buf
* for BTF verification log, if necessary.
*/
char *kernel_log_buf;
size_t kernel_log_size;
/*
* Log level can be set independently from log buffer. Log_level=0
* means that libbpf will attempt loading BTF or program without any
* logging requested, but will retry with either its own or custom log
* buffer, if provided, and log_level=1 on any error.
* And vice versa, setting log_level>0 will request BTF or prog
* loading with verbose log from the first attempt (and as such also
* for successfully loaded BTF or program), and the actual log buffer
* could be either libbpf's own auto-allocated log buffer, if
* kernel_log_buffer is NULL, or user-provided custom kernel_log_buf.
* If user didn't provide custom log buffer, libbpf will emit captured
* logs through its print callback.
*/
__u32 kernel_log_level;
/* Path to BPF FS mount point to derive BPF token from.
*
* Created BPF token will be used for all bpf() syscall operations
* that accept BPF token (e.g., map creation, BTF and program loads,
* etc) automatically within instantiated BPF object.
*
* If bpf_token_path is not specified, libbpf will consult
* LIBBPF_BPF_TOKEN_PATH environment variable. If set, it will be
* taken as a value of bpf_token_path option and will force libbpf to
* either create BPF token from provided custom BPF FS path, or will
* disable implicit BPF token creation, if envvar value is an empty
* string. bpf_token_path overrides LIBBPF_BPF_TOKEN_PATH, if both are
* set at the same time.
*
* Setting bpf_token_path option to empty string disables libbpf's
* automatic attempt to create BPF token from default BPF FS mount
* point (/sys/fs/bpf), in case this default behavior is undesirable.
*/
const char *bpf_token_path;
size_t :0;
};
Annotation
- Immediate include surface: `stdarg.h`, `stdio.h`, `stdint.h`, `stdbool.h`, `sys/types.h`, `linux/bpf.h`, `libbpf_common.h`, `libbpf_legacy.h`.
- Detected declarations: `struct bpf_object`, `struct bpf_object_open_opts`, `struct btf`, `struct bpf_program`, `struct bpf_insn`, `struct bpf_link`, `struct bpf_perf_event_opts`, `struct bpf_kprobe_opts`, `struct bpf_kprobe_multi_opts`, `struct bpf_uprobe_multi_opts`.
- 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.