eBPF for Windows
libbpf.h File Reference
#include "libbpf_legacy.h"

Go to the source code of this file.

Functions

Link-related functions
int bpf_link__destroy (struct bpf_link *link)
 Clean up a link. More...
 
void bpf_link__disconnect (struct bpf_link *link)
 Release ownership of a link so that it is not detached when destroyed. More...
 
int bpf_link__fd (const struct bpf_link *link)
 Get a file descriptor that refers to a link. More...
 
int bpf_link__pin (struct bpf_link *link, const char *path)
 Pin a link to a specified path. More...
 
int bpf_link__unpin (struct bpf_link *link)
 Unpin a link. More...
 
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. More...
 
Map-related functions
int bpf_map__fd (const struct bpf_map *map)
 Get a file descriptor that refers to a map. More...
 
bool bpf_map__is_pinned (const struct bpf_map *map)
 Determine whether a map is pinned. More...
 
__u32 bpf_map__key_size (const struct bpf_map *map)
 Get the size of keys in a given map. More...
 
__u32 bpf_map__max_entries (const struct bpf_map *map)
 Get the maximum number of entries allowed in a given map. More...
 
const char * bpf_map__name (const struct bpf_map *map)
 Get the name of an eBPF map. More...
 
int bpf_map__pin (struct bpf_map *map, const char *path)
 Pin a map to a specified path. More...
 
enum bpf_map_type bpf_map__type (const struct bpf_map *map)
 Get the type of a map. More...
 
int bpf_map__unpin (struct bpf_map *map, const char *path)
 Unpin a map. More...
 
__u32 bpf_map__value_size (const struct bpf_map *map)
 Get the size of values in a given map. More...
 
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. More...
 
Object-related functions
void bpf_object__close (struct bpf_object *object)
 Close an eBPF object. More...
 
struct bpf_mapbpf_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. More...
 
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. More...
 
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. More...
 
int bpf_object__load (struct bpf_object *obj)
 Load all the programs in a given object. More...
 
const char * bpf_object__name (const struct bpf_object *obj)
 Get the name of an eBPF object. More...
 
struct bpf_mapbpf_object__next_map (const struct bpf_object *obj, const struct bpf_map *map)
 Get the next map for a given eBPF object. More...
 
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. More...
 
struct bpf_object * bpf_object__open (const char *path)
 Open a file without loading the programs. More...
 
struct bpf_object * bpf_object__open_file (const char *path, const struct bpf_object_open_opts *opts)
 Open a file without loading the programs. More...
 
int bpf_object__pin (struct bpf_object *object, const char *path)
 Pin an eBPF object to a specified path. More...
 
int bpf_object__pin_maps (struct bpf_object *obj, const char *path)
 Pin all maps associated with an eBPF object to a specified path. More...
 
int bpf_object__pin_programs (struct bpf_object *obj, const char *path)
 Pin all programs associated with an eBPF object to a specified path. More...
 
struct bpf_mapbpf_object__prev_map (const struct bpf_object *obj, const struct bpf_map *map)
 Get the previous map for a given eBPF object. More...
 
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. More...
 
int bpf_object__unpin_maps (struct bpf_object *obj, const char *path)
 Unpin all maps associated with an eBPF object from a specified path. More...
 
int bpf_object__unpin_programs (struct bpf_object *obj, const char *path)
 Unpin all programs associated with an eBPF object from a specified path. More...
 
Program-related functions
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. More...
 
struct bpf_link * bpf_program__attach_xdp (struct bpf_program *prog, int ifindex)
 Attach an eBPF program to an XDP hook. More...
 
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. More...
 
int bpf_prog_detach (int attachable_fd, enum bpf_attach_type type)
 Detach eBPF program(s) from an attach point. More...
 
int bpf_prog_detach2 (int prog_fd, int attachable_fd, enum bpf_attach_type type)
 Detach an eBPF program from an attach point. More...
 
int bpf_program__fd (const struct bpf_program *prog)
 Get a file descriptor that refers to a program. More...
 
