eBPF for Windows
bpf.h File Reference

Go to the source code of this file.

Functions

Link-related functions
int bpf_link_detach (int link_fd)
 Detach a link. More...
 
int bpf_link_get_fd_by_id (__u32 id)
 Get a file descriptor referring to a link with a given ID. More...
 
int bpf_link_get_next_id (__u32 start_id, __u32 *next_id)
 Look for the next link ID greater than a given ID. More...
 
Map-related functions
int bpf_map_create (enum bpf_map_type map_type, const char *map_name, __u32 key_size, __u32 value_size, __u32 max_entries, const struct bpf_map_create_opts *opts)
 Create a new map. More...
 
int bpf_map_delete_elem (int fd, const void *key)
 Look up and delete an element by key in a specified map. More...
 
int bpf_map_get_fd_by_id (__u32 id)
 Get a file descriptor referring to a map with a given ID. More...
 
int bpf_map_get_next_id (__u32 start_id, __u32 *next_id)
 Look for the next map ID greater than a given ID. More...
 
int bpf_map_get_next_key (int fd, const void *key, void *next_key)
 Look up an element by key in a map and get the next key. If the specific key is not found, the first key in the map is passed back. More...
 
int bpf_map_lookup_elem (int fd, const void *key, void *value)
 Look up an element by key in a specified map and return its value. More...
 
int bpf_map_update_elem (int fd, const void *key, const void *value, __u64 flags)
 Create or update an element (key/value pair) in a specified map. More...
 
Object-related functions
int bpf_obj_get (const char *pathname)
 Get a file descriptor for a pinned object by pin path. More...
 
int bpf_obj_get_info_by_fd (int bpf_fd, void *info, __u32 *info_len)
 Obtain information about the eBPF object referred to by bpf_fd. This function populates up to info_len bytes of info, which will be in one of the following formats depending on the eBPF object type of bpf_fd: More...
 
int bpf_obj_pin (int fd, const char *pathname)
 Pin an eBPF program or map referred to by fd to the provided pathname. More...
 
Program-related functions
int bpf_prog_bind_map (int prog_fd, int map_fd, const struct bpf_prog_bind_opts *opts)
 Bind a map to a program so that it holds a reference on the map. More...
 
int bpf_prog_get_fd_by_id (__u32 id)
 Get a file descriptor referring to a program with a given ID. More...
 
int bpf_prog_get_next_id (__u32 start_id, __u32 *next_id)
 Look for the next program ID greater than a given ID. More...
 
int bpf_prog_load (enum bpf_prog_type prog_type, const char *prog_name, const char *license, const struct bpf_insn *insns, size_t insn_cnt, const struct bpf_prog_load_opts *opts)
 Load (but do not attach) an eBPF programs. More...
 

Function Documentation

◆ bpf_link_detach()

int bpf_link_detach ( int  link_fd)

Detach a link.

Parameters
[in]link_fdFile descriptor of link to detach.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EBADFThe file descriptor was not found.
See also
bpf_link__destroy
bpf_link__disconnect

◆ bpf_link_get_fd_by_id()

int bpf_link_get_fd_by_id ( __u32  id)

Get a file descriptor referring to a link with a given ID.

Parameters
[in]idID of link to find.
Returns
A new file descriptor that refers to the link. The caller should call _close() on the fd to close this when done. A negative value indicates an error occurred and errno was set.
Exceptions
ENOENTNo link with the specified ID was found.

◆ bpf_link_get_next_id()

int bpf_link_get_next_id ( __u32  start_id,
__u32 next_id 
)

Look for the next link ID greater than a given ID.

Parameters
[in]start_idID to look for an ID after. The start_id need not exist.
[out]next_idPointer to where to write the next ID.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
ENOENTNo more IDs found.

◆ bpf_map_create()

int bpf_map_create ( enum bpf_map_type  map_type,
const char *  map_name,
__u32  key_size,
__u32  value_size,
__u32  max_entries,
const struct bpf_map_create_opts *  opts 
)

Create a new map.

Parameters
[in]map_typeType of outer map to create.
[in]map_nameOptionally, the name to use for the map.
[in]key_sizeSize in bytes of keys.
[in]value_sizeSize in bytes of values.
[in]max_entriesMaximum number of entries in the map.
[in]optsStructure of options using which a map gets created.
Returns
A new file descriptor that refers to the map. The caller should call _close() on the fd to close this when done. A negative value indicates an error occurred and errno was set.
Exceptions
EINVALAn invalid argument was provided.
ENOMEMOut of memory.

◆ bpf_map_delete_elem()

int bpf_map_delete_elem ( int  fd,
const void *  key 
)

Look up and delete an element by key in a specified map.

Parameters
[in]fdFile descriptor of map to update.
[in]keyPointer to key to look up.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EINVALAn invalid argument was provided.
EBADFThe file descriptor was not found.
ENOMEMOut of memory.

◆ bpf_map_get_fd_by_id()

int bpf_map_get_fd_by_id ( __u32  id)

Get a file descriptor referring to a map with a given ID.

Parameters
[in]idID of map to find.
Returns
A new file descriptor that refers to the map. The caller should call _close() on the fd to close this when done. A negative value indicates an error occurred and errno was set.
Exceptions
ENOENTNo map with the specified ID was found.

◆ bpf_map_get_next_id()

