libbpf_rs

Struct ProgramImpl

Source
pub struct ProgramImpl<'obj, T = ()> { /* private fields */ }
Expand description

Represents a loaded Program.

This struct is not safe to clone because the underlying libbpf resource cannot currently be protected from data races.

If you attempt to attach a Program with the wrong attach method, the attach_* method will fail with the appropriate error.

Implementations§

Source§

impl<'obj> ProgramImpl<'obj>

Source

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

Source

pub fn name(&self) -> &OsStr

Retrieve the name of this Program.

Source

pub fn section(&self) -> &OsStr

Retrieve the name of the section this Program belongs to.

Source

pub fn prog_type(&self) -> ProgramType

Retrieve the type of the program.

Source

pub fn get_fd_by_id(id: u32) -> Result<OwnedFd>

👎Deprecated: renamed to Program::fd_from_id
Source

pub fn fd_from_id(id: u32) -> Result<OwnedFd>

Returns program file descriptor given a program ID.

Source

pub fn get_id_by_fd(fd: BorrowedFd<'_>) -> Result<u32>

👎Deprecated: renamed to Program::id_from_fd
Source

pub fn id_from_fd(fd: BorrowedFd<'_>) -> Result<u32>

Returns program ID given a file descriptor.

Source

pub fn fd_from_pinned_path<P: AsRef<Path>>(path: P) -> Result<OwnedFd>

Returns fd of a previously pinned program

Returns error, if the pinned path doesn’t represent an eBPF program.

Source

pub fn flags(&self) -> u32

Returns flags that have been set for the program.

Source

pub fn attach_type(&self) -> ProgramAttachType

Retrieve the attach type of the program.

Source

pub fn autoload(&self) -> bool

Return true if the bpf program is set to autoload, false otherwise.

Source

pub fn log_level(&self) -> u32

Return the bpf program’s log level.

Source

pub fn insn_cnt(&self) -> usize

Returns the number of instructions that form the program.

Please see note in OpenProgram::insn_cnt.

Source

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

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

Please see note in OpenProgram::insns.

Source§

impl<'obj> ProgramImpl<'obj, Mut>

Source

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

Source

pub fn pin<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Pin this program to bpffs.

Source

pub fn unpin<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Unpin this program from bpffs

Source

pub fn attach(&self) -> Result<Link>

Auto-attach based on prog section

Source

pub fn attach_cgroup(&self, cgroup_fd: i32) -> Result<Link>

Attach this program to a cgroup.

Source

pub fn attach_perf_event(&self, pfd: i32) -> Result<Link>

Attach this program to a perf event.

Source

pub fn attach_uprobe<T: AsRef<Path>>( &self, retprobe: bool, pid: i32, binary_path: T, func_offset: usize, ) -> Result<Link>

Attach this program to a userspace probe.

Source

pub fn attach_uprobe_with_opts( &self, pid: i32, binary_path: impl AsRef<Path>, func_offset: usize, opts: UprobeOpts, ) -> Result<Link>

Attach this program to a userspace probe, providing additional options.

Source

pub fn attach_kprobe<T: AsRef<str>>( &self, retprobe: bool, func_name: T, ) -> Result<Link>

Attach this program to a kernel probe.

Source

pub fn attach_ksyscall<T: AsRef<str>>( &self, retprobe: bool, syscall_name: T, ) -> Result<Link>

Attach this program to the specified syscall

Source

pub fn attach_tracepoint( &self, tp_category: impl AsRef<str>, tp_name: impl AsRef<str>, ) -> Result<Link>

Attach this program to a kernel tracepoint.

Source

pub fn attach_tracepoint_with_opts( &self, tp_category: impl AsRef<str>, tp_name: impl AsRef<str>, tp_opts: TracepointOpts, ) -> Result<Link>

Attach this program to a kernel tracepoint, providing additional options.

Source

pub fn attach_raw_tracepoint<T: AsRef<str>>(&self, tp_name: T) -> Result<Link>

Attach this program to a raw kernel tracepoint.

Source

pub fn attach_lsm(&self) -> Result<Link>

Attach to an LSM hook

Source

pub fn attach_trace(&self) -> Result<Link>

Source

pub fn attach_sockmap(&self, map_fd: i32) -> Result<()>

Attach a verdict/parser to a sockmap/sockhash

Source

pub fn attach_xdp(&self, ifindex: i32) -> Result<Link>

Attach this program to XDP

Source

pub fn attach_netns(&self, netns_fd: i32) -> Result<Link>

Attach this program to netns-based programs

Source

pub fn attach_netfilter_with_opts( &self, netfilter_opt: NetfilterOpts, ) -> Result<Link>

Attach this program to netfilter programs

Source

pub fn attach_usdt( &self, pid: i32, binary_path: impl AsRef<Path>, usdt_provider: impl AsRef<str>, usdt_name: impl AsRef<str>, ) -> Result<Link>

Attach this program to a USDT probe point. The entry point of the program must be defined with SEC("usdt").

Source

pub fn attach_usdt_with_opts( &self, pid: i32, binary_path: impl AsRef<Path>, usdt_provider: impl AsRef<str>, usdt_name: impl AsRef<str>, usdt_opts: UsdtOpts, ) -> Result<Link>

Attach this program to a USDT probe point, providing additional options. The entry point of the program must be defined with SEC("usdt").

Source

pub fn attach_iter(&self, map_fd: BorrowedFd<'_>) -> Result<Link>

Attach this program to a BPF Iterator. The entry point of the program must be defined with SEC("iter") or SEC("iter.s").

Source

pub fn test_run<'dat>(&self, input: Input<'dat>) -> Result<Output<'dat>>

Test run the program with the given input data.

This function uses the BPF_PROG_RUN facility.

Trait Implementations§

Source§

impl<T> AsFd for ProgramImpl<'_, T>

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl<T> AsRawLibbpf for ProgramImpl<'_, T>

Source§

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

Retrieve the underlying libbpf_sys::bpf_program.

Source§

type LibbpfType = bpf_program

The underlying libbpf type.
Source§

impl<'obj, T: Debug> Debug for ProgramImpl<'obj, T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'obj, T> Freeze for ProgramImpl<'obj, T>

§

impl<'obj, T> RefUnwindSafe for ProgramImpl<'obj, T>
where T: RefUnwindSafe,

§

impl<'obj, T = ()> !Send for ProgramImpl<'obj, T>

§

impl<'obj, T = ()> !Sync for ProgramImpl<'obj, T>

§

impl<'obj, T> Unpin for ProgramImpl<'obj, T>

§

impl<'obj, T> UnwindSafe for ProgramImpl<'obj, T>
where T: RefUnwindSafe,

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>,

Source§

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>,

Source§

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.