enum bpf_attach_type bpf_program__get_expected_attach_type (const struct bpf_program *prog)
 Get the expected attach type for an eBPF program. More...
 
enum bpf_prog_type bpf_program__get_type (const struct bpf_program *prog)
 Get the program type for an eBPF program. More...
 
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. More...
 
const char * bpf_program__name (const struct bpf_program *prog)
 Get the function name of an eBPF program. More...
 
int bpf_program__pin (struct bpf_program *prog, const char *path)
 Pin a program to a specified path. More...
 
const char * bpf_program__section_name (const struct bpf_program *prog)
 Gets the ELF section name of an eBPF program, if any. More...
 
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. More...
 
int bpf_program__set_type (struct bpf_program *prog, enum bpf_prog_type type)
 Set the program type for an eBPF program. More...
 
enum bpf_prog_type bpf_program__type (const struct bpf_program *prog)
 Get the program type for an eBPF program. More...
 
void bpf_program__unload (struct bpf_program *prog)
 Unload a program. More...
 
int bpf_program__unpin (struct bpf_program *prog, const char *path)
 Unpin a program. More...
 
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. More...
 
int bpf_xdp_detach (int ifindex, __u32 flags, const struct bpf_xdp_attach_opts *opts)
 Detach an XDP program from a given interface. More...
 
int bpf_xdp_query_id (int ifindex, int flags, __u32 *prog_id)
 Get the XDP program id attached to a given interface index. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
System-related functions
long libbpf_get_error (const void *ptr)
 Get a negative error code based on errno and a possibly null pointer. More...
 
int libbpf_strerror (int err, char *buf, size_t size)
 Get an error message. More...
 
int libbpf_num_possible_cpus (void)
 Get the number of processors on the current system. More...
 
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. More...
 
void ring_buffer__free (struct ring_buffer *rb)
 Frees a new ring buffer manager. More...
 

Function Documentation

◆ bpf_link__destroy()

int bpf_link__destroy ( struct bpf_link *  link)

Clean up a link.

Unless bpf_link__disconnect was called first, this API detaches the link. Either way, it then closes the link fd and frees the memory for the link.

Parameters
[in]linkLink to destroy.
See also
bpf_link_detach
ebpf_link_close

◆ bpf_link__disconnect()

void bpf_link__disconnect ( struct bpf_link *  link)

Release ownership of a link so that it is not detached when destroyed.

Parameters
[in]linkLink to disconnect.
See also
bpf_link__destroy

◆ bpf_link__fd()

int bpf_link__fd ( const struct bpf_link *  link)

Get a file descriptor that refers to a link.

Parameters
[in]linkLink to get a file descriptor for.
Returns
File descriptor that refers to the link. The caller should not call _close() on the fd.

◆ bpf_link__pin()

int bpf_link__pin ( struct bpf_link *  link,
const char *  path 
)

Pin a link to a specified path.

Parameters
[in]linkLink to pin.
[in]pathPath to pin the link to.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EBUSYA pin path was previously specified.
EEXISTSomething is already pinned to the specified path.
EINVALAn invalid argument was provided.
ENOMEMOut of memory.
See also
bpf_link__unpin

◆ bpf_link__unpin()

int bpf_link__unpin ( struct bpf_link *  link)

Unpin a link.

Parameters
[in]linkLink to unpin.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EINVALAn invalid argument was provided.
ENOENTThe link was not pinned.
See also
bpf_link__pin

◆ bpf_map__fd()

int bpf_map__fd ( const struct bpf_map map)

Get a file descriptor that refers to a map.

Parameters
[in]mapMap to get a file descriptor for.
Returns
File descriptor that refers to the map. The caller should not call _close() on the fd.

◆ bpf_map__is_pinned()

bool bpf_map__is_pinned ( const struct bpf_map map)

Determine whether a map is pinned.

Parameters
[in]mapMap to check.
Return values
trueThe map is pinned.
falseThe map is not pinned.
See also
bpf_map__pin
bpf_object__pin
bpf_object__pin_maps

◆ bpf_map__key_size()

__u32 bpf_map__key_size ( const struct bpf_map map)

