eBPF for Windows
Loading...
Searching...
No Matches
libbpf.h
Go to the documentation of this file.
1// Copyright (c) eBPF for Windows contributors
2// SPDX-License-Identifier: MIT
3
4#ifdef __doxygen
5
10
22int
23bpf_link__destroy(struct bpf_link* link);
24
32void
33bpf_link__disconnect(struct bpf_link* link);
34
43int
44bpf_link__fd(const struct bpf_link* link);
45
62int
63bpf_link__pin(struct bpf_link* link, const char* path);
64
78int
79bpf_link__unpin(struct bpf_link* link);
80
90const char*
92
94
99
108int
109bpf_map__fd(const struct bpf_map* map);
110
123bool
124bpf_map__is_pinned(const struct bpf_map* map);
125
133__u32
134bpf_map__key_size(const struct bpf_map* map);
135
146__u32
147bpf_map__max_entries(const struct bpf_map* map);
148
156const char*
157bpf_map__name(const struct bpf_map* map);
158
176int
177bpf_map__pin(struct bpf_map* map, const char* path);
178
186enum bpf_map_type
187bpf_map__type(const struct bpf_map* map);
188
204int
205bpf_map__unpin(struct bpf_map* map, const char* path);
206
214__u32
215bpf_map__value_size(const struct bpf_map* map);
216
226const char*
228
230
235
243void
244bpf_object__close(struct bpf_object* object);
245
254struct bpf_map*
255bpf_object__find_map_by_name(const struct bpf_object* obj, const char* name);
256
268int
269bpf_object__find_map_fd_by_name(const struct bpf_object* obj, const char* name);
270
281struct bpf_program*
282bpf_object__find_program_by_name(const struct bpf_object* obj, const char* name);
283
300int
301bpf_object__load(struct bpf_object* obj);
302
310const char*
311bpf_object__name(const struct bpf_object* obj);
312
323struct bpf_map*
324bpf_object__next_map(const struct bpf_object* obj, const struct bpf_map* map);
325
336struct bpf_program*
337bpf_object__next_program(const struct bpf_object* obj, struct bpf_program* prog);
338
346struct bpf_object*
347bpf_object__open(const char* path);
348
358struct bpf_object*
359bpf_object__open_file(const char* path, const struct bpf_object_open_opts* opts);
360
379int
380bpf_object__pin(struct bpf_object* object, const char* path);
381
399int
400bpf_object__pin_maps(struct bpf_object* obj, const char* path);
401
419int
420bpf_object__pin_programs(struct bpf_object* obj, const char* path);
421
432struct bpf_map*
433bpf_object__prev_map(const struct bpf_object* obj, const struct bpf_map* map);
434
445struct bpf_program*
446bpf_object__prev_program(const struct bpf_object* obj, struct bpf_program* prog);
447
463int
464bpf_object__unpin_maps(struct bpf_object* obj, const char* path);
465
481int
482bpf_object__unpin_programs(struct bpf_object* obj, const char* path);
483
485
490
504struct bpf_link*
505bpf_program__attach(const struct bpf_program* prog);
506
519struct bpf_link*
520bpf_program__attach_xdp(struct bpf_program* prog, int ifindex);
521
533bool
534bpf_program__autoload(const struct bpf_program* prog);
535
548int
549bpf_program__set_autoload(struct bpf_program* prog, bool autoload);
550
563int
564bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type, unsigned int flags);
565
576int
577bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
578
590int
591bpf_prog_detach2(int prog_fd, int attachable_fd, enum bpf_attach_type type);
592
601int
602bpf_program__fd(const struct bpf_program* prog);
603
615bpf_program__get_expected_attach_type(const struct bpf_program* prog);
616
629enum bpf_prog_type
630bpf_program__get_type(const struct bpf_program* prog);
631
640size_t
641bpf_program__insn_cnt(const struct bpf_program* prog);
642
653const char*
654bpf_program__name(const struct bpf_program* prog);
655
676int
677bpf_program__pin(struct bpf_program* prog, const char* path);
678
686const char*
687bpf_program__section_name(const struct bpf_program* prog);
688
701int
702bpf_program__set_expected_attach_type(struct bpf_program* prog, enum bpf_attach_type type);
703
715int
716bpf_program__set_type(struct bpf_program* prog, enum bpf_prog_type type);
717
727enum bpf_prog_type
728bpf_program__type(const struct bpf_program* prog);
729
738void
739bpf_program__unload(struct bpf_program* prog);
740
756int
757bpf_program__unpin(struct bpf_program* prog, const char* path);
758
774int
775bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags, const struct bpf_xdp_attach_opts* opts);
776
793int
794bpf_xdp_detach(int ifindex, __u32 flags, const struct bpf_xdp_attach_opts* opts);
795
808int
809bpf_xdp_query_id(int ifindex, int flags, __u32* prog_id);
810
821int
822libbpf_attach_type_by_name(const char* name, enum bpf_attach_type* attach_type);
823
833const char*
835
845const char*
847
858int
859libbpf_prog_type_by_name(const char* name, enum bpf_prog_type* prog_type, enum bpf_attach_type* expected_attach_type);
860
862
867
875long
876libbpf_get_error(const void* ptr);
877
888int
889libbpf_strerror(int err, char* buf, size_t size);
890
896int
898
899/* Ring buffer APIs */
900
911typedef int (*ring_buffer_sample_fn)(void* ctx, void* data, size_t size);
912
917{
918 size_t sz; /* Size of this struct, for forward/backward compatibility. */
919};
920
921#define ring_buffer_opts__last_field sz
922
936struct ring_buffer*
937ring_buffer__new(int map_fd, ring_buffer_sample_fn sample_cb, void* ctx, const struct ring_buffer_opts* opts);
938
950int
951ring_buffer__add(struct ring_buffer* rb, int map_fd, ring_buffer_sample_fn sample_cb, void* ctx);
952
963int
964ring_buffer__poll(struct ring_buffer* rb, int timeout_ms);
965
975int
976ring_buffer__consume(struct ring_buffer* rb);
977
983void
984ring_buffer__free(struct ring_buffer* rb);
986
993__u32
994bpf_program__flags(const struct bpf_program* prog);
995
1009int
1010bpf_program__set_flags(struct bpf_program* prog, __u32 flags);
1011
1012/* Perf buffer APIs */
1013
1022typedef void (*perf_buffer_sample_fn)(void* ctx, int cpu, void* data, __u32 size);
1023
1031typedef void (*perf_buffer_lost_fn)(void* ctx, int cpu, __u64 cnt);
1032
1037{
1038 size_t sz; /* size of this struct, for forward/backward compatibility */
1039};
1040
1041#define perf_buffer_opts__last_field sz
1042
1054LIBBPF_API struct perf_buffer*
1056 int map_fd,
1057 size_t page_cnt,
1058 perf_buffer_sample_fn sample_cb,
1059 perf_buffer_lost_fn lost_cb,
1060 void* ctx,
1061 const struct perf_buffer_opts* opts);
1062
1071LIBBPF_API int
1072perf_buffer__poll(struct perf_buffer* pb, int timeout_ms);
1073
1081LIBBPF_API int
1082perf_buffer__consume(struct perf_buffer* pb);
1083
1092LIBBPF_API int
1093perf_buffer__consume_buffer(struct perf_buffer* pb, size_t buf_idx);
1094
1102LIBBPF_API size_t
1103perf_buffer__buffer_cnt(const struct perf_buffer* pb);
1104
1110LIBBPF_API void
1111perf_buffer__free(struct perf_buffer* pb);
1112
1113#else
1114#pragma warning(push)
1115#pragma warning(disable : 4200) // Zero-sized array in struct/union
1116#pragma warning(disable : 4201) // Zero-sized array in struct/union
1117#include "libbpf/src/libbpf.h"
1118#pragma warning(pop)
1119#endif
1120#include "libbpf_legacy.h"
#define bpf_map
Definition bpf_helpers_platform.h:16
bpf_prog_type
Definition ebpf_structs.h:203
bpf_link_type
Definition ebpf_structs.h:299
bpf_attach_type
Definition ebpf_structs.h:310
bpf_map_type
Definition ebpf_structs.h:18
int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type)
Detach eBPF program(s) from an attach point.
const char * libbpf_bpf_prog_type_str(enum bpf_prog_type t)
libbpf_bpf_prog_type_str() converts the provided program type value into a textual representation.
int bpf_object__load(struct bpf_object *obj)
Load all the programs in a given object.
bool bpf_map__is_pinned(const struct bpf_map *map)
Determine whether a map is pinned.
int bpf_program__set_autoload(struct bpf_program *prog, bool autoload)
Set whether an eBPF program will be loaded when the object is loaded.
int bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags, const struct bpf_xdp_attach_opts *opts)
Attach an XDP program to a given interface.
struct ring_buffer * ring_buffer__new(int map_fd, ring_buffer_sample_fn sample_cb, void *ctx, const struct ring_buffer_opts *opts)
Creates a new ring buffer manager with synchronous callbacks.
int bpf_program__set_expected_attach_type(struct bpf_program *prog, enum bpf_attach_type type)
bpf_program__set_expected_attach_type() sets the attach type of the passed BPF program....
int libbpf_attach_type_by_name(const char *name, enum bpf_attach_type *attach_type)
libbpf_attach_type_by_name() converts the provided textual representation into an attach type value.
LIBBPF_API struct perf_buffer * perf_buffer__new(int map_fd, size_t page_cnt, perf_buffer_sample_fn sample_cb, perf_buffer_lost_fn lost_cb, void *ctx, const struct perf_buffer_opts *opts)
Create BPF perfbuf manager.
const char * bpf_map__name(const struct bpf_map *map)
Get the name of an eBPF map.
struct bpf_link * bpf_program__attach(const struct bpf_program *prog)
bpf_program__attach() is a generic function for attaching a BPF program based on the program's expect...
int bpf_object__unpin_maps(struct bpf_object *obj, const char *path)
Unpin all maps associated with an eBPF object from a specified path.
int bpf_program__set_flags(struct bpf_program *prog, __u32 flags)
Set the BPF program flags. The set of flags is defined by the program type. Neither libbpf nor the eB...
struct bpf_object * bpf_object__open_file(const char *path, const struct bpf_object_open_opts *opts)
Open a file without loading the programs.
int bpf_program__unpin(struct bpf_program *prog, const char *path)
Unpin a program.
struct bpf_map * bpf_object__next_map(const struct bpf_object *obj, const struct bpf_map *map)
Get the next map for a given eBPF object.
LIBBPF_API int perf_buffer__consume_buffer(struct perf_buffer *pb, size_t buf_idx)
Consume records from a specific per-CPU buffer.
void bpf_object__close(struct bpf_object *object)
Close an eBPF object.
struct bpf_link * bpf_program__attach_xdp(struct bpf_program *prog, int ifindex)
Attach an eBPF program to an XDP hook.
struct bpf_object * bpf_object__open(const char *path)
Open a file without loading the programs.
LIBBPF_API size_t perf_buffer__buffer_cnt(const struct perf_buffer *pb)
Get the number of per-CPU buffers in the perf buffer manager.
size_t bpf_program__insn_cnt(const struct bpf_program *prog)
bpf_program__insn_cnt() returns number of struct bpf_insn's that form specified BPF program.
enum bpf_attach_type bpf_program__get_expected_attach_type(const struct bpf_program *prog)
Get the expected attach type for an eBPF program.
int bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type, unsigned int flags)
Attach an eBPF program to an attach point.
__u32 bpf_map__value_size(const struct bpf_map *map)
Get the size of values in a given map.
struct bpf_program * bpf_object__prev_program(const struct bpf_object *obj, struct bpf_program *prog)
Get the previous eBPF program for a given eBPF object.
void ring_buffer__free(struct ring_buffer *rb)
Frees a ring buffer manager.
const char * libbpf_bpf_attach_type_str(enum bpf_attach_type t)
libbpf_bpf_attach_type_str() converts the provided attach type value into a textual representation.
struct bpf_program * bpf_object__find_program_by_name(const struct bpf_object *obj, const char *name)
Find a program with a given name among programs associated with an eBPF object.
const char * bpf_object__name(const struct bpf_object *obj)
Get the name of an eBPF object.
int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type, enum bpf_attach_type *expected_attach_type)
Get a program type and expected attach type by name.
struct bpf_map * bpf_object__prev_map(const struct bpf_object *obj, const struct bpf_map *map)
Get the previous map for a given eBPF object.
__u32 bpf_map__key_size(const struct bpf_map *map)
Get the size of keys in a given map.
int bpf_object__pin_programs(struct bpf_object *obj, const char *path)
Pin all programs associated with an eBPF object to a specified path.
enum bpf_prog_type bpf_program__get_type(const struct bpf_program *prog)
Get the program type for an eBPF program.
long libbpf_get_error(const void *ptr)
Get a negative error code based on errno and a possibly null pointer.
void bpf_link__disconnect(struct bpf_link *link)
Release ownership of a link so that it is not detached when destroyed.
int bpf_object__unpin_programs(struct bpf_object *obj, const char *path)
Unpin all programs associated with an eBPF object from a specified path.
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 ...
int bpf_object__find_map_fd_by_name(const struct bpf_object *obj, const char *name)
Find a map with a given name among maps associated with an eBPF object.
int ring_buffer__consume(struct ring_buffer *rb)
Consume all available records without waiting.
int bpf_map__fd(const struct bpf_map *map)
Get a file descriptor that refers to a map.
enum bpf_prog_type bpf_program__type(const struct bpf_program *prog)
Get the program type for an eBPF program.
__u32 bpf_program__flags(const struct bpf_program *prog)
Query the BPF program flags.
LIBBPF_API int perf_buffer__poll(struct perf_buffer *pb, int timeout_ms)
Poll perf buffer for new data with timeout.
void(* perf_buffer_sample_fn)(void *ctx, int cpu, void *data, __u32 size)
Perf buffer callback function for sample data.
Definition libbpf.h:1022
const char * libbpf_bpf_link_type_str(enum bpf_link_type t)
libbpf_bpf_link_type_str() converts the provided link type value into a textual representation.
int bpf_object__pin(struct bpf_object *object, const char *path)
Pin an eBPF object to a specified path.
int bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type)
bpf_program__set_type() sets the program type of the passed BPF program.
int bpf_prog_detach2(int prog_fd, int attachable_fd, enum bpf_attach_type type)
Detach an eBPF program from an attach point.
int bpf_program__fd(const struct bpf_program *prog)
Get a file descriptor that refers to a program.
int bpf_xdp_detach(int ifindex, __u32 flags, const struct bpf_xdp_attach_opts *opts)
Detach an XDP program from a given interface.
const char * bpf_program__name(const struct bpf_program *prog)
Get the function name of an eBPF program.
int libbpf_num_possible_cpus(void)
Get the number of processors on the current system.
int bpf_link__fd(const struct bpf_link *link)
Get a file descriptor that refers to a link.
int bpf_link__unpin(struct bpf_link *link)
Unpin a link.
void bpf_program__unload(struct bpf_program *prog)
Unload a program.
int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms)
Poll ring buffer for available data and consume records by calling sample_cb.
int bpf_link__destroy(struct bpf_link *link)
Clean up a link.
int libbpf_strerror(int err, char *buf, size_t size)
Get an error message.
bool bpf_program__autoload(const struct bpf_program *prog)
Get whether an eBPF program will be loaded when the object is loaded.
LIBBPF_API int perf_buffer__consume(struct perf_buffer *pb)
Consume available records without waiting.
const char * libbpf_bpf_map_type_str(enum bpf_map_type t)
libbpf_bpf_map_type_str() converts the provided map type value into a textual representation.
__u32 bpf_map__max_entries(const struct bpf_map *map)
Get the configured max_entries value for a given map.
int bpf_xdp_query_id(int ifindex, int flags, __u32 *prog_id)
Get the XDP program id attached to a given interface index.
struct bpf_program * bpf_object__next_program(const struct bpf_object *obj, struct bpf_program *prog)
Get the next program for a given eBPF object.
int bpf_link__pin(struct bpf_link *link, const char *path)
Pin a link to a specified path.
LIBBPF_API void perf_buffer__free(struct perf_buffer *pb)
Free a perf buffer manager.
enum bpf_map_type bpf_map__type(const struct bpf_map *map)
Get the type of a map.
int bpf_map__unpin(struct bpf_map *map, const char *path)
Unpin a map.
int bpf_object__pin_maps(struct bpf_object *obj, const char *path)
Pin all maps associated with an eBPF object to a specified path.
int bpf_map__pin(struct bpf_map *map, const char *path)
Pin a map to a specified path.
int(* ring_buffer_sample_fn)(void *ctx, void *data, size_t size)
Ring buffer callback function type.
Definition libbpf.h:911
int ring_buffer__add(struct ring_buffer *rb, int map_fd, ring_buffer_sample_fn sample_cb, void *ctx)
Add another ring buffer map to the ring buffer manager.
void(* perf_buffer_lost_fn)(void *ctx, int cpu, __u64 cnt)
Perf buffer callback function for lost events.
Definition libbpf.h:1031
const char * bpf_program__section_name(const struct bpf_program *prog)
Gets the ELF section name of an eBPF program, if any.
int bpf_program__pin(struct bpf_program *prog, const char *path)
Pin a program to a specified path. This increments the programs reference count, allowing it to stay ...
Perf buffer options structure.
Definition libbpf.h:1037
size_t sz
Definition libbpf.h:1038
Ring buffer options structure (Linux-compatible, limited functionality).
Definition libbpf.h:917
size_t sz
Definition libbpf.h:918
uint32_t __u32
Definition types.h:6
uint64_t __u64
Definition types.h:7