eBPF for Windows
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 
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 
253 struct bpf_map*
254 bpf_object__find_map_by_name(const struct bpf_object* obj, const char* name);
255 
267 int
268 bpf_object__find_map_fd_by_name(const struct bpf_object* obj, const char* name);
269 
280 struct bpf_program*
281 bpf_object__find_program_by_name(const struct bpf_object* obj, const char* name);
282 
299 int
300 bpf_object__load(struct bpf_object* obj);
301 
309 const char*
310 bpf_object__name(const struct bpf_object* obj);
311 
322 struct bpf_map*
323 bpf_object__next_map(const struct bpf_object* obj, const struct bpf_map* map);
324 
335 struct bpf_program*
336 bpf_object__next_program(const struct bpf_object* obj, struct bpf_program* prog);
337 
345 struct bpf_object*
346 bpf_object__open(const char* path);
347 
356 struct bpf_object*
357 bpf_object__open_file(const char* path, const struct bpf_object_open_opts* opts);
358 
377 int
378 bpf_object__pin(struct bpf_object* object, const char* path);
379 
397 int
398 bpf_object__pin_maps(struct bpf_object* obj, const char* path);
399 
417 int
418 bpf_object__pin_programs(struct bpf_object* obj, const char* path);
419 
430 struct bpf_map*
431 bpf_object__prev_map(const struct bpf_object* obj, const struct bpf_map* map);
432 
443 struct bpf_program*
444 bpf_object__prev_program(const struct bpf_object* obj, struct bpf_program* prog);
445 
461 int
462 bpf_object__unpin_maps(struct bpf_object* obj, const char* path);
463 
479 int
480 bpf_object__unpin_programs(struct bpf_object* obj, const char* path);
481 
501 struct bpf_link*
502 bpf_program__attach(const struct bpf_program* prog);
503 
516 struct bpf_link*
517 bpf_program__attach_xdp(struct bpf_program* prog, int ifindex);
518 
530 bool
531 bpf_program__autoload(const struct bpf_program* prog);
532 
545 int
546 bpf_program__set_autoload(struct bpf_program* prog, bool autoload);
547 
560 int
561 bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type, unsigned int flags);
562 
573 int
574 bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
575 
587 int
588 bpf_prog_detach2(int prog_fd, int attachable_fd, enum bpf_attach_type type);
589 
598 int
599 bpf_program__fd(const struct bpf_program* prog);
600 
611 enum bpf_attach_type
612 bpf_program__get_expected_attach_type(const struct bpf_program* prog);
613 
626 enum bpf_prog_type
627 bpf_program__get_type(const struct bpf_program* prog);
628 
637 size_t
638 bpf_program__insn_cnt(const struct bpf_program* prog);
639 
650 const char*
651 bpf_program__name(const struct bpf_program* prog);
652 
671 int
672 bpf_program__pin(struct bpf_program* prog, const char* path);
673 
681 const char*
682 bpf_program__section_name(const struct bpf_program* prog);
683 
696 int
697 bpf_program__set_expected_attach_type(struct bpf_program* prog, enum bpf_attach_type type);
698 
711 int
712 bpf_program__set_type(struct bpf_program* prog, enum bpf_prog_type type);
713 
723 enum bpf_prog_type
724 bpf_program__type(const struct bpf_program* prog);
725 
734 void
735 bpf_program__unload(struct bpf_program* prog);
736 
752 int
753 bpf_program__unpin(struct bpf_program* prog, const char* path);
754 
770 int
771 bpf_xdp_attach(int ifindex, int prog_fd, __u32 flags, const struct bpf_xdp_attach_opts* opts);
772 
789 int
790 bpf_xdp_detach(int ifindex, __u32 flags, const struct bpf_xdp_attach_opts* opts);
791 
804 int
805 bpf_xdp_query_id(int ifindex, int flags, __u32* prog_id);
806 
817 int
818 libbpf_attach_type_by_name(const char* name, enum bpf_attach_type* attach_type);
819 
829 const char*
831 
841 const char*
843 
854 int
855 libbpf_prog_type_by_name(const char* name, enum bpf_prog_type* prog_type, enum bpf_attach_type* expected_attach_type);
856 
871 long
872 libbpf_get_error(const void* ptr);
873 
884 int
885 libbpf_strerror(int err, char* buf, size_t size);
886 
892 int
894 
895 /* Ring buffer APIs */
896 
907 struct ring_buffer*
908 ring_buffer__new(int map_fd, ring_buffer_sample_fn sample_cb, void* ctx, const struct ring_buffer_opts* opts);
909 
916 void
917 ring_buffer__free(struct ring_buffer* rb);
920 #else
921 #pragma warning(push)
922 #pragma warning(disable : 4200) // Zero-sized array in struct/union
923 #pragma warning(disable : 4201) // Zero-sized array in struct/union
924 #include "libbpf/src/libbpf.h"
925 #pragma warning(pop)
926 #endif
927 #include "libbpf_legacy.h"
#define bpf_map
Definition: bpf_helpers_platform.h:16
bpf_prog_type
Definition: ebpf_structs.h:171
bpf_link_type
Definition: ebpf_structs.h:247
bpf_attach_type
Definition: ebpf_structs.h:261
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.
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_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.
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.
bool bpf_program__autoload(const struct bpf_program *prog)
Get whether an eBPF program will be loaded when the object is loaded.
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