Struct libbpf_rs::OpenProgram

source ·
pub struct OpenProgram { /* 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 OpenProgram

source

pub fn set_prog_type(&mut self, prog_type: ProgramType)

source

pub fn prog_type(&self) -> ProgramType

source

pub fn set_attach_type(&mut self, attach_type: ProgramAttachType)

source

pub fn set_ifindex(&mut self, idx: u32)

source

pub fn set_log_level(&mut self, log_level: u32) -> Result<()>

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.

source

pub fn section(&self) -> &str

Name of the section this OpenProgram belongs to.

source

pub fn name(&self) -> Result<&str>

The name of this OpenProgram.

source

pub fn set_autoload(&mut self, autoload: bool) -> Result<()>

Set whether a bpf program should be automatically loaded by default when the bpf object is loaded.

source

pub fn set_attach_target( &mut self, attach_prog_fd: i32, attach_func_name: Option<String>, ) -> Result<()>

source

pub fn set_flags(&self, flags: u32) -> Result<()>

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.

Trait Implementations§

source§

impl AsRawLibbpf for OpenProgram

source§

fn as_libbpf_object(&self) -> NonNull<Self::LibbpfType>

Retrieve the underlying libbpf_sys::bpf_program.

§

type LibbpfType = bpf_program

The underlying libbpf type.
source§

impl Debug for OpenProgram

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.