Libbpf userspace function bpf_prog_load
Low level wrapper around the BPF_PROG_LOAD
syscall command.
Definition
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, struct bpf_prog_load_opts *opts);
Parameters
prog_type
: type of the program to loadprog_name
: name of the programlicense
: license of the programinsns
: pointer to the program instructionsinsn_cnt
: number of instructions in the programopts
: options for the program load
struct bpf_prog_load_opts
struct bpf_prog_load_opts {
size_t sz; /* size of this struct for forward/backward compatibility */
/* libbpf can retry BPF_PROG_LOAD command if bpf() syscall returns
* -EAGAIN. This field determines how many attempts libbpf has to
* make. If not specified, libbpf will use default value of 5.
*/
int attempts;
enum bpf_attach_type expected_attach_type;
__u32 prog_btf_fd;
__u32 prog_flags;
__u32 prog_ifindex;
__u32 kern_version;
__u32 attach_btf_id;
__u32 attach_prog_fd;
__u32 attach_btf_obj_fd;
const int *fd_array;
/* .BTF.ext func info data */
const void *func_info;
__u32 func_info_cnt;
__u32 func_info_rec_size;
/* .BTF.ext line info data */
const void *line_info;
__u32 line_info_cnt;
__u32 line_info_rec_size;
/* verifier log options */
__u32 log_level;
__u32 log_size;
char *log_buf;
/* output: actual total log contents size (including terminating zero).
* It could be both larger than original log_size (if log was
* truncated), or smaller (if log buffer wasn't filled completely).
* If kernel doesn't support this feature, log_size is left unchanged.
*/
__u32 log_true_size;
__u32 token_fd;
/* if set, provides the length of fd_array */
__u32 fd_array_cnt;
size_t :0;
};
attempts
expected_attach_type
prog_btf_fd
prog_flags
prog_ifindex
kern_version
attach_btf_id
attach_prog_fd
attach_btf_obj_fd
fd_array
func_info
func_info_cnt
func_info_rec_size
line_info
line_info_cnt
line_info_rec_size
log_level
log_size
log_buf
log_true_size
token_fd
fd_array_cnt
Usage
This function should only be used if you need precise control over the program loading process. For most cases, program should be loaded via bpf_object__load
or similar high level APIs instead.
Example
Docs could be improved
This part of the docs is incomplete, contributions are very welcome