Get the size of keys in a given map.

Parameters
[in]mapMap to check.
Returns
The size in bytes of keys in the map.

◆ bpf_map__max_entries()

__u32 bpf_map__max_entries ( const struct bpf_map map)

Get the maximum number of entries allowed in a given map.

Parameters
[in]mapMap to check.
Returns
The maximum number of entries allowed.

◆ bpf_map__name()

const char* bpf_map__name ( const struct bpf_map map)

Get the name of an eBPF map.

Parameters
[in]mapThe map to check.
Returns
The name of the map, or NULL if none.

◆ bpf_map__pin()

int bpf_map__pin ( struct bpf_map map,
const char *  path 
)

Pin a map to a specified path.

Parameters
[in]mapMap to pin.
[in]pathPath to pin the map to.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EBUSYA pin path was previously specified.
EEXISTSomething is already pinned to the specified path.
EINVALAn invalid argument was provided.
ENOMEMOut of memory.
See also
bpf_map_unpin
bpf_object__pin_maps

◆ bpf_map__type()

enum bpf_map_type bpf_map__type ( const struct bpf_map map)

Get the type of a map.

Parameters
[in]mapMap to check.
Returns
The map type.

◆ bpf_map__unpin()

int bpf_map__unpin ( struct bpf_map map,
const char *  path 
)

Unpin a map.

Parameters
[in]mapMap to unpin.
[in]pathPath from which to unpin the map.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EINVALAn invalid argument was provided.
ENOENTThe map was not pinned.
See also
bpf_map_pin
bpf_object__unpin_maps

◆ bpf_map__value_size()

__u32 bpf_map__value_size ( const struct bpf_map map)

Get the size of values in a given map.

Parameters
[in]mapMap to check.
Returns
The size in bytes of values in the map.

◆ bpf_object__close()

void bpf_object__close ( struct bpf_object *  object)

Close an eBPF object.

Parameters
[in]objectThe object to close.
See also
bpf_prog_load

◆ bpf_object__find_map_by_name()

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.

Parameters
[in]objThe object to check.
[in]nameThe name to look for.
Returns
The map found, or NULL if none.

◆ bpf_object__find_map_fd_by_name()

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.

Parameters
[in]objThe object to check.
[in]nameThe name to look for.
Returns
A file descriptor referring to the map found, or a negative value if none. The caller should not call _close() on the fd.
See also
bpf_map__fd

◆ bpf_object__find_program_by_name()

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.

Parameters
[in]objThe object to check.
[in]nameThe name to look for.
Returns
The program found, or NULL if none.
See also
bpf_program__name

◆ bpf_object__load()

int bpf_object__load ( struct bpf_object *  obj)

Load all the programs in a given object.

Parameters
[in]objObject from which to load programs.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EINVALAn invalid argument was provided.
ENOMEMOut of memory.
See also
bpf_object__load_xattr
bpf_object__open
bpf_object__unload
bpf_prog_load

◆ bpf_object__name()

const char* bpf_object__name ( const struct bpf_object *  obj)

Get the name of an eBPF object.

Parameters
[in]objThe object to check.
Returns
The name of the object, or NULL if none.

◆ bpf_object__next_map()

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.

Parameters
[in]objObject with maps.
[in]mapPrevious map.
Returns
Next map, or NULL if none.
See also
bpf_object__prev_map

◆ bpf_object__next_program()

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.

Parameters
[in]objObject with programs.
[in]progPrevious program, or NULL to get the first program.
Returns
Next program, or NULL if none.
See also
bpf_object__prev_program

◆ bpf_object__open()

struct bpf_object* bpf_object__open ( const char *  path)

Open a file without loading the programs.

Parameters
[in]pathFile name to open.
Returns
Pointer to an eBPF object, or NULL on failure.

◆ bpf_object__open_file()

struct bpf_object* bpf_object__open_file ( const char *  path,
const struct bpf_object_open_opts *  opts 
)

Open a file without loading the programs.