int bpf_map_get_next_id ( __u32  start_id,
__u32 next_id 
)

Look for the next map ID greater than a given ID.

Parameters
[in]start_idID to look for an ID after. The start_id need not exist.
[out]next_idPointer to where to write the next ID.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
ENOENTNo more IDs found.

◆ bpf_map_get_next_key()

int bpf_map_get_next_key ( int  fd,
const void *  key,
void *  next_key 
)

Look up an element by key in a map and get the next key. If the specific key is not found, the first key in the map is passed back.

Parameters
[in]fdFile descriptor of map.
[in]keyPointer to key to look up.
[out]next_keyPointer to memory in which to write the next key.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EINVALAn invalid argument was provided.
EBADFThe file descriptor was not found.
ENOMEMOut of memory.

◆ bpf_map_lookup_elem()

int bpf_map_lookup_elem ( int  fd,
const void *  key,
void *  value 
)

Look up an element by key in a specified map and return its value.

Parameters
[in]fdFile descriptor of map.
[in]keyPointer to key to look up.
[out]valuePointer to memory in which to write the value.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
EINVALAn invalid argument was provided.
EBADFThe file descriptor was not found.
ENOMEMOut of memory.

◆ bpf_map_update_elem()

int bpf_map_update_elem ( int  fd,
const void *  key,
const void *  value,
__u64  flags 
)

Create or update an element (key/value pair) in a specified map.

Parameters
[in]fdFile descriptor of map.
[in]keyPointer to key.
[in]valuePointer to value.
[in]flagsFlags (currently 0).
Exceptions
EINVALAn invalid argument was provided.
EBADFThe file descriptor was not found.
ENOMEMOut of memory.

◆ bpf_obj_get()

int bpf_obj_get ( const char *  pathname)

Get a file descriptor for a pinned object by pin path.

Parameters
[in]pathnamePin path for the object.
Returns
A new file descriptor for the pinned object. The caller should call _close() on the fd to close this when done. A negative value indicates an error occurred and errno was set.

◆ bpf_obj_get_info_by_fd()

int bpf_obj_get_info_by_fd ( int  bpf_fd,
void *  info,
__u32 info_len 
)

Obtain information about the eBPF object referred to by bpf_fd. This function populates up to info_len bytes of info, which will be in one of the following formats depending on the eBPF object type of bpf_fd:

Parameters
[in]bpf_fdFile descriptor referring to an eBPF object.
[out]infoPointer to memory in which to write the info obtained.
[in,out]info_lenOn input, contains the maximum number of bytes to write into the info. On output, contains the actual number of bytes written.
Return values
0The operation was successful.
-EFAULTA pointer passed in the input info was invalid.
<0An error occured, and errno was set.

◆ bpf_obj_pin()

int bpf_obj_pin ( int  fd,
const char *  pathname 
)

Pin an eBPF program or map referred to by fd to the provided pathname.

Parameters
[in]fdFile descriptor referring to the program or map to pin.
[in]pathnamePath name to pin the object to.
Return values
0The operation was successful.
<0An error occured, and errno was set.

◆ bpf_prog_bind_map()

int bpf_prog_bind_map ( int  prog_fd,
int  map_fd,
const struct bpf_prog_bind_opts *  opts 
)

Bind a map to a program so that it holds a reference on the map.

Parameters
[in]prog_fdFile descriptor of program to bind map to.
[in]map_fdFile descriptor of map to bind.
[in]optsOptional set of options affecting the bind operation.
Return values
0The operation was successful.
<0An error occured, and errno was set.

◆ bpf_prog_get_fd_by_id()

int bpf_prog_get_fd_by_id ( __u32  id)

Get a file descriptor referring to a program with a given ID.

Parameters
[in]idID of program to find.
Returns
A new file descriptor that refers to the program. The caller should call _close() on the fd to close this when done. A negative value indicates an error occurred and errno was set.
Exceptions
ENOENTNo program with the specified ID was found.

◆ bpf_prog_get_next_id()

int bpf_prog_get_next_id ( __u32  start_id,
__u32 next_id 
)

Look for the next program ID greater than a given ID.

Parameters
[in]start_idID to look for an ID after. The start_id need not exist.
[out]next_idPointer to where to write the next ID.
Return values
0The operation was successful.
<0An error occured, and errno was set.
Exceptions
ENOENTNo more IDs found.

◆ bpf_prog_load()

int bpf_prog_load ( enum bpf_prog_type  prog_type,
const char *  prog_name,
const char *  license,
const struct bpf_insn *  insns,
size_t  insn_cnt,
const struct bpf_prog_load_opts *  opts 
)

Load (but do not attach) an eBPF programs.

Parameters
[in]prog_typeProgram type to use for loading eBPF programs.
[in]prog_nameProgram name.
[in]licenseLicense string (unused).
[in]insnsArray of eBPF instructions.
[in]insn_cntCount of instructions in the array.
[in]optsAdditional options, or NULL to use default options.
Returns
A new file descriptor that refers to the program. The caller should call _close() on the fd to close this when done. A negative value indicates an error occurred and errno was set.
Exceptions
EACCESThe program failed verification.
EINVALOne or more parameters are incorrect.
ENOMEMOut of memory.
See also
bpf_load_program
bpf_load_program_xattr
bpf_object__close
bpf_program__attach