pub struct Program { /* 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 Program
impl Program
sourcepub fn prog_type(&self) -> ProgramType
pub fn prog_type(&self) -> ProgramType
Retrieve the type of the program.
sourcepub fn get_fd_by_id(id: u32) -> Result<OwnedFd>
pub fn get_fd_by_id(id: u32) -> Result<OwnedFd>
Returns program fd by id
sourcepub fn get_id_by_fd(fd: BorrowedFd<'_>) -> Result<u32>
pub fn get_id_by_fd(fd: BorrowedFd<'_>) -> Result<u32>
Returns program id by fd
sourcepub fn attach_type(&self) -> ProgramAttachType
pub fn attach_type(&self) -> ProgramAttachType
Retrieve the attach type of the program.
sourcepub fn autoload(&self) -> bool
pub fn autoload(&self) -> bool
Return true
if the bpf program is set to autoload, false
otherwise.
sourcepub fn attach_cgroup(&mut self, cgroup_fd: i32) -> Result<Link>
pub fn attach_cgroup(&mut self, cgroup_fd: i32) -> Result<Link>
Attach this program to a cgroup.
sourcepub fn attach_perf_event(&mut self, pfd: i32) -> Result<Link>
pub fn attach_perf_event(&mut self, pfd: i32) -> Result<Link>
Attach this program to a perf event.
sourcepub fn attach_uprobe<T: AsRef<Path>>(
&mut self,
retprobe: bool,
pid: i32,
binary_path: T,
func_offset: usize,
) -> Result<Link>
pub fn attach_uprobe<T: AsRef<Path>>( &mut self, retprobe: bool, pid: i32, binary_path: T, func_offset: usize, ) -> Result<Link>
Attach this program to a userspace probe.
sourcepub fn attach_uprobe_with_opts(
&mut self,
pid: i32,
binary_path: impl AsRef<Path>,
func_offset: usize,
opts: UprobeOpts,
) -> Result<Link>
pub fn attach_uprobe_with_opts( &mut 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.
sourcepub fn attach_kprobe<T: AsRef<str>>(
&mut self,
retprobe: bool,
func_name: T,
) -> Result<Link>
pub fn attach_kprobe<T: AsRef<str>>( &mut self, retprobe: bool, func_name: T, ) -> Result<Link>
Attach this program to a kernel probe.
sourcepub fn attach_ksyscall<T: AsRef<str>>(
&mut self,
retprobe: bool,
syscall_name: T,
) -> Result<Link>
pub fn attach_ksyscall<T: AsRef<str>>( &mut self, retprobe: bool, syscall_name: T, ) -> Result<Link>
Attach this program to the specified syscall
sourcepub fn attach_tracepoint(
&mut self,
tp_category: impl AsRef<str>,
tp_name: impl AsRef<str>,
) -> Result<Link>
pub fn attach_tracepoint( &mut self, tp_category: impl AsRef<str>, tp_name: impl AsRef<str>, ) -> Result<Link>
Attach this program to a kernel tracepoint.
sourcepub fn attach_tracepoint_with_opts(
&mut self,
tp_category: impl AsRef<str>,
tp_name: impl AsRef<str>,
tp_opts: TracepointOpts,
) -> Result<Link>
pub fn attach_tracepoint_with_opts( &mut 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.
sourcepub fn attach_raw_tracepoint<T: AsRef<str>>(
&mut self,
tp_name: T,
) -> Result<Link>
pub fn attach_raw_tracepoint<T: AsRef<str>>( &mut self, tp_name: T, ) -> Result<Link>
Attach this program to a raw kernel tracepoint.
sourcepub fn attach_lsm(&mut self) -> Result<Link>
pub fn attach_lsm(&mut self) -> Result<Link>
Attach to an LSM hook
sourcepub fn attach_trace(&mut self) -> Result<Link>
pub fn attach_trace(&mut self) -> Result<Link>
Attach to a fentry/fexit kernel probe
sourcepub fn attach_sockmap(&self, map_fd: i32) -> Result<()>
pub fn attach_sockmap(&self, map_fd: i32) -> Result<()>
Attach a verdict/parser to a sockmap/sockhash
sourcepub fn attach_netns(&mut self, netns_fd: i32) -> Result<Link>
pub fn attach_netns(&mut self, netns_fd: i32) -> Result<Link>
Attach this program to netns-based programs
sourcepub fn attach_usdt(
&mut self,
pid: i32,
binary_path: impl AsRef<Path>,
usdt_provider: impl AsRef<str>,
usdt_name: impl AsRef<str>,
) -> Result<Link>
pub fn attach_usdt( &mut 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")
.
sourcepub fn attach_usdt_with_opts(
&mut self,
pid: i32,
binary_path: impl AsRef<Path>,
usdt_provider: impl AsRef<str>,
usdt_name: impl AsRef<str>,
usdt_opts: UsdtOpts,
) -> Result<Link>
pub fn attach_usdt_with_opts( &mut 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")
.
sourcepub fn attach_iter(&mut self, map_fd: BorrowedFd<'_>) -> Result<Link>
pub fn attach_iter(&mut 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")
.
sourcepub fn test_run<'dat>(&mut self, input: Input<'dat>) -> Result<Output<'dat>>
pub fn test_run<'dat>(&mut self, input: Input<'dat>) -> Result<Output<'dat>>
Test run the program with the given input data.
This function uses the BPF_PROG_RUN facility.
sourcepub fn insn_cnt(&self) -> usize
pub fn insn_cnt(&self) -> usize
Returns the number of instructions that form the program.
Please see note in OpenProgram::insn_cnt
.
sourcepub fn insns(&self) -> &[bpf_insn]
pub fn insns(&self) -> &[bpf_insn]
Gives read-only access to BPF program’s underlying BPF instructions.
Please see note in OpenProgram::insns
.
Trait Implementations§
source§impl AsFd for Program
impl AsFd for Program
source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
source§impl AsRawLibbpf for Program
impl AsRawLibbpf for Program
source§fn as_libbpf_object(&self) -> NonNull<Self::LibbpfType>
fn as_libbpf_object(&self) -> NonNull<Self::LibbpfType>
Retrieve the underlying libbpf_sys::bpf_program
.
§type LibbpfType = bpf_program
type LibbpfType = bpf_program
libbpf
type.