Parameters
[in]pathFile name to open.
[opts]opts Options to use when opening the object, or NULL pointer for default.
Returns
Pointer to an eBPF object, or NULL on failure.

◆ bpf_object__pin()

int bpf_object__pin ( struct bpf_object *  object,
const char *  path 
)

Pin an eBPF object to a specified path.

Parameters
[in]objectObject to pin.
[in]pathPath to pin the object to.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EBUSYSomething is already pinned to the specified path.
EINVALAn invalid argument was provided.
ENOMEMOut of memory.
See also
bpf_object__pin_maps
bpf_object__pin_programs
bpf_object__unpin_maps
bpf_object__unpin_programs

◆ bpf_object__pin_maps()

int bpf_object__pin_maps ( struct bpf_object *  obj,
const char *  path 
)

Pin all maps associated with an eBPF object to a specified path.

Parameters
[in]objObject to pin maps of.
[in]pathPath to pin the maps to.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EBUSYSomething is already pinned to the specified path.
EINVALAn invalid argument was provided.
ENOMEMOut of memory.
See also
bpf_map__pin
bpf_object__pin
bpf_object__unpin_maps

◆ bpf_object__pin_programs()

int bpf_object__pin_programs ( struct bpf_object *  obj,
const char *  path 
)

Pin all programs associated with an eBPF object to a specified path.

Parameters
[in]objObject to pin programs of.
[in]pathPath to pin the programs to.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EBUSYSomething is already pinned to the specified path.
EINVALAn invalid argument was provided.
ENOMEMOut of memory.
See also
bpf_program__pin
bpf_object__pin
bpf_object__unpin_programs

◆ bpf_object__prev_map()

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.

Parameters
[in]objObject with maps.
[in]mapNext map.
Returns
Previous map, or NULL if none.
See also
bpf_object__next_map

◆ bpf_object__prev_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.

Parameters
[in]objObject with programs.
[in]progNext program.
Returns
Previous eBPF program, or NULL if none.
See also
bpf_object__next_program

◆ bpf_object__unpin_maps()

int bpf_object__unpin_maps ( struct bpf_object *  obj,
const char *  path 
)

Unpin all maps associated with an eBPF object from a specified path.

Parameters
[in]objObject to unpin maps of.
[in]pathPath from which to unpin the maps.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EINVALAn invalid argument was provided.
See also
bpf_map__unpin
bpf_object__pin_maps
bpf_object__unpin

◆ bpf_object__unpin_programs()

int bpf_object__unpin_programs ( struct bpf_object *  obj,
const char *  path 
)

Unpin all programs associated with an eBPF object from a specified path.

Parameters
[in]objObject to unpin programs of.
[in]pathPath from which to unpin the programs.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EINVALAn invalid argument was provided.
See also
bpf_program__unpin
bpf_object__pin_programs
bpf_object__unpin

◆ bpf_prog_attach()

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.

Parameters
[in]prog_fdFile descriptor of the program to attach.
[in]attachable_fdFile descriptor corresponding to the attach point.
[in]typeAttach type.
[in]flagsFlags (currently 0).
Return values
0The operation was successful.
<0An error occured, and errno was set.

◆ bpf_prog_detach()

int bpf_prog_detach ( int  attachable_fd,
enum bpf_attach_type  type 
)

Detach eBPF program(s) from an attach point.

Parameters
[in]attachable_fdFile descriptor corresponding to the attach point.
[in]typeAttach type.
Return values
0The operation was successful.
<0An error occured, and errno was set.

◆ bpf_prog_detach2()

int bpf_prog_detach2 ( int  prog_fd,
int  attachable_fd,
enum bpf_attach_type  type 
)

Detach an eBPF program from an attach point.

Parameters
[in]prog_fdFile descriptor of the program to detach.
[in]attachable_fdFile descriptor corresponding to the attach point.
[in]typeAttach type.
Return values
0The operation was successful.
<0An error occured, and errno was set.

◆ bpf_program__attach()

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.

Parameters
[in]progThe program to attach.
Returns
The link created. On error, returns NULL and sets errno.
See also
bpf_link__destroy
bpf_program__get_expected_attach_type
bpf_program__set_expected_attach_type
ebpf_link_close

