libbpf_rs

Type Alias OpenProgram

Source
pub type OpenProgram<'obj> = OpenProgramImpl<'obj>;
Expand description

An immutable parsed but not yet loaded BPF program.

Aliased Type§

struct OpenProgram<'obj> { /* private fields */ }

Implementations§

Source§

impl<'obj> OpenProgram<'obj>

Source

pub fn new(prog: &'obj bpf_program) -> Self

Create a new OpenProgram from a ptr to a libbpf_sys::bpf_program.

Source

pub fn prog_type(&self) -> ProgramType

The ProgramType of this OpenProgram.

Source

pub fn name(&self) -> &OsStr

Retrieve the name of this OpenProgram.

Source

pub fn section(&self) -> &OsStr

Retrieve the name of the section this OpenProgram belongs to.

Source

pub fn insn_cnt(&self) -> usize

Returns the number of instructions that form the program.

Note: Keep in mind, libbpf can modify the program’s instructions and consequently its instruction count, as it processes the BPF object file. So OpenProgram::insn_cnt and Program::insn_cnt may return different values.

Source

pub fn insns(&self) -> &[bpf_insn]

Gives read-only access to BPF program’s underlying BPF instructions.

Keep in mind, libbpf can modify and append/delete BPF program’s instructions as it processes BPF object file and prepares everything for uploading into the kernel. So OpenProgram::insns and Program::insns may return different sets of instructions. As an example, during BPF object load phase BPF program instructions will be CO-RE-relocated, BPF subprograms instructions will be appended, ldimm64 instructions will have FDs embedded, etc. So instructions returned before load and after it might be quite different.