Skip to content

Libbpf userspace function bpf_prog_attach_opts

0.0.8

Low level wrapper around the BPF_PROG_ATTACH syscall command.

Definition

int bpf_prog_attach_opts(int prog_fd, int target, enum bpf_attach_type type, const struct bpf_prog_attach_opts *opts);

Parameters

  • prog_fd: BPF program file descriptor
  • target: attach location file descriptor or ifindex
  • type: attach type for the BPF program
  • opts: options for configuring the attachment

struct bpf_prog_attach_opts

struct bpf_prog_attach_opts {
    size_t sz; /* size of this struct for forward/backward compatibility */
    __u32 flags;
    union {
        int replace_prog_fd;
        int replace_fd;
    };
    int relative_fd;
    __u32 relative_id;
    __u64 expected_revision;
    size_t :0;
};

flags

0.0.8

replace_prog_fd

0.0.8

replace_fd

1.3.0

relative_fd

1.3.0

relative_id

1.3.0

expected_revision

1.3.0

Return

0, on success; negative error code, otherwise (errno is also set to the error code)

Usage

Attaches the BPF program corresponding to prog_fd to a target which can represent a file descriptor or netdevice ifindex.

This function should only be used for specific program types that need to be attached via the BPF_PROG_ATTACH syscall command and you need specific control over this process. In most cases, the bpf_program__attach or specific bpf_program__attach_* functions should be used instead.

Example

Docs could be improved

This part of the docs is incomplete, contributions are very welcome