◆ bpf_program__attach_xdp()

struct bpf_link* bpf_program__attach_xdp ( struct bpf_program *  prog,
int  ifindex 
)

Attach an eBPF program to an XDP hook.

Parameters
[in]progThe program to attach.
[in]ifindexThe interface index to attach to.
Returns
The link created. On error, returns NULL and sets errno.
See also
bpf_link__destroy
bpf_program__attach
ebpf_link_close

◆ bpf_program__fd()

int bpf_program__fd ( const struct bpf_program *  prog)

Get a file descriptor that refers to a program.

Parameters
[in]progProgram to get a file descriptor for.
Returns
File descriptor that refers to the program. The caller should not call _close() on the fd.

◆ bpf_program__get_expected_attach_type()

enum bpf_attach_type bpf_program__get_expected_attach_type ( const struct bpf_program *  prog)

Get the expected attach type for an eBPF program.

Parameters
[in]progProgram to check.
Returns
Expected attach type.
See also
bpf_program__attach
bpf_program__set_expected_attach_type

◆ bpf_program__get_type()

enum bpf_prog_type bpf_program__get_type ( const struct bpf_program *  prog)

Get the program type for an eBPF program.

Parameters
[in]progProgram to check.
Returns
Program type.
Deprecated:
Use bpf_program__type() instead.
See also
bpf_program__get_expected_attach_type
bpf_program__type

◆ bpf_program__insn_cnt()

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.

Parameters
[in]progBPF program for which to return number of BPF instructions
Returns
Number of instructions.

◆ bpf_program__name()

const char* bpf_program__name ( const struct bpf_program *  prog)

Get the function name of an eBPF program.

Parameters
[in]progProgram to check.
Returns
The name of the program, which is the name of the main function called when invoked.
See also
bpf_object__find_program_by_name

◆ bpf_program__pin()

int bpf_program__pin ( struct bpf_program *  prog,
const char *  path 
)

Pin a program to a specified path.

Parameters
[in]progProgram to pin.
[in]pathPath to pin the program to.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EBUSYA pin path was previously specified.
EEXISTSomething is already pinned to the specified path.
EINVALAn invalid argument was provided.
ENOMEMOut of memory.
See also
bpf_object__pin
bpf_object__pin_programs
bpf_program__unpin

◆ bpf_program__section_name()

const char* bpf_program__section_name ( const struct bpf_program *  prog)

Gets the ELF section name of an eBPF program, if any.

Parameters
[in]progAn eBPF program.
Returns
The ELF section name of an eBPF program, or NULL if none.

◆ bpf_program__set_expected_attach_type()

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.

Parameters
[in]progProgram to update.
[in]typeAttach type to set.
See also
bpf_program__attach
bpf_program__get_expected_attach_type
Return values
0The operation was successful.
<0An error occured, and errno was set.

◆ bpf_program__set_type()

int bpf_program__set_type ( struct bpf_program *  prog,
enum bpf_prog_type  type 
)

Set the program type for an eBPF program.

Parameters
[in]progProgram to update.
[in]typeProgram type to set.
See also
bpf_program__set_expected_attach_type
bpf_program__type
Return values
0The operation was successful.
<0An error occured, and errno was set.

◆ bpf_program__type()

enum bpf_prog_type bpf_program__type ( const struct bpf_program *  prog)

Get the program type for an eBPF program.

Parameters
[in]progProgram to check.
Returns
Program type.
See also
bpf_program__get_expected_attach_type

◆ bpf_program__unload()

void bpf_program__unload ( struct bpf_program *  prog)

Unload a program.

Parameters
[in]progProgram to unload.
See also
bpf_object__unload
bpf_prog_load

◆ bpf_program__unpin()

int bpf_program__unpin ( struct bpf_program *  prog,
const char *  path 
)

Unpin a program.

Parameters
[in]progProgram to unpin.
[in]pathPath from which to unpin the program.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EINVALAn invalid argument was provided.
ENOENTThe program was not pinned.
See also
bpf_object__unpin_programs
bpf_program__pin

