eBPF for Windows
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
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
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
143__u32
144bpf_map__max_entries(const struct bpf_map* map);
145
153const char*
154bpf_map__name(const struct bpf_map* map);
155
173int
174bpf_map__pin(struct bpf_map* map, const char* path);
175
183enum bpf_map_type
184bpf_map__type(const struct bpf_map* map);
185
201int
202bpf_map__unpin(struct bpf_map* map, const char* path);
203
211__u32
212bpf_map__value_size(const struct bpf_map* map);
213
223const char*
225
240void
241bpf_object__close(struct bpf_object* object);
242
251struct bpf_map*
252bpf_object__find_map_by_name(const struct bpf_object* obj, const char* name);
253
265int
266bpf_object__find_map_fd_by_name(const struct bpf_object* obj, const char* name);
267
278struct bpf_program*
279bpf_object__find_program_by_name(const struct bpf_object* obj, const char* name);
280
297int
298bpf_object__load(struct bpf_object* obj);
299
307const char*
308bpf_object__name(const struct bpf_object* obj);
309
320struct bpf_map*
321bpf_object__next_map(const struct bpf_object* obj, const struct bpf_map* map);
322
333struct bpf_program*
334bpf_object__next_program(const struct bpf_object* obj, struct bpf_program* prog);
335
343struct bpf_object*
344bpf_object__open(const char* path);
345
355struct bpf_object*
356bpf_object__open_file(const char* path, const struct bpf_object_open_opts* opts);
357
376int
377bpf_object__pin(struct bpf_object* object, const char* path);
378
396int
397bpf_object__pin_maps(struct bpf_object* obj, const char* path);
398
416int
417bpf_object__pin_programs(struct bpf_object* obj, const char* path);
418
429struct bpf_map*
430bpf_object__prev_map(const struct bpf_object* obj, const struct bpf_map* map);
431
442struct bpf_program*
443bpf_object__prev_program(const struct bpf_object* obj, struct bpf_program* prog);
444
460int
461bpf_object__unpin_maps(struct bpf_object* obj, const char* path);
462
478int
479bpf_object__unpin_programs(struct bpf_object* obj, const char* path);
480
501struct bpf_link*
502bpf_program__attach(const struct bpf_program* prog);
503
516struct bpf_link*
517bpf_program__attach_xdp(struct bpf_program* prog, int ifindex);
518
530bool
531bpf_program__autoload(const struct bpf_program* prog);
532
545int
546bpf_program__set_autoload(struct bpf_program* prog, bool autoload);
547
560int
561bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type, unsigned int flags);
562
573int
574bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
575
587int
588bpf_prog_detach2(int prog_fd, int attachable_fd, enum bpf_attach_type type);
589
598int
599bpf_program__fd(const struct bpf_program* prog);
600
612bpf_program__get_expected_attach_type(const struct bpf_program* prog);
613
626enum bpf_prog_type
627bpf_program__get_type(const struct bpf_program* prog);
628
637size_t
638bpf_program__insn_cnt(const struct bpf_program* prog);
639
650const char*
651bpf_program__name(const struct bpf_program* prog);
652
673int
674bpf_program__pin(struct bpf_program* prog, const char* path);
675
683const char*
684bpf_program__section_name(const struct bpf_program* prog);
685
698int
699bpf_program__set_expected_attach_type(struct bpf_program* prog, enum bpf_attach_type type);
700
712int
713bpf_program__set_type(struct bpf_program* prog, enum bpf_prog_type type);
714
724enum bpf_prog_type
725bpf_program__type(const struct bpf_program* prog);
726
735void
736bpf_program__unload(struct bpf_program* prog);
737
753int
754bpf_program__unpin(struct bpf_program* prog, const char* path);
755
771int
772bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags, const struct bpf_xdp_attach_opts* opts);
773
790int
791bpf_xdp_detach(int ifindex, __u32 flags, const struct bpf_xdp_attach_opts* opts);
792
805int
806bpf_xdp_query_id(int ifindex, int flags, __u32* prog_id);
807
818int
819libbpf_attach_type_by_name(const char* name, enum bpf_attach_type* attach_type);
820
830const char*
832
842const char*
844
855int
856libbpf_prog_type_by_name(const char* name, enum bpf_prog_type* prog_type, enum bpf_attach_type* expected_attach_type);
857
872long
873libbpf_get_error(const void* ptr);
874
885int
886libbpf_strerror(int err, char* buf, size_t size);
887
893int
895
896/* Ring buffer APIs */
897
908struct ring_buffer*
909ring_buffer__new(int map_fd, ring_buffer_sample_fn sample_cb, void* ctx, const struct ring_buffer_opts* opts);
910
917void
918ring_buffer__free(struct ring_buffer* rb);
927__u32
928bpf_program__flags(const struct bpf_program* prog);
929
943int
944bpf_program__set_flags(struct bpf_program* prog, __u32 flags);
945
946#else
947#pragma warning(push)
948#pragma warning(disable : 4200) // Zero-sized array in struct/union
949#pragma warning(disable : 4201) // Zero-sized array in struct/union
950#include "libbpf/src/libbpf.h"
951#pragma warning(pop)
952#endif
953#include "libbpf_legacy.h"
#define bpf_map
Definition bpf_helpers_platform.h:16
bpf_prog_type
Definition ebpf_structs.h:178
bpf_link_type
Definition ebpf_structs.h:278
bpf_attach_type
Definition ebpf_structs.h:292
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.
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.
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.
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.
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 new 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 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.
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 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.
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 maximum number of entries allowed in 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.
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.
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 ...
uint32_t __u32
Definition types.h:6