pub struct OpenProgramImpl<'obj, T = ()> { /* private fields */ }
Expand description
Represents a parsed but not yet loaded BPF program.
This object exposes operations that need to happen before the program is loaded.
Implementations§
Source§impl<'obj> OpenProgramImpl<'obj>
impl<'obj> OpenProgramImpl<'obj>
Sourcepub fn new(prog: &'obj bpf_program) -> Self
pub fn new(prog: &'obj bpf_program) -> Self
Create a new OpenProgram
from a ptr to a libbpf_sys::bpf_program
.
Sourcepub fn prog_type(&self) -> ProgramType
pub fn prog_type(&self) -> ProgramType
The ProgramType
of this OpenProgram
.
Sourcepub fn insn_cnt(&self) -> usize
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.
Sourcepub fn insns(&self) -> &[bpf_insn]
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.
Source§impl<'obj> OpenProgramImpl<'obj, Mut>
impl<'obj> OpenProgramImpl<'obj, Mut>
Sourcepub fn new_mut(prog: &'obj mut bpf_program) -> Self
pub fn new_mut(prog: &'obj mut bpf_program) -> Self
Create a new OpenProgram
from a ptr to a libbpf_sys::bpf_program
.
Sourcepub fn set_prog_type(&mut self, prog_type: ProgramType)
pub fn set_prog_type(&mut self, prog_type: ProgramType)
Set the program type.
Sourcepub fn set_attach_type(&mut self, attach_type: ProgramAttachType)
pub fn set_attach_type(&mut self, attach_type: ProgramAttachType)
Set the attachment type of the program.
Sourcepub fn set_ifindex(&mut self, idx: u32)
pub fn set_ifindex(&mut self, idx: u32)
Bind the program to a particular network device.
Currently only used for hardware offload and certain XDP features such like HW metadata.
Sourcepub fn set_log_level(&mut self, log_level: u32)
pub fn set_log_level(&mut self, log_level: u32)
Set the log level for the bpf program.
The log level is interpreted by bpf kernel code and interpretation may change with newer kernel versions. Refer to the kernel source code for details.
In general, a value of 0
disables logging while values > 0
enables
it.
Sourcepub fn set_autoload(&mut self, autoload: bool)
pub fn set_autoload(&mut self, autoload: bool)
Set whether a bpf program should be automatically loaded by default when the bpf object is loaded.
pub fn set_attach_target( &mut self, attach_prog_fd: i32, attach_func_name: Option<String>, ) -> Result<()>
Trait Implementations§
Source§impl<T> AsRawLibbpf for OpenProgramImpl<'_, T>
impl<T> AsRawLibbpf for OpenProgramImpl<'_, T>
Source§fn as_libbpf_object(&self) -> NonNull<Self::LibbpfType>
fn as_libbpf_object(&self) -> NonNull<Self::LibbpfType>
Retrieve the underlying libbpf_sys::bpf_program
.
Source§type LibbpfType = bpf_program
type LibbpfType = bpf_program
libbpf
type.