◆ bpf_xdp_attach()

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.

Parameters
[in]ifindexThe interface index to attach to, or -1 to detach.
[in]prog_fdFile descriptor of program to attach.
[in]flagsFlags. Use XDP_FLAGS_REPLACE to replace any program previously attached to the specified interface index.
[in]optsOptions (currently unused).
Return values
0The operation was successful.
<0An error occured, and errno was set.
See also
bpf_program__attach_xdp
bpf_xdp_detach

◆ bpf_xdp_detach()

int bpf_xdp_detach ( int  ifindex,
__u32  flags,
const struct bpf_xdp_attach_opts *  opts 
)

Detach an XDP program from a given interface.

Parameters
[in]ifindexThe interface index to detach from.
[in]prog_fdFile descriptor of program to detach.
[in]flagsFlags. Use XDP_FLAGS_REPLACE to detach any program previously attached to the specified interface index.
[in]optsOptions (currently unused).
Return values
0The operation was successful.
<0An error occured, and errno was set.
See also
bpf_link_detach
bpf_program__attach_xdp
bpf_xdp_attach

◆ bpf_xdp_query_id()

int bpf_xdp_query_id ( int  ifindex,
int  flags,
__u32 prog_id 
)

Get the XDP program id attached to a given interface index.

Parameters
[in]ifindexThe interface index to query.
[in]flagsFlags (currently 0).
[out]prog_idThe ID of the program attached.
Return values
0The operation was successful.
<0An error occured, and errno was set.
See also
bpf_xdp_attach

◆ libbpf_attach_type_by_name()

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.

Parameters
[in]nameThe textual representation of an attach type.
[out]attach_typeReturns the attach type.
Return values
0The operation was successful.
<0An error occured, and errno was set.

◆ libbpf_bpf_attach_type_str()

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.

Parameters
[in]tThe attach type.
Returns
Pointer to a static string identifying the attach type. NULL is returned for unknown bpf_attach_type values.

◆ libbpf_bpf_link_type_str()

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.

Parameters
[in]tThe link type.
Returns
Pointer to a static string identifying the link type. NULL is returned for unknown bpf_link_type values.

◆ libbpf_bpf_map_type_str()

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.

Parameters
[in]tThe map type.
Returns
Pointer to a static string identifying the map type. NULL is returned for unknown bpf_map_type values.

◆ libbpf_bpf_prog_type_str()

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.

Parameters
[in]tThe program type.
Returns
Pointer to a static string identifying the program type. NULL is returned for unknown bpf_prog_type values.

◆ libbpf_get_error()

long libbpf_get_error ( const void *  ptr)

Get a negative error code based on errno and a possibly null pointer.

Parameters
[in]ptrPointer that may be NULL.
Returns
Negative error code.

◆ libbpf_num_possible_cpus()

int libbpf_num_possible_cpus ( void  )

Get the number of processors on the current system.

Returns
Number of processors.

◆ libbpf_prog_type_by_name()

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.

Parameters
[in]nameName, as if it were a section name in an ELF file.
[out]prog_typeProgram type.
[out]expected_attach_typeExpected attach type.
Return values
0The operation was successful.
<0An error occured, and errno was set.

◆ libbpf_strerror()

int libbpf_strerror ( int  err,
char *  buf,
size_t  size 
)

Get an error message.

Parameters
[in]errError number.
[out]bufPointer to buffer to write message into.
[in]sizeSize of output buffer.
Return values
0The operation was successful.
<0An error occured, and errno was set.

◆ ring_buffer__free()

void ring_buffer__free ( struct ring_buffer *  rb)

Frees a new ring buffer manager.

Parameters
[in]rbPointer to ring buffer to be freed.

◆ ring_buffer__new()

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.

Parameters
[in]map_fdFile descriptor to ring buffer map.
[in]sample_cbPointer to ring buffer notification callback function.
[in]ctxPointer to sample_cb callback function.
[in]optsRing buffer options.
Returns
Pointer to ring buffer manager.