eBPF for Windows
libbpf.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation
2 // SPDX-License-Identifier: MIT
3 
4 #ifdef __doxygen
5 
22 int
23 bpf_link__destroy(struct bpf_link* link);
24 
32 void
33 bpf_link__disconnect(struct bpf_link* link);
34 
43 int
44 bpf_link__fd(const struct bpf_link* link);
45 
62 int
63 bpf_link__pin(struct bpf_link* link, const char* path);
64 
78 int
79 bpf_link__unpin(struct bpf_link* link);
80 
90 const char*
92 
108 int
109 bpf_map__fd(const struct bpf_map* map);
110 
123 bool
124 bpf_map__is_pinned(const struct bpf_map* map);
125 
133 __u32
134 bpf_map__key_size(const struct bpf_map* map);
135 
143 __u32
144 bpf_map__max_entries(const struct bpf_map* map);
145 
153 const char*
154 bpf_map__name(const struct bpf_map* map);
155 
173 int
174 bpf_map__pin(struct bpf_map* map, const char* path);
175 
183 enum bpf_map_type
184 bpf_map__type(const struct bpf_map* map);
185 
201 int
202 bpf_map__unpin(struct bpf_map* map, const char* path);
203 
211 __u32
212 bpf_map__value_size(const struct bpf_map* map);
213 
223 const char*
225 
240 void
241 bpf_object__close(struct bpf_object* object);
242 
251 struct bpf_map*
252 bpf_object__find_map_by_name(const struct bpf_object* obj, const char* name);
253 
265 int
266 bpf_object__find_map_fd_by_name(const struct bpf_object* obj, const char* name);
267 
278 struct bpf_program*
279 bpf_object__find_program_by_name(const struct bpf_object* obj, const char* name);
280 
297 int
298 bpf_object__load(struct bpf_object* obj);
299 
307 const char*
308 bpf_object__name(const struct bpf_object* obj);
309 
320 struct bpf_map*
321 bpf_object__next_map(const struct bpf_object* obj, const struct bpf_map* map);
322 
333 struct bpf_program*
334 bpf_object__next_program(const struct bpf_object* obj, struct bpf_program* prog);
335 
343 struct bpf_object*
344 bpf_object__open(const char* path);
345 
354 struct bpf_object*
355 bpf_object__open_file(const char* path, const struct bpf_object_open_opts* opts);
356 
375 int
376 bpf_object__pin(struct bpf_object* object, const char* path);
377 
395 int
396 bpf_object__pin_maps(struct bpf_object* obj, const char* path);
397 
415 int
416 bpf_object__pin_programs(struct bpf_object* obj, const char* path);
417 
428 struct bpf_map*
429 bpf_object__prev_map(const struct bpf_object* obj, const struct bpf_map* map);
430 
441 struct bpf_program*
442 bpf_object__prev_program(const struct bpf_object* obj, struct bpf_program* prog);
443 
459 int
460 bpf_object__unpin_maps(struct bpf_object* obj, const char* path);
461 
477 int
478 bpf_object__unpin_programs(struct bpf_object* obj, const char* path);
479 
499 struct bpf_link*
500 bpf_program__attach(const struct bpf_program* prog);
501 
514 struct bpf_link*
515 bpf_program__attach_xdp(struct bpf_program* prog, int ifindex);
516 
529 int
530 bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type, unsigned int flags);
531 
542 int
543 bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
544 
556 int
557 bpf_prog_detach2(int prog_fd, int attachable_fd, enum bpf_attach_type type);
558 
567 int
568 bpf_program__fd(const struct bpf_program* prog);
569 
580 enum bpf_attach_type
581 bpf_program__get_expected_attach_type(const struct bpf_program* prog);
582 
595 enum bpf_prog_type
596 bpf_program__get_type(const struct bpf_program* prog);
597 
606 size_t
607 bpf_program__insn_cnt(const struct bpf_program* prog);
608 
619 const char*
620 bpf_program__name(const struct bpf_program* prog);
621 
640 int
641 bpf_program__pin(struct bpf_program* prog, const char* path);
642 
650 const char*
651 bpf_program__section_name(const struct bpf_program* prog);
652 
665 int
666 bpf_program__set_expected_attach_type(struct bpf_program* prog, enum bpf_attach_type type);
667 
680 int
681 bpf_program__set_type(struct bpf_program* prog, enum bpf_prog_type type);
682 
692 enum bpf_prog_type
693 bpf_program__type(const struct bpf_program* prog);
694 
703 void
704 bpf_program__unload(struct bpf_program* prog);
705 
721 int
722 bpf_program__unpin(struct bpf_program* prog, const char* path);
723 
739 int
740 bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags, const struct bpf_xdp_attach_opts* opts);
741 
758 int
759 bpf_xdp_detach(int ifindex, __u32 flags, const struct bpf_xdp_attach_opts* opts);
760 
773 int
774 bpf_xdp_query_id(int ifindex, int flags, __u32* prog_id);
775 
786 int
787 libbpf_attach_type_by_name(const char* name, enum bpf_attach_type* attach_type);
788 
798 const char*
800 
810 const char*
812 
823 int
824 libbpf_prog_type_by_name(const char* name, enum bpf_prog_type* prog_type, enum bpf_attach_type* expected_attach_type);
825 
840 long
841 libbpf_get_error(const void* ptr);
842 
853 int
854 libbpf_strerror(int err, char* buf, size_t size);
855 
861 int
863 
864 /* Ring buffer APIs */
865 
876 struct ring_buffer*
877 ring_buffer__new(int map_fd, ring_buffer_sample_fn sample_cb, void* ctx, const struct ring_buffer_opts* opts);
878 
885 void
886 ring_buffer__free(struct ring_buffer* rb);
889 #else
890 #pragma warning(push)
891 #pragma warning(disable : 4200) // Zero-sized array in struct/union
892 #pragma warning(disable : 4201) // Zero-sized array in struct/union
893 #include "libbpf/src/libbpf.h"
894 #pragma warning(pop)
895 #endif
896 #include "libbpf_legacy.h"
#define bpf_map
Definition: bpf_helpers_platform.h:15
bpf_prog_type
Definition: ebpf_structs.h:177
bpf_link_type
Definition: ebpf_structs.h:253
bpf_attach_type
Definition: ebpf_structs.h:266
bpf_map_type
Definition: ebpf_structs.h:28
int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type)
Detach eBPF program(s) from an attach point.
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_object__load(struct bpf_object *obj)
Load all the programs in a given object.
struct bpf_link * bpf_program__attach(const struct bpf_program *prog)
Attach an eBPF program to a hook associated with the program's expected attach type.
bool bpf_map__is_pinned(const struct bpf_map *map)
Determine whether a map is pinned.
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.
int bpf_program__set_expected_attach_type(struct bpf_program *prog, enum bpf_attach_type type)
Set the expected attach type for an eBPF 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_program__section_name(const struct bpf_program *prog)
Gets the ELF section name of an eBPF program, if any.
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.
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__unpin(struct bpf_program *prog, const char *path)
Unpin a program.
void bpf_object__close(struct bpf_object *object)
Close an eBPF object.
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.
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.
struct bpf_object * bpf_object__open(const char *path)
Open a file without loading the programs.
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.
const char * bpf_program__name(const struct bpf_program *prog)
Get the function name of an eBPF program.
void ring_buffer__free(struct ring_buffer *rb)
Frees a new ring buffer manager.
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.
__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.
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.
int bpf_object__unpin_programs(struct bpf_object *obj, const char *path)
Unpin all programs associated with an eBPF object from a specified path.
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.
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)
Set the program type for an eBPF program.
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.
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.
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.
struct bpf_map * bpf_object__find_map_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_link__destroy(struct bpf_link *link)
Clean up a link.
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.
int libbpf_strerror(int err, char *buf, size_t size)
Get an error message.
const char * bpf_map__name(const struct bpf_map *map)
Get the name of an eBPF map.
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.
const char * bpf_object__name(const struct bpf_object *obj)
Get the name of an eBPF object.
__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.
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.
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.
struct bpf_link * bpf_program__attach_xdp(struct bpf_program *prog, int ifindex)
Attach an eBPF program to an XDP hook.
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.
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.
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.
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_program__pin(struct bpf_program *prog, const char *path)
Pin a program to a specified path.
uint32_t __u32
Definition: types.h:6