LIBBPF API

libbpf.h

Functions

LIBBPF_API int libbpf_strerror (int err, char *buf, size_t size)
LIBBPF_API libbpf_print_fn_t libbpf_set_print (libbpf_print_fn_t fn)
LIBBPF_API struct bpf_object * bpf_object__open (const char *path)
LIBBPF_API struct bpf_object * bpf_object__open_file (const char *path, const struct bpf_object_open_opts *opts)
LIBBPF_API struct bpf_object * bpf_object__open_mem (const void *obj_buf, size_t obj_buf_sz, const struct bpf_object_open_opts *opts)
LIBBPF_API struct bpf_object * bpf_object__open_buffer (const void *obj_buf, size_t obj_buf_sz, const char *name)
LIBBPF_API struct bpf_object * bpf_object__open_xattr (struct bpf_object_open_attr *attr)
LIBBPF_API int bpf_object__pin_maps (struct bpf_object *obj, const char *path)
LIBBPF_API int bpf_object__unpin_maps (struct bpf_object *obj, const char *path)
LIBBPF_API int bpf_object__pin_programs (struct bpf_object *obj, const char *path)
LIBBPF_API int bpf_object__unpin_programs (struct bpf_object *obj, const char *path)
LIBBPF_API int bpf_object__pin (struct bpf_object *object, const char *path)
LIBBPF_API void bpf_object__close (struct bpf_object *object)
LIBBPF_API int bpf_object__load (struct bpf_object *obj)
LIBBPF_API int bpf_object__load_xattr (struct bpf_object_load_attr *attr)
LIBBPF_DEPRECATED_SINCE (0, 6, "bpf_object__unload() is deprecated, use bpf_object__close() instead") LIBBPF_API int bpf_object__unload(struct bpf_object *obj)
LIBBPF_API const char * bpf_object__name (const struct bpf_object *obj)
LIBBPF_API unsigned int bpf_object__kversion (const struct bpf_object *obj)
LIBBPF_API int bpf_object__set_kversion (struct bpf_object *obj, __u32 kern_version)
LIBBPF_API struct btf * bpf_object__btf (const struct bpf_object *obj)
LIBBPF_API int bpf_object__btf_fd (const struct bpf_object *obj)
LIBBPF_API struct bpf_program * bpf_object__find_program_by_title (const struct bpf_object *obj, const char *title)
LIBBPF_API struct bpf_program * bpf_object__find_program_by_name (const struct bpf_object *obj, const char *name)
LIBBPF_API struct bpf_object * bpf_object__next (struct bpf_object *prev)
LIBBPF_API int bpf_object__set_priv (struct bpf_object *obj, void *priv, bpf_object_clear_priv_t clear_priv)
LIBBPF_API void * bpf_object__priv (const struct bpf_object *prog)
LIBBPF_API int libbpf_prog_type_by_name (const char *name, enum bpf_prog_type *prog_type, enum bpf_attach_type *expected_attach_type)
LIBBPF_API int libbpf_attach_type_by_name (const char *name, enum bpf_attach_type *attach_type)
LIBBPF_API int libbpf_find_vmlinux_btf_id (const char *name, enum bpf_attach_type attach_type)
LIBBPF_API LIBBPF_DEPRECATED_SINCE (0, 7, "use bpf_object__next_program() instead") struct bpf_program *bpf_program__next(struct bpf_program *prog
LIBBPF_API struct bpf_program * bpf_object__next_program (const struct bpf_object *obj, struct bpf_program *prog)
LIBBPF_API LIBBPF_DEPRECATED_SINCE (0, 7, "use bpf_object__prev_program() instead") struct bpf_program *bpf_program__prev(struct bpf_program *prog
LIBBPF_API struct bpf_program * bpf_object__prev_program (const struct bpf_object *obj, struct bpf_program *prog)
LIBBPF_API int bpf_program__set_priv (struct bpf_program *prog, void *priv, bpf_program_clear_priv_t clear_priv)
LIBBPF_API void * bpf_program__priv (const struct bpf_program *prog)
LIBBPF_API void bpf_program__set_ifindex (struct bpf_program *prog, __u32 ifindex)
LIBBPF_API const char * bpf_program__name (const struct bpf_program *prog)
LIBBPF_API const char * bpf_program__section_name (const struct bpf_program *prog)
LIBBPF_API LIBBPF_DEPRECATED ("BPF program title is confusing term; please use bpf_program__section_name() instead") const char *bpf_program__title(const struct bpf_program *prog
LIBBPF_API bool bpf_program__autoload (const struct bpf_program *prog)
LIBBPF_API int bpf_program__set_autoload (struct bpf_program *prog, bool autoload)
LIBBPF_API size_t bpf_program__size (const struct bpf_program *prog)
LIBBPF_API int bpf_program__load (struct bpf_program *prog, char *license, __u32 kern_version)
LIBBPF_API int bpf_program__fd (const struct bpf_program *prog)
LIBBPF_API int bpf_program__pin_instance (struct bpf_program *prog, const char *path, int instance)
LIBBPF_API int bpf_program__unpin_instance (struct bpf_program *prog, const char *path, int instance)
LIBBPF_API int bpf_program__pin (struct bpf_program *prog, const char *path)
LIBBPF_API int bpf_program__unpin (struct bpf_program *prog, const char *path)
LIBBPF_API void bpf_program__unload (struct bpf_program *prog)
LIBBPF_API struct bpf_link * bpf_link__open (const char *path)
LIBBPF_API int bpf_link__fd (const struct bpf_link *link)
LIBBPF_API const char * bpf_link__pin_path (const struct bpf_link *link)
LIBBPF_API int bpf_link__pin (struct bpf_link *link, const char *path)
LIBBPF_API int bpf_link__unpin (struct bpf_link *link)
LIBBPF_API int bpf_link__update_program (struct bpf_link *link, struct bpf_program *prog)
LIBBPF_API void bpf_link__disconnect (struct bpf_link *link)
LIBBPF_API int bpf_link__detach (struct bpf_link *link)
LIBBPF_API int bpf_link__destroy (struct bpf_link *link)
LIBBPF_API struct bpf_link * bpf_program__attach (const struct bpf_program *prog)
LIBBPF_API struct bpf_link * bpf_program__attach_perf_event (const struct bpf_program *prog, int pfd)
LIBBPF_API struct bpf_link * bpf_program__attach_perf_event_opts (const struct bpf_program *prog, int pfd, const struct bpf_perf_event_opts *opts)
LIBBPF_API struct bpf_link * bpf_program__attach_kprobe (const struct bpf_program *prog, bool retprobe, const char *func_name)
LIBBPF_API struct bpf_link * bpf_program__attach_kprobe_opts (const struct bpf_program *prog, const char *func_name, const struct bpf_kprobe_opts *opts)
LIBBPF_API struct bpf_link * bpf_program__attach_uprobe (const struct bpf_program *prog, bool retprobe, pid_t pid, const char *binary_path, size_t func_offset)
LIBBPF_API struct bpf_link * bpf_program__attach_uprobe_opts (const struct bpf_program *prog, pid_t pid, const char *binary_path, size_t func_offset, const struct bpf_uprobe_opts *opts)
LIBBPF_API struct bpf_link * bpf_program__attach_tracepoint (const struct bpf_program *prog, const char *tp_category, const char *tp_name)
LIBBPF_API struct bpf_link * bpf_program__attach_tracepoint_opts (const struct bpf_program *prog, const char *tp_category, const char *tp_name, const struct bpf_tracepoint_opts *opts)
LIBBPF_API struct bpf_link * bpf_program__attach_raw_tracepoint (const struct bpf_program *prog, const char *tp_name)
LIBBPF_API struct bpf_link * bpf_program__attach_trace (const struct bpf_program *prog)
LIBBPF_API struct bpf_link * bpf_program__attach_lsm (const struct bpf_program *prog)
LIBBPF_API struct bpf_link * bpf_program__attach_cgroup (const struct bpf_program *prog, int cgroup_fd)
LIBBPF_API struct bpf_link * bpf_program__attach_netns (const struct bpf_program *prog, int netns_fd)
LIBBPF_API struct bpf_link * bpf_program__attach_xdp (const struct bpf_program *prog, int ifindex)
LIBBPF_API struct bpf_link * bpf_program__attach_freplace (const struct bpf_program *prog, int target_fd, const char *attach_func_name)
LIBBPF_API struct bpf_link * bpf_map__attach_struct_ops (const struct bpf_map *map)
LIBBPF_API struct bpf_link * bpf_program__attach_iter (const struct bpf_program *prog, const struct bpf_iter_attach_opts *opts)
LIBBPF_API int bpf_program__set_prep (struct bpf_program *prog, int nr_instance, bpf_program_prep_t prep)
LIBBPF_API int bpf_program__nth_fd (const struct bpf_program *prog, int n)
LIBBPF_API int bpf_program__set_socket_filter (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_tracepoint (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_raw_tracepoint (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_kprobe (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_lsm (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_sched_cls (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_sched_act (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_xdp (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_perf_event (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_tracing (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_struct_ops (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_extension (struct bpf_program *prog)
LIBBPF_API int bpf_program__set_sk_lookup (struct bpf_program *prog)
LIBBPF_API enum bpf_prog_type bpf_program__get_type (const struct bpf_program *prog)
LIBBPF_API void bpf_program__set_type (struct bpf_program *prog, enum bpf_prog_type type)
LIBBPF_API enum bpf_attach_type bpf_program__get_expected_attach_type (const struct bpf_program *prog)
LIBBPF_API void bpf_program__set_expected_attach_type (struct bpf_program *prog, enum bpf_attach_type type)
LIBBPF_API int bpf_program__set_attach_target (struct bpf_program *prog, int attach_prog_fd, const char *attach_func_name)
LIBBPF_API bool bpf_program__is_socket_filter (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_tracepoint (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_raw_tracepoint (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_kprobe (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_lsm (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_sched_cls (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_sched_act (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_xdp (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_perf_event (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_tracing (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_struct_ops (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_extension (const struct bpf_program *prog)
LIBBPF_API bool bpf_program__is_sk_lookup (const struct bpf_program *prog)
LIBBPF_API struct bpf_map * bpf_object__find_map_by_name (const struct bpf_object *obj, const char *name)

bpf_object__find_map_by_name() returns BPF map of the given name, if it exists within the passed BPF object

Parameters
  • obj – BPF object

  • name – name of the BPF map

Returns

BPF map instance, if such map exists within the BPF object; or NULL otherwise.

LIBBPF_API int bpf_object__find_map_fd_by_name (const struct bpf_object *obj, const char *name)
LIBBPF_API struct bpf_map * bpf_object__find_map_by_offset (struct bpf_object *obj, size_t offset)
LIBBPF_API LIBBPF_DEPRECATED_SINCE (0, 7, "use bpf_object__next_map() instead") struct bpf_map *bpf_map__next(const struct bpf_map *map
LIBBPF_API struct bpf_map * bpf_object__next_map (const struct bpf_object *obj, const struct bpf_map *map)
LIBBPF_API LIBBPF_DEPRECATED_SINCE (0, 7, "use bpf_object__prev_map() instead") struct bpf_map *bpf_map__prev(const struct bpf_map *map
LIBBPF_API struct bpf_map * bpf_object__prev_map (const struct bpf_object *obj, const struct bpf_map *map)
LIBBPF_API int bpf_map__fd (const struct bpf_map *map)

bpf_map__fd() gets the file descriptor of the passed BPF map

Parameters

map – the BPF map instance

Returns

the file descriptor; or -EINVAL in case of an error

LIBBPF_API int bpf_map__reuse_fd (struct bpf_map *map, int fd)
LIBBPF_API const struct bpf_map_def * bpf_map__def (const struct bpf_map *map)
LIBBPF_API const char * bpf_map__name (const struct bpf_map *map)
LIBBPF_API enum bpf_map_type bpf_map__type (const struct bpf_map *map)
LIBBPF_API int bpf_map__set_type (struct bpf_map *map, enum bpf_map_type type)
LIBBPF_API __u32 bpf_map__max_entries (const struct bpf_map *map)
LIBBPF_API int bpf_map__set_max_entries (struct bpf_map *map, __u32 max_entries)
LIBBPF_API int bpf_map__resize (struct bpf_map *map, __u32 max_entries)
LIBBPF_API __u32 bpf_map__map_flags (const struct bpf_map *map)
LIBBPF_API int bpf_map__set_map_flags (struct bpf_map *map, __u32 flags)
LIBBPF_API __u32 bpf_map__numa_node (const struct bpf_map *map)
LIBBPF_API int bpf_map__set_numa_node (struct bpf_map *map, __u32 numa_node)
LIBBPF_API __u32 bpf_map__key_size (const struct bpf_map *map)
LIBBPF_API int bpf_map__set_key_size (struct bpf_map *map, __u32 size)
LIBBPF_API __u32 bpf_map__value_size (const struct bpf_map *map)
LIBBPF_API int bpf_map__set_value_size (struct bpf_map *map, __u32 size)
LIBBPF_API __u32 bpf_map__btf_key_type_id (const struct bpf_map *map)
LIBBPF_API __u32 bpf_map__btf_value_type_id (const struct bpf_map *map)
LIBBPF_API __u32 bpf_map__ifindex (const struct bpf_map *map)
LIBBPF_API int bpf_map__set_ifindex (struct bpf_map *map, __u32 ifindex)
LIBBPF_API int bpf_map__set_priv (struct bpf_map *map, void *priv, bpf_map_clear_priv_t clear_priv)
LIBBPF_API void * bpf_map__priv (const struct bpf_map *map)
LIBBPF_API int bpf_map__set_initial_value (struct bpf_map *map, const void *data, size_t size)
LIBBPF_API const void * bpf_map__initial_value (struct bpf_map *map, size_t *psize)
LIBBPF_API bool bpf_map__is_offload_neutral (const struct bpf_map *map)
LIBBPF_API bool bpf_map__is_internal (const struct bpf_map *map)

bpf_map__is_internal() tells the caller whether or not the passed map is a special map created by libbpf automatically for things like global variables, __ksym externs, Kconfig values, etc

Parameters

map – the bpf_map

Returns

true, if the map is an internal map; false, otherwise

LIBBPF_API int bpf_map__set_pin_path (struct bpf_map *map, const char *path)
LIBBPF_API const char * bpf_map__get_pin_path (const struct bpf_map *map)
LIBBPF_API const char * bpf_map__pin_path (const struct bpf_map *map)
LIBBPF_API bool bpf_map__is_pinned (const struct bpf_map *map)
LIBBPF_API int bpf_map__pin (struct bpf_map *map, const char *path)
LIBBPF_API int bpf_map__unpin (struct bpf_map *map, const char *path)
LIBBPF_API int bpf_map__set_inner_map_fd (struct bpf_map *map, int fd)
LIBBPF_API struct bpf_map * bpf_map__inner_map (struct bpf_map *map)
LIBBPF_API long libbpf_get_error (const void *ptr)

libbpf_get_error() extracts the error code from the passed pointer

Many libbpf API functions which return pointers have logic to encode error codes as pointers, and do not return NULL. Meaning libbpf_get_error() should be used on the return value from these functions immediately after calling the API function, with no intervening calls that could clobber the errno variable. Consult the individual functions documentation to verify if this logic applies should be used.

For these API functions, if libbpf_set_strict_mode(LIBBPF_STRICT_CLEAN_PTRS) is enabled, NULL is returned on error instead.

If ptr is NULL, then errno should be already set by the failing API, because libbpf never returns NULL on success and it now always sets errno on error.

Example usage:

struct perf_buffer *pb;

pb = perf_buffer__new(bpf_map__fd(obj->maps.events), PERF_BUFFER_PAGES, &opts); err = libbpf_get_error(pb); if (err) { pb = NULL; fprintf(stderr, “failed to open perf buffer: %d\n”, err); goto cleanup; }

Parameters

ptr – pointer returned from libbpf API function

Returns

error code; or 0 if no error occured

LIBBPF_API int bpf_prog_load_xattr (const struct bpf_prog_load_attr *attr, struct bpf_object **pobj, int *prog_fd)
LIBBPF_API int bpf_prog_load (const char *file, enum bpf_prog_type type, struct bpf_object **pobj, int *prog_fd)
LIBBPF_API int bpf_set_link_xdp_fd (int ifindex, int fd, __u32 flags)
LIBBPF_API int bpf_set_link_xdp_fd_opts (int ifindex, int fd, __u32 flags, const struct bpf_xdp_set_link_opts *opts)
LIBBPF_API int bpf_get_link_xdp_id (int ifindex, __u32 *prog_id, __u32 flags)
LIBBPF_API int bpf_get_link_xdp_info (int ifindex, struct xdp_link_info *info, size_t info_size, __u32 flags)
LIBBPF_API int bpf_tc_hook_create (struct bpf_tc_hook *hook)
LIBBPF_API int bpf_tc_hook_destroy (struct bpf_tc_hook *hook)
LIBBPF_API int bpf_tc_attach (const struct bpf_tc_hook *hook, struct bpf_tc_opts *opts)
LIBBPF_API int bpf_tc_detach (const struct bpf_tc_hook *hook, const struct bpf_tc_opts *opts)
LIBBPF_API int bpf_tc_query (const struct bpf_tc_hook *hook, struct bpf_tc_opts *opts)
LIBBPF_API struct ring_buffer * ring_buffer__new (int map_fd, ring_buffer_sample_fn sample_cb, void *ctx, const struct ring_buffer_opts *opts)
LIBBPF_API void ring_buffer__free (struct ring_buffer *rb)
LIBBPF_API int ring_buffer__add (struct ring_buffer *rb, int map_fd, ring_buffer_sample_fn sample_cb, void *ctx)
LIBBPF_API int ring_buffer__poll (struct ring_buffer *rb, int timeout_ms)
LIBBPF_API int ring_buffer__consume (struct ring_buffer *rb)
LIBBPF_API int ring_buffer__epoll_fd (const struct ring_buffer *rb)
LIBBPF_API struct perf_buffer * perf_buffer__new (int map_fd, size_t page_cnt, const struct perf_buffer_opts *opts)
LIBBPF_API struct perf_buffer * perf_buffer__new_raw (int map_fd, size_t page_cnt, const struct perf_buffer_raw_opts *opts)
LIBBPF_API void perf_buffer__free (struct perf_buffer *pb)
LIBBPF_API int perf_buffer__epoll_fd (const struct perf_buffer *pb)
LIBBPF_API int perf_buffer__poll (struct perf_buffer *pb, int timeout_ms)
LIBBPF_API int perf_buffer__consume (struct perf_buffer *pb)
LIBBPF_API int perf_buffer__consume_buffer (struct perf_buffer *pb, size_t buf_idx)
LIBBPF_API size_t perf_buffer__buffer_cnt (const struct perf_buffer *pb)
LIBBPF_API int perf_buffer__buffer_fd (const struct perf_buffer *pb, size_t buf_idx)
LIBBPF_API enum bpf_perf_event_ret bpf_perf_event_read_simple (void *mmap_mem, size_t mmap_size, size_t page_size, void **copy_mem, size_t *copy_size, bpf_perf_event_print_t fn, void *private_data)
LIBBPF_API void bpf_prog_linfo__free (struct bpf_prog_linfo *prog_linfo)
LIBBPF_API struct bpf_prog_linfo * bpf_prog_linfo__new (const struct bpf_prog_info *info)
LIBBPF_API const struct bpf_line_info * bpf_prog_linfo__lfind_addr_func (const struct bpf_prog_linfo *prog_linfo, __u64 addr, __u32 func_idx, __u32 nr_skip)
LIBBPF_API const struct bpf_line_info * bpf_prog_linfo__lfind (const struct bpf_prog_linfo *prog_linfo, __u32 insn_off, __u32 nr_skip)
LIBBPF_API bool bpf_probe_prog_type (enum bpf_prog_type prog_type, __u32 ifindex)
LIBBPF_API bool bpf_probe_map_type (enum bpf_map_type map_type, __u32 ifindex)
LIBBPF_API bool bpf_probe_helper (enum bpf_func_id id, enum bpf_prog_type prog_type, __u32 ifindex)
LIBBPF_API bool bpf_probe_large_insn_limit (__u32 ifindex)
LIBBPF_API struct bpf_prog_info_linear * bpf_program__get_prog_info_linear (int fd, __u64 arrays)
LIBBPF_API void bpf_program__bpil_addr_to_offs (struct bpf_prog_info_linear *info_linear)
LIBBPF_API void bpf_program__bpil_offs_to_addr (struct bpf_prog_info_linear *info_linear)
LIBBPF_API int libbpf_num_possible_cpus (void)

libbpf_num_possible_cpus() is a helper function to get the number of possible CPUs that the host kernel supports and expects.

Example usage:

int ncpus = libbpf_num_possible_cpus();
if (ncpus < 0) {
     // error handling
}
long values[ncpus];
bpf_map_lookup_elem(per_cpu_map_fd, key, values);

Returns

number of possible CPUs; or error code on failure

LIBBPF_API int bpf_object__open_skeleton (struct bpf_object_skeleton *s, const struct bpf_object_open_opts *opts)
LIBBPF_API int bpf_object__load_skeleton (struct bpf_object_skeleton *s)
LIBBPF_API int bpf_object__attach_skeleton (struct bpf_object_skeleton *s)
LIBBPF_API void bpf_object__detach_skeleton (struct bpf_object_skeleton *s)
LIBBPF_API void bpf_object__destroy_skeleton (struct bpf_object_skeleton *s)
LIBBPF_API int bpf_object__gen_loader (struct bpf_object *obj, struct gen_loader_opts *opts)
LIBBPF_API struct bpf_linker * bpf_linker__new (const char *filename, struct bpf_linker_opts *opts)
LIBBPF_API int bpf_linker__add_file (struct bpf_linker *linker, const char *filename, const struct bpf_linker_file_opts *opts)
LIBBPF_API int bpf_linker__finalize (struct bpf_linker *linker)
LIBBPF_API void bpf_linker__free (struct bpf_linker *linker)

Defines

bpf_object_open_opts__last_field btf_custom_path
bpf_object__for_each_safe(pos, tmp)

for ((pos) = bpf_object__next(NULL), \

(tmp) = bpf_object__next(pos); \

(pos) != NULL; \

(pos) = (tmp), (tmp) = bpf_object__next(tmp))


bpf_object__for_each_program(pos, obj)

for ((pos) = bpf_object__next_program((obj), NULL); \

(pos) != NULL; \

(pos) = bpf_object__next_program((obj), (pos)))


bpf_perf_event_opts__last_field bpf_cookie
bpf_kprobe_opts__last_field retprobe
bpf_uprobe_opts__last_field retprobe
bpf_tracepoint_opts__last_field bpf_cookie
bpf_iter_attach_opts__last_field link_info_len
bpf_object__for_each_map(pos, obj)

for ((pos) = bpf_object__next_map((obj), NULL); \

(pos) != NULL; \

(pos) = bpf_object__next_map((obj), (pos)))


bpf_map__for_each bpf_object__for_each_map
BPF_TC_PARENT(a, b) ((((a) << 16) & 0xFFFF0000U) | ((b) & 0x0000FFFFU))
bpf_tc_hook__last_field parent
bpf_tc_opts__last_field priority
ring_buffer_opts__last_field sz
gen_loader_opts__last_field insns_sz
bpf_linker_opts__last_field sz
bpf_linker_file_opts__last_field sz

Enums

enum libbpf_errno

Values:

enumerator __LIBBPF_ERRNO__START = 4000
enumerator LIBBPF_ERRNO__LIBELF = __LIBBPF_ERRNO__START
enumerator LIBBPF_ERRNO__FORMAT
enumerator LIBBPF_ERRNO__KVERSION
enumerator LIBBPF_ERRNO__ENDIAN
enumerator LIBBPF_ERRNO__INTERNAL
enumerator LIBBPF_ERRNO__RELOC
enumerator LIBBPF_ERRNO__LOAD
enumerator LIBBPF_ERRNO__VERIFY
enumerator LIBBPF_ERRNO__PROG2BIG
enumerator LIBBPF_ERRNO__KVER
enumerator LIBBPF_ERRNO__PROGTYPE
enumerator LIBBPF_ERRNO__WRNGPID
enumerator LIBBPF_ERRNO__INVSEQ
enumerator LIBBPF_ERRNO__NLPARSE
enumerator __LIBBPF_ERRNO__END
enum libbpf_print_level

Values:

enumerator LIBBPF_WARN
enumerator LIBBPF_INFO
enumerator LIBBPF_DEBUG
enum libbpf_pin_type

Values:

enumerator LIBBPF_PIN_NONE
enumerator LIBBPF_PIN_BY_NAME
enumerator LIBBPF_PIN_NONE
enumerator LIBBPF_PIN_BY_NAME
enum bpf_tc_attach_point

Values:

enumerator BPF_TC_INGRESS = 1 << 0
enumerator BPF_TC_EGRESS = 1 << 1
enumerator BPF_TC_CUSTOM = 1 << 2
enum bpf_tc_flags

Values:

enumerator BPF_TC_F_REPLACE = 1 << 0
enum bpf_perf_event_ret

Values:

enumerator LIBBPF_PERF_EVENT_DONE = 0
enumerator LIBBPF_PERF_EVENT_ERROR = -1
enumerator LIBBPF_PERF_EVENT_CONT = -2
enum bpf_prog_info_array

Values:

enumerator BPF_PROG_INFO_FIRST_ARRAY = 0
enumerator BPF_PROG_INFO_JITED_INSNS = 0
enumerator BPF_PROG_INFO_XLATED_INSNS
enumerator BPF_PROG_INFO_MAP_IDS
enumerator BPF_PROG_INFO_JITED_KSYMS
enumerator BPF_PROG_INFO_JITED_FUNC_LENS
enumerator BPF_PROG_INFO_FUNC_INFO
enumerator BPF_PROG_INFO_LINE_INFO
enumerator BPF_PROG_INFO_JITED_LINE_INFO
enumerator BPF_PROG_INFO_PROG_TAGS
enumerator BPF_PROG_INFO_LAST_ARRAY
enum libbpf_tristate

Values:

enumerator TRI_NO = 0
enumerator TRI_YES = 1
enumerator TRI_MODULE = 2
enumerator TRI_NO = 0
enumerator TRI_YES = 1
enumerator TRI_MODULE = 2

bpf.h

Functions

LIBBPF_API int bpf_create_map_xattr (const struct bpf_create_map_attr *create_attr)
LIBBPF_API int bpf_create_map_node (enum bpf_map_type map_type, const char *name, int key_size, int value_size, int max_entries, __u32 map_flags, int node)
LIBBPF_API int bpf_create_map_name (enum bpf_map_type map_type, const char *name, int key_size, int value_size, int max_entries, __u32 map_flags)
LIBBPF_API int bpf_create_map (enum bpf_map_type map_type, int key_size, int value_size, int max_entries, __u32 map_flags)
LIBBPF_API int bpf_create_map_in_map_node (enum bpf_map_type map_type, const char *name, int key_size, int inner_map_fd, int max_entries, __u32 map_flags, int node)
LIBBPF_API int bpf_create_map_in_map (enum bpf_map_type map_type, const char *name, int key_size, int inner_map_fd, int max_entries, __u32 map_flags)
LIBBPF_API int bpf_load_program_xattr (const struct bpf_load_program_attr *load_attr, char *log_buf, size_t log_buf_sz)
LIBBPF_API int bpf_load_program (enum bpf_prog_type type, const struct bpf_insn *insns, size_t insns_cnt, const char *license, __u32 kern_version, char *log_buf, size_t log_buf_sz)
LIBBPF_API int bpf_verify_program (enum bpf_prog_type type, const struct bpf_insn *insns, size_t insns_cnt, __u32 prog_flags, const char *license, __u32 kern_version, char *log_buf, size_t log_buf_sz, int log_level)
LIBBPF_API int bpf_map_update_elem (int fd, const void *key, const void *value, __u64 flags)
LIBBPF_API int bpf_map_lookup_elem (int fd, const void *key, void *value)
LIBBPF_API int bpf_map_lookup_elem_flags (int fd, const void *key, void *value, __u64 flags)
LIBBPF_API int bpf_map_lookup_and_delete_elem (int fd, const void *key, void *value)
LIBBPF_API int bpf_map_lookup_and_delete_elem_flags (int fd, const void *key, void *value, __u64 flags)
LIBBPF_API int bpf_map_delete_elem (int fd, const void *key)
LIBBPF_API int bpf_map_get_next_key (int fd, const void *key, void *next_key)
LIBBPF_API int bpf_map_freeze (int fd)
LIBBPF_API int bpf_map_delete_batch (int fd, void *keys, __u32 *count, const struct bpf_map_batch_opts *opts)
LIBBPF_API int bpf_map_lookup_batch (int fd, void *in_batch, void *out_batch, void *keys, void *values, __u32 *count, const struct bpf_map_batch_opts *opts)
LIBBPF_API int bpf_map_lookup_and_delete_batch (int fd, void *in_batch, void *out_batch, void *keys, void *values, __u32 *count, const struct bpf_map_batch_opts *opts)
LIBBPF_API int bpf_map_update_batch (int fd, void *keys, void *values, __u32 *count, const struct bpf_map_batch_opts *opts)
LIBBPF_API int bpf_obj_pin (int fd, const char *pathname)
LIBBPF_API int bpf_obj_get (const char *pathname)
LIBBPF_API int bpf_prog_attach (int prog_fd, int attachable_fd, enum bpf_attach_type type, unsigned int flags)
LIBBPF_API int bpf_prog_attach_xattr (int prog_fd, int attachable_fd, enum bpf_attach_type type, const struct bpf_prog_attach_opts *opts)
LIBBPF_API int bpf_prog_detach (int attachable_fd, enum bpf_attach_type type)
LIBBPF_API int bpf_prog_detach2 (int prog_fd, int attachable_fd, enum bpf_attach_type type)
LIBBPF_API int bpf_link_create (int prog_fd, int target_fd, enum bpf_attach_type attach_type, const struct bpf_link_create_opts *opts)
LIBBPF_API int bpf_link_detach (int link_fd)
LIBBPF_API int bpf_link_update (int link_fd, int new_prog_fd, const struct bpf_link_update_opts *opts)
LIBBPF_API int bpf_iter_create (int link_fd)
LIBBPF_API int bpf_prog_test_run_xattr (struct bpf_prog_test_run_attr *test_attr)
LIBBPF_API int bpf_prog_test_run (int prog_fd, int repeat, void *data, __u32 size, void *data_out, __u32 *size_out, __u32 *retval, __u32 *duration)
LIBBPF_API int bpf_prog_get_next_id (__u32 start_id, __u32 *next_id)
LIBBPF_API int bpf_map_get_next_id (__u32 start_id, __u32 *next_id)
LIBBPF_API int bpf_btf_get_next_id (__u32 start_id, __u32 *next_id)
LIBBPF_API int bpf_link_get_next_id (__u32 start_id, __u32 *next_id)
LIBBPF_API int bpf_prog_get_fd_by_id (__u32 id)
LIBBPF_API int bpf_map_get_fd_by_id (__u32 id)
LIBBPF_API int bpf_btf_get_fd_by_id (__u32 id)
LIBBPF_API int bpf_link_get_fd_by_id (__u32 id)
LIBBPF_API int bpf_obj_get_info_by_fd (int bpf_fd, void *info, __u32 *info_len)
LIBBPF_API int bpf_prog_query (int target_fd, enum bpf_attach_type type, __u32 query_flags, __u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt)
LIBBPF_API int bpf_raw_tracepoint_open (const char *name, int prog_fd)
LIBBPF_API int bpf_load_btf (const void *btf, __u32 btf_size, char *log_buf, __u32 log_buf_size, bool do_log)
LIBBPF_API int bpf_task_fd_query (int pid, int fd, __u32 flags, char *buf, __u32 *buf_len, __u32 *prog_id, __u32 *fd_type, __u64 *probe_offset, __u64 *probe_addr)
LIBBPF_API int bpf_enable_stats (enum bpf_stats_type type)
LIBBPF_API int bpf_prog_bind_map (int prog_fd, int map_fd, const struct bpf_prog_bind_opts *opts)
LIBBPF_API int bpf_prog_test_run_opts (int prog_fd, struct bpf_test_run_opts *opts)

Defines

MAPS_RELAX_COMPAT 0x01
BPF_LOG_BUF_SIZE (UINT32_MAX >> 8) /* verifier maximum in kernels <= 5.1 */
bpf_map_batch_opts__last_field flags
bpf_prog_attach_opts__last_field replace_prog_fd
bpf_prog_bind_opts__last_field flags
bpf_test_run_opts__last_field cpu

btf.h

Functions

LIBBPF_API void btf__free (struct btf *btf)

btf__free() frees all data of a BTF object

Parameters

btf – BTF object to free

LIBBPF_API struct btf * btf__new (const void *data, __u32 size)

btf__new() creates a new instance of a BTF object from the raw bytes of an ELF’s BTF section

On error, error-code-encoded-as-pointer is returned, not a NULL. To extract error code from such a pointer libbpf_get_error() should be used. If libbpf_set_strict_mode(LIBBPF_STRICT_CLEAN_PTRS) is enabled, NULL is returned on error instead. In both cases thread-local errno variable is always set to error code as well.

Parameters
  • data – raw bytes

  • size – number of bytes passed in data

Returns

new BTF object instance which has to be eventually freed with btf__free()

LIBBPF_API struct btf * btf__new_split (const void *data, __u32 size, struct btf *base_btf)

btf__new_split() create a new instance of a BTF object from the provided raw data bytes. It takes another BTF instance, base_btf, which serves as a base BTF, which is extended by types in a newly created BTF instance

If base_btf is NULL, btf__new_split() is equivalent to btf__new() and creates non-split BTF.

On error, error-code-encoded-as-pointer is returned, not a NULL. To extract error code from such a pointer libbpf_get_error() should be used. If libbpf_set_strict_mode(LIBBPF_STRICT_CLEAN_PTRS) is enabled, NULL is returned on error instead. In both cases thread-local errno variable is always set to error code as well.

Parameters
  • data – raw bytes

  • size – length of raw bytes

  • base_btf – the base BTF object

Returns

new BTF object instance which has to be eventually freed with btf__free()

LIBBPF_API struct btf * btf__new_empty (void)

btf__new_empty() creates an empty BTF object. Use btf__add_*() to populate such BTF object.

On error, error-code-encoded-as-pointer is returned, not a NULL. To extract error code from such a pointer libbpf_get_error() should be used. If libbpf_set_strict_mode(LIBBPF_STRICT_CLEAN_PTRS) is enabled, NULL is returned on error instead. In both cases thread-local errno variable is always set to error code as well.

Returns

new BTF object instance which has to be eventually freed with btf__free()

LIBBPF_API struct btf * btf__new_empty_split (struct btf *base_btf)

btf__new_empty_split() creates an unpopulated BTF object from an ELF BTF section except with a base BTF on top of which split BTF should be based

If base_btf is NULL, btf__new_empty_split() is equivalent to btf__new_empty() and creates non-split BTF.

On error, error-code-encoded-as-pointer is returned, not a NULL. To extract error code from such a pointer libbpf_get_error() should be used. If libbpf_set_strict_mode(LIBBPF_STRICT_CLEAN_PTRS) is enabled, NULL is returned on error instead. In both cases thread-local errno variable is always set to error code as well.

Returns

new BTF object instance which has to be eventually freed with btf__free()

LIBBPF_API struct btf * btf__parse (const char *path, struct btf_ext **btf_ext)
LIBBPF_API struct btf * btf__parse_split (const char *path, struct btf *base_btf)
LIBBPF_API struct btf * btf__parse_elf (const char *path, struct btf_ext **btf_ext)
LIBBPF_API struct btf * btf__parse_elf_split (const char *path, struct btf *base_btf)
LIBBPF_API struct btf * btf__parse_raw (const char *path)
LIBBPF_API struct btf * btf__parse_raw_split (const char *path, struct btf *base_btf)
LIBBPF_API struct btf * btf__load_vmlinux_btf (void)
LIBBPF_API struct btf * btf__load_module_btf (const char *module_name, struct btf *vmlinux_btf)
LIBBPF_API struct btf * libbpf_find_kernel_btf (void)
LIBBPF_API struct btf * btf__load_from_kernel_by_id (__u32 id)
LIBBPF_API struct btf * btf__load_from_kernel_by_id_split (__u32 id, struct btf *base_btf)
LIBBPF_DEPRECATED_SINCE (0, 6, "use btf__load_from_kernel_by_id instead") LIBBPF_API int btf__get_from_id(__u32 id
LIBBPF_API int btf__finalize_data (struct bpf_object *obj, struct btf *btf)
LIBBPF_DEPRECATED_SINCE (0, 6, "use btf__load_into_kernel instead") LIBBPF_API int btf__load(struct btf *btf)
LIBBPF_API int btf__load_into_kernel (struct btf *btf)
LIBBPF_API __s32 btf__find_by_name (const struct btf *btf, const char *type_name)
LIBBPF_API __s32 btf__find_by_name_kind (const struct btf *btf, const char *type_name, __u32 kind)
LIBBPF_API __u32 btf__get_nr_types (const struct btf *btf)
LIBBPF_API const struct btf * btf__base_btf (const struct btf *btf)
LIBBPF_API const struct btf_type * btf__type_by_id (const struct btf *btf, __u32 id)
LIBBPF_API size_t btf__pointer_size (const struct btf *btf)
LIBBPF_API int btf__set_pointer_size (struct btf *btf, size_t ptr_sz)
LIBBPF_API enum btf_endianness btf__endianness (const struct btf *btf)
LIBBPF_API int btf__set_endianness (struct btf *btf, enum btf_endianness endian)
LIBBPF_API __s64 btf__resolve_size (const struct btf *btf, __u32 type_id)
LIBBPF_API int btf__resolve_type (const struct btf *btf, __u32 type_id)
LIBBPF_API int btf__align_of (const struct btf *btf, __u32 id)
LIBBPF_API int btf__fd (const struct btf *btf)
LIBBPF_API void btf__set_fd (struct btf *btf, int fd)
LIBBPF_API const void * btf__get_raw_data (const struct btf *btf, __u32 *size)
LIBBPF_API const char * btf__name_by_offset (const struct btf *btf, __u32 offset)
LIBBPF_API const char * btf__str_by_offset (const struct btf *btf, __u32 offset)
LIBBPF_API int btf__get_map_kv_tids (const struct btf *btf, const char *map_name, __u32 expected_key_size, __u32 expected_value_size, __u32 *key_type_id, __u32 *value_type_id)
LIBBPF_API struct btf_ext * btf_ext__new (__u8 *data, __u32 size)
LIBBPF_API void btf_ext__free (struct btf_ext *btf_ext)
LIBBPF_API const void * btf_ext__get_raw_data (const struct btf_ext *btf_ext, __u32 *size)
LIBBPF_API LIBBPF_DEPRECATED ("btf_ext__reloc_func_info was never meant as a public API and has wrong assumptions embedded in it; it will be removed in the future libbpf versions") int btf_ext__reloc_func_info(const struct btf *btf
LIBBPF_API LIBBPF_DEPRECATED ("btf_ext__reloc_line_info was never meant as a public API and has wrong assumptions embedded in it; it will be removed in the future libbpf versions") int btf_ext__reloc_line_info(const struct btf *btf
LIBBPF_API __u32 btf_ext__func_info_rec_size (const struct btf_ext *btf_ext)
LIBBPF_API __u32 btf_ext__line_info_rec_size (const struct btf_ext *btf_ext)
LIBBPF_API int btf__find_str (struct btf *btf, const char *s)
LIBBPF_API int btf__add_str (struct btf *btf, const char *s)
LIBBPF_API int btf__add_type (struct btf *btf, const struct btf *src_btf, const struct btf_type *src_type)
LIBBPF_API int btf__add_btf (struct btf *btf, const struct btf *src_btf)

btf__add_btf() appends all the BTF types from src_btf into btf

btf__add_btf() can be used to simply and efficiently append the entire contents of one BTF object to another one. All the BTF type data is copied over, all referenced type IDs are adjusted by adding a necessary ID offset. Only strings referenced from BTF types are copied over and deduplicated, so if there were some unused strings in src_btf, those won’t be copied over, which is consistent with the general string deduplication semantics of BTF writing APIs.

If any error is encountered during this process, the contents of btf is left intact, which means that btf__add_btf() follows the transactional semantics and the operation as a whole is all-or-nothing.

src_btf has to be non-split BTF, as of now copying types from split BTF is not supported and will result in -ENOTSUP error code returned.

Parameters
  • btf – BTF object which all the BTF types and strings are added to

  • src_btf – BTF object which all BTF types and referenced strings are copied from

Returns

BTF type ID of the first appended BTF type, or negative error code

LIBBPF_API int btf__add_int (struct btf *btf, const char *name, size_t byte_sz, int encoding)
LIBBPF_API int btf__add_float (struct btf *btf, const char *name, size_t byte_sz)
LIBBPF_API int btf__add_ptr (struct btf *btf, int ref_type_id)
LIBBPF_API int btf__add_array (struct btf *btf, int index_type_id, int elem_type_id, __u32 nr_elems)
LIBBPF_API int btf__add_struct (struct btf *btf, const char *name, __u32 sz)
LIBBPF_API int btf__add_union (struct btf *btf, const char *name, __u32 sz)
LIBBPF_API int btf__add_field (struct btf *btf, const char *name, int field_type_id, __u32 bit_offset, __u32 bit_size)
LIBBPF_API int btf__add_enum (struct btf *btf, const char *name, __u32 bytes_sz)
LIBBPF_API int btf__add_enum_value (struct btf *btf, const char *name, __s64 value)
LIBBPF_API int btf__add_fwd (struct btf *btf, const char *name, enum btf_fwd_kind fwd_kind)
LIBBPF_API int btf__add_typedef (struct btf *btf, const char *name, int ref_type_id)
LIBBPF_API int btf__add_volatile (struct btf *btf, int ref_type_id)
LIBBPF_API int btf__add_const (struct btf *btf, int ref_type_id)
LIBBPF_API int btf__add_restrict (struct btf *btf, int ref_type_id)
LIBBPF_API int btf__add_func (struct btf *btf, const char *name, enum btf_func_linkage linkage, int proto_type_id)
LIBBPF_API int btf__add_func_proto (struct btf *btf, int ret_type_id)
LIBBPF_API int btf__add_func_param (struct btf *btf, const char *name, int type_id)
LIBBPF_API int btf__add_var (struct btf *btf, const char *name, int linkage, int type_id)
LIBBPF_API int btf__add_datasec (struct btf *btf, const char *name, __u32 byte_sz)
LIBBPF_API int btf__add_datasec_var_info (struct btf *btf, int var_type_id, __u32 offset, __u32 byte_sz)
LIBBPF_API int btf__add_tag (struct btf *btf, const char *value, int ref_type_id, int component_idx)
LIBBPF_API int btf__dedup (struct btf *btf, struct btf_ext *btf_ext, const struct btf_dedup_opts *opts)
LIBBPF_API struct btf_dump * btf_dump__new (const struct btf *btf, const struct btf_ext *btf_ext, const struct btf_dump_opts *opts, btf_dump_printf_fn_t printf_fn)
LIBBPF_API void btf_dump__free (struct btf_dump *d)
LIBBPF_API int btf_dump__dump_type (struct btf_dump *d, __u32 id)
LIBBPF_API int btf_dump__emit_type_decl (struct btf_dump *d, __u32 id, const struct btf_dump_emit_type_decl_opts *opts)
LIBBPF_API int btf_dump__dump_type_data (struct btf_dump *d, __u32 id, const void *data, size_t data_sz, const struct btf_dump_type_data_opts *opts)
static inline __u16 btf_kind(const struct btf_type *t)
static inline __u16 btf_vlen(const struct btf_type *t)
static inline bool btf_kflag(const struct btf_type *t)
static inline bool btf_is_void(const struct btf_type *t)
static inline bool btf_is_int(const struct btf_type *t)
static inline bool btf_is_ptr(const struct btf_type *t)
static inline bool btf_is_array(const struct btf_type *t)
static inline bool btf_is_struct(const struct btf_type *t)
static inline bool btf_is_union(const struct btf_type *t)
static inline bool btf_is_composite(const struct btf_type *t)
static inline bool btf_is_enum(const struct btf_type *t)
static inline bool btf_is_fwd(const struct btf_type *t)
static inline bool btf_is_typedef(const struct btf_type *t)
static inline bool btf_is_volatile(const struct btf_type *t)
static inline bool btf_is_const(const struct btf_type *t)
static inline bool btf_is_restrict(const struct btf_type *t)
static inline bool btf_is_mod(const struct btf_type *t)
static inline bool btf_is_func(const struct btf_type *t)
static inline bool btf_is_func_proto(const struct btf_type *t)
static inline bool btf_is_var(const struct btf_type *t)
static inline bool btf_is_datasec(const struct btf_type *t)
static inline bool btf_is_float(const struct btf_type *t)
static inline bool btf_is_tag(const struct btf_type *t)
static inline __u8 btf_int_encoding(const struct btf_type *t)
static inline __u8 btf_int_offset(const struct btf_type *t)
static inline __u8 btf_int_bits(const struct btf_type *t)
static struct btf_array *btf_array(const struct btf_type *t)
static struct btf_enum *btf_enum(const struct btf_type *t)
static struct btf_member *btf_members(const struct btf_type *t)
static inline __u32 btf_member_bit_offset(const struct btf_type *t, __u32 member_idx)
static inline __u32 btf_member_bitfield_size(const struct btf_type *t, __u32 member_idx)
static struct btf_param *btf_params(const struct btf_type *t)
static struct btf_var *btf_var(const struct btf_type *t)
static struct btf_var_secinfo *btf_var_secinfos(const struct btf_type *t)
static struct btf_tag *btf_tag(const struct btf_type *t)

Defines

BTF_ELF_SEC ".BTF"
BTF_EXT_ELF_SEC ".BTF.ext"
MAPS_ELF_SEC ".maps"
btf_dump_emit_type_decl_opts__last_field strip_mods
btf_dump_type_data_opts__last_field emit_zeroes

Enums

enum btf_endianness

Values:

enumerator BTF_LITTLE_ENDIAN = 0
enumerator BTF_BIG_ENDIAN = 1
enum btf_fwd_kind

Values:

enumerator BTF_FWD_STRUCT = 0
enumerator BTF_FWD_UNION = 1
enumerator BTF_FWD_ENUM = 2

xsk.h

Functions

DEFINE_XSK_RING(xsk_ring_prod)
DEFINE_XSK_RING(xsk_ring_cons)
static inline __u64 *xsk_ring_prod__fill_addr(struct xsk_ring_prod *fill, __u32 idx)
static inline const __u64 *xsk_ring_cons__comp_addr(const struct xsk_ring_cons *comp, __u32 idx)
static struct xdp_desc *xsk_ring_prod__tx_desc(struct xsk_ring_prod *tx, __u32 idx)
static const struct xdp_desc *xsk_ring_cons__rx_desc(const struct xsk_ring_cons *rx, __u32 idx)
static inline int xsk_ring_prod__needs_wakeup(const struct xsk_ring_prod *r)
static inline __u32 xsk_prod_nb_free(struct xsk_ring_prod *r, __u32 nb)
static inline __u32 xsk_cons_nb_avail(struct xsk_ring_cons *r, __u32 nb)
static inline __u32 xsk_ring_prod__reserve(struct xsk_ring_prod *prod, __u32 nb, __u32 *idx)
static inline void xsk_ring_prod__submit(struct xsk_ring_prod *prod, __u32 nb)
static inline __u32 xsk_ring_cons__peek(struct xsk_ring_cons *cons, __u32 nb, __u32 *idx)
static inline void xsk_ring_cons__cancel(struct xsk_ring_cons *cons, __u32 nb)
static inline void xsk_ring_cons__release(struct xsk_ring_cons *cons, __u32 nb)
static inline void *xsk_umem__get_data(void *umem_area, __u64 addr)
static inline __u64 xsk_umem__extract_addr(__u64 addr)
static inline __u64 xsk_umem__extract_offset(__u64 addr)
static inline __u64 xsk_umem__add_offset_to_addr(__u64 addr)
LIBBPF_API int xsk_umem__fd (const struct xsk_umem *umem)
LIBBPF_API int xsk_socket__fd (const struct xsk_socket *xsk)
LIBBPF_API int xsk_setup_xdp_prog (int ifindex, int *xsks_map_fd)
LIBBPF_API int xsk_socket__update_xskmap (struct xsk_socket *xsk, int xsks_map_fd)
LIBBPF_API int xsk_umem__create (struct xsk_umem **umem, void *umem_area, __u64 size, struct xsk_ring_prod *fill, struct xsk_ring_cons *comp, const struct xsk_umem_config *config)
LIBBPF_API int xsk_umem__create_v0_0_2 (struct xsk_umem **umem, void *umem_area, __u64 size, struct xsk_ring_prod *fill, struct xsk_ring_cons *comp, const struct xsk_umem_config *config)
LIBBPF_API int xsk_umem__create_v0_0_4 (struct xsk_umem **umem, void *umem_area, __u64 size, struct xsk_ring_prod *fill, struct xsk_ring_cons *comp, const struct xsk_umem_config *config)
LIBBPF_API int xsk_socket__create (struct xsk_socket **xsk, const char *ifname, __u32 queue_id, struct xsk_umem *umem, struct xsk_ring_cons *rx, struct xsk_ring_prod *tx, const struct xsk_socket_config *config)
LIBBPF_API int xsk_socket__create_shared (struct xsk_socket **xsk_ptr, const char *ifname, __u32 queue_id, struct xsk_umem *umem, struct xsk_ring_cons *rx, struct xsk_ring_prod *tx, struct xsk_ring_prod *fill, struct xsk_ring_cons *comp, const struct xsk_socket_config *config)
LIBBPF_API int xsk_umem__delete (struct xsk_umem *umem)
LIBBPF_API void xsk_socket__delete (struct xsk_socket *xsk)

Defines

__XSK_READ_ONCE(x) (*(volatile typeof(x) *)&x)
__XSK_WRITE_ONCE(x, v) (*(volatile typeof(x) *)&x) = (v)
libbpf_smp_store_release(p, v)

do { \

__sync_synchronize(); \

__XSK_WRITE_ONCE(*p, v); \

} while (0)


libbpf_smp_load_acquire(p)

({ \

typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \

__sync_synchronize(); \

___p1; \

})


DEFINE_XSK_RING(name)

struct name { \

__u32 cached_prod; \

__u32 cached_cons; \

__u32 mask; \

__u32 size; \

__u32 *producer; \

__u32 *consumer; \

void *

ring

; \

__u32 *flags; \

}


XSK_RING_CONS__DEFAULT_NUM_DESCS 2048
XSK_RING_PROD__DEFAULT_NUM_DESCS 2048
XSK_UMEM__DEFAULT_FRAME_SHIFT 12 /* 4096 bytes */
XSK_UMEM__DEFAULT_FRAME_SIZE (1 << XSK_UMEM__DEFAULT_FRAME_SHIFT)
XSK_UMEM__DEFAULT_FRAME_HEADROOM 0
XSK_UMEM__DEFAULT_FLAGS 0
XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD (1 << 0)

bpf_tracing.h

Defines

__BPF_TARGET_MISSING "GCC error \"Must specify a BPF target arch via __TARGET_ARCH_xxx\""
PT_REGS_PARM1(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_PARM2(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_PARM3(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_PARM4(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_PARM5(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_RET(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_FP(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_RC(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_SP(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_IP(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_PARM1_CORE(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_PARM2_CORE(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_PARM3_CORE(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_PARM4_CORE(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_PARM5_CORE(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_RET_CORE(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_FP_CORE(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_RC_CORE(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_SP_CORE(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
PT_REGS_IP_CORE(x) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
BPF_KPROBE_READ_RET_IP(ip, ctx) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
BPF_KRETPROBE_READ_RET_IP(ip, ctx) ({ _Pragma(__BPF_TARGET_MISSING); 0l; })
BPF_PROG(name, args...)

name(unsigned long long *ctx);     \

static __attribute__((always_inline)) typeof(name(0))     \

____##name(unsigned long long *ctx, ##args);     \

typeof(name(0)) name(unsigned long long *ctx)     \

{     \

_Pragma("GCC diagnostic push")     \

_Pragma("GCC diagnostic ignored \"-Wint-conversion\"")     \

return ____##name(___bpf_ctx_cast(args));     \

_Pragma("GCC diagnostic pop")     \

}     \

static __attribute__((always_inline)) typeof(name(0))     \

____##name(unsigned long long *ctx, ##args)


BPF_KPROBE(name, args...)

name(struct pt_regs *ctx);     \

static __attribute__((always_inline)) typeof(name(0))     \

____##name(struct pt_regs *ctx, ##args);     \

typeof(name(0)) name(struct pt_regs *ctx)     \

{     \

_Pragma("GCC diagnostic push")     \

_Pragma("GCC diagnostic ignored \"-Wint-conversion\"")     \

return ____##name(___bpf_kprobe_args(args));     \

_Pragma("GCC diagnostic pop")     \

}     \

static __attribute__((always_inline)) typeof(name(0))     \

____##name(struct pt_regs *ctx, ##args)


BPF_KRETPROBE(name, args...)

name(struct pt_regs *ctx);     \

static __attribute__((always_inline)) typeof(name(0))     \

____##name(struct pt_regs *ctx, ##args);     \

typeof(name(0)) name(struct pt_regs *ctx)     \

{     \

_Pragma("GCC diagnostic push")     \

_Pragma("GCC diagnostic ignored \"-Wint-conversion\"")     \

return ____##name(___bpf_kretprobe_args(args));     \

_Pragma("GCC diagnostic pop")     \

}     \

static __always_inline typeof(name(0)) ____##name(struct pt_regs *ctx, ##args)


bpf_core_read.h

Defines

__CORE_RELO(src, field, info) __builtin_preserve_field_info((src)->field, BPF_FIELD_##info)
__CORE_BITFIELD_PROBE_READ(dst, src, fld)

bpf_probe_read_kernel(       \

(void *)dst,       \

__CORE_RELO(src, fld, BYTE_SIZE),       \

(const void *)src + __CORE_RELO(src, fld, BYTE_OFFSET))


BPF_CORE_READ_BITFIELD_PROBED(s, field)

({       \

unsigned long long val = 0;       \

\

__CORE_BITFIELD_PROBE_READ(&val, s, field);       \

val <<= __CORE_RELO(s, field, LSHIFT_U64);       \

if (__CORE_RELO(s, field, SIGNED))       \

val = ((long long)val) >> __CORE_RELO(s, field, RSHIFT_U64);  \

else       \

val = val >> __CORE_RELO(s, field, RSHIFT_U64);       \

val;       \

})


BPF_CORE_READ_BITFIELD(s, field)

({       \

const void *p = (const void *)s + __CORE_RELO(s, field, BYTE_OFFSET); \

unsigned long long val;       \

\

/* This is a so-called barrier_var() operation that makes specified   \

* variable "a black box" for optimizing compiler.       \

* It forces compiler to perform BYTE_OFFSET relocation on p and use  \

* its calculated value in the switch below, instead of applying      \

* the same relocation 4 times for each individual memory load.       \

*/       \

asm volatile("" : "=r"(p) : "0"(p));       \

\

switch (__CORE_RELO(s, field, BYTE_SIZE)) {       \

case 1: val = *(const unsigned char *)p; break;       \

case 2: val = *(const unsigned short *)p; break;       \

case 4: val = *(const unsigned int *)p; break;       \

case 8: val = *(const unsigned long long *)p; break;       \

}       \

val <<= __CORE_RELO(s, field, LSHIFT_U64);       \

if (__CORE_RELO(s, field, SIGNED))       \

val = ((long long)val) >> __CORE_RELO(s, field, RSHIFT_U64);  \

else       \

val = val >> __CORE_RELO(s, field, RSHIFT_U64);       \

val;       \

})


bpf_core_field_exists(field) __builtin_preserve_field_info(field, BPF_FIELD_EXISTS)
bpf_core_field_size(field) __builtin_preserve_field_info(field, BPF_FIELD_BYTE_SIZE)
bpf_core_type_id_local(type) __builtin_btf_type_id(*(typeof(type) *)0, BPF_TYPE_ID_LOCAL)
bpf_core_type_id_kernel(type) __builtin_btf_type_id(*(typeof(type) *)0, BPF_TYPE_ID_TARGET)
bpf_core_type_exists(type) __builtin_preserve_type_info(*(typeof(type) *)0, BPF_TYPE_EXISTS)
bpf_core_type_size(type) __builtin_preserve_type_info(*(typeof(type) *)0, BPF_TYPE_SIZE)
bpf_core_enum_value_exists(enum_type, enum_value) __builtin_preserve_enum_value(*(typeof(enum_type) *)enum_value, BPF_ENUMVAL_EXISTS)
bpf_core_enum_value(enum_type, enum_value) __builtin_preserve_enum_value(*(typeof(enum_type) *)enum_value, BPF_ENUMVAL_VALUE)
bpf_core_read(dst, sz, src) bpf_probe_read_kernel(dst, sz, (const void *)__builtin_preserve_access_index(src))
bpf_core_read_user(dst, sz, src) bpf_probe_read_user(dst, sz, (const void *)__builtin_preserve_access_index(src))
bpf_core_read_str(dst, sz, src) bpf_probe_read_kernel_str(dst, sz, (const void *)__builtin_preserve_access_index(src))
bpf_core_read_user_str(dst, sz, src) bpf_probe_read_user_str(dst, sz, (const void *)__builtin_preserve_access_index(src))
BPF_CORE_READ_INTO(dst, src, a, ...)

({     \

___core_read(bpf_core_read, bpf_core_read,     \

dst, (src), a, ##__VA_ARGS__)     \

})


BPF_CORE_READ_USER_INTO(dst, src, a, ...)

({     \

___core_read(bpf_core_read_user, bpf_core_read_user,     \

dst, (src), a, ##__VA_ARGS__)     \

})


BPF_PROBE_READ_INTO(dst, src, a, ...)

({     \

___core_read(bpf_probe_read, bpf_probe_read,     \

dst, (src), a, ##__VA_ARGS__)     \

})


BPF_PROBE_READ_USER_INTO(dst, src, a, ...)

({     \

___core_read(bpf_probe_read_user, bpf_probe_read_user,     \

dst, (src), a, ##__VA_ARGS__)     \

})


BPF_CORE_READ_STR_INTO(dst, src, a, ...)

({     \

___core_read(bpf_core_read_str, bpf_core_read,     \

dst, (src), a, ##__VA_ARGS__)     \

})


BPF_CORE_READ_USER_STR_INTO(dst, src, a, ...)

({     \

___core_read(bpf_core_read_user_str, bpf_core_read_user,     \

dst, (src), a, ##__VA_ARGS__)     \

})


BPF_PROBE_READ_STR_INTO(dst, src, a, ...)

({     \

___core_read(bpf_probe_read_str, bpf_probe_read,     \

dst, (src), a, ##__VA_ARGS__)     \

})


BPF_PROBE_READ_USER_STR_INTO(dst, src, a, ...)

({     \

___core_read(bpf_probe_read_user_str, bpf_probe_read_user,     \

dst, (src), a, ##__VA_ARGS__)     \

})


BPF_CORE_READ(src, a, ...)

({     \

___type((src), a, ##__VA_ARGS__) __r;     \

BPF_CORE_READ_INTO(&__r, (src), a, ##__VA_ARGS__);     \

__r;     \

})


BPF_CORE_READ_USER(src, a, ...)

({     \

___type((src), a, ##__VA_ARGS__) __r;     \

BPF_CORE_READ_USER_INTO(&__r, (src), a, ##__VA_ARGS__);     \

__r;     \

})


BPF_PROBE_READ(src, a, ...)

({     \

___type((src), a, ##__VA_ARGS__) __r;     \

BPF_PROBE_READ_INTO(&__r, (src), a, ##__VA_ARGS__);     \

__r;     \

})


BPF_PROBE_READ_USER(src, a, ...)

({     \

___type((src), a, ##__VA_ARGS__) __r;     \

BPF_PROBE_READ_USER_INTO(&__r, (src), a, ##__VA_ARGS__);     \

__r;     \

})


Enums

enum bpf_field_info_kind

Values:

enumerator BPF_FIELD_BYTE_OFFSET = 0
enumerator BPF_FIELD_BYTE_SIZE = 1
enumerator BPF_FIELD_EXISTS = 2
enumerator BPF_FIELD_SIGNED = 3
enumerator BPF_FIELD_LSHIFT_U64 = 4
enumerator BPF_FIELD_RSHIFT_U64 = 5
enum bpf_type_id_kind

Values:

enumerator BPF_TYPE_ID_LOCAL = 0
enumerator BPF_TYPE_ID_TARGET = 1
enum bpf_type_info_kind

Values:

enumerator BPF_TYPE_EXISTS = 0
enumerator BPF_TYPE_SIZE = 1
enum bpf_enum_value_kind

Values:

enumerator BPF_ENUMVAL_EXISTS = 0
enumerator BPF_ENUMVAL_VALUE = 1

bpf_endian.h

Defines

__bpf_ntohs(x) __builtin_bswap16(x)
__bpf_htons(x) __builtin_bswap16(x)
__bpf_constant_ntohs(x) ___bpf_swab16(x)
__bpf_constant_htons(x) ___bpf_swab16(x)
__bpf_ntohl(x) __builtin_bswap32(x)
__bpf_htonl(x) __builtin_bswap32(x)
__bpf_constant_ntohl(x) ___bpf_swab32(x)
__bpf_constant_htonl(x) ___bpf_swab32(x)
__bpf_be64_to_cpu(x) __builtin_bswap64(x)
__bpf_cpu_to_be64(x) __builtin_bswap64(x)
__bpf_constant_be64_to_cpu(x) ___bpf_swab64(x)
__bpf_constant_cpu_to_be64(x) ___bpf_swab64(x)
bpf_htons(x)

(__builtin_constant_p(x) ? \

__bpf_constant_htons(x) : __bpf_htons(x))


bpf_ntohs(x)

(__builtin_constant_p(x) ? \

__bpf_constant_ntohs(x) : __bpf_ntohs(x))


bpf_htonl(x)

(__builtin_constant_p(x) ? \

__bpf_constant_htonl(x) : __bpf_htonl(x))


bpf_ntohl(x)

(__builtin_constant_p(x) ? \

__bpf_constant_ntohl(x) : __bpf_ntohl(x))


bpf_cpu_to_be64(x)

(__builtin_constant_p(x) ? \

__bpf_constant_cpu_to_be64(x) : __bpf_cpu_to_be64(x))


bpf_be64_to_cpu(x)

(__builtin_constant_p(x) ? \

__bpf_constant_be64_to_cpu(x) : __bpf_be64_to_cpu(x))