Skip to content

Libbpf userspace function bpf_prog_load

0.6.0

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 load
  • prog_name: name of the program
  • license: license of the program
  • insns: pointer to the program instructions
  • insn_cnt: number of instructions in the program
  • opts: 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

0.6.0

expected_attach_type

0.6.0

prog_btf_fd

0.6.0

prog_flags

0.6.0

prog_ifindex

0.6.0

kern_version

0.6.0

attach_btf_id

0.6.0

attach_prog_fd

0.6.0

attach_btf_obj_fd

0.6.0

fd_array

0.6.0

func_info

0.6.0

func_info_cnt

0.6.0

func_info_rec_size

0.6.0

line_info

0.6.0

line_info_cnt

0.6.0

line_info_rec_size

0.6.0

log_level

0.6.0

log_size

0.6.0

log_buf

0.6.0

log_true_size

1.2.0

token_fd

1.4.0

fd_array_cnt

1.6.0

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