libbpf_rs

Struct Link

Source
pub struct Link { /* private fields */ }
Expand description

Represents an attached Program.

This struct is used to model ownership. The underlying program will be detached when this object is dropped if nothing else is holding a reference count.

Implementations§

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Create link from BPF FS file.

Source

pub unsafe fn from_ptr(ptr: NonNull<bpf_link>) -> Self

Takes ownership from pointer.

§Safety

It is not safe to manipulate ptr after this operation.

Source

pub fn update_prog(&mut self, prog: &Program<'_>) -> Result<()>

Replace the underlying prog with prog.

Source

pub fn disconnect(&mut self)

Release “ownership” of underlying BPF resource (typically, a BPF program attached to some BPF hook, e.g., tracepoint, kprobe, etc). Disconnected links, when destructed through bpf_link__destroy() call won’t attempt to detach/unregistered that BPF resource. This is useful in situations where, say, attached BPF program has to outlive userspace program that attached it in the system. Depending on type of BPF program, though, there might be additional steps (like pinning BPF program in BPF FS) necessary to ensure exit of userspace program doesn’t trigger automatic detachment and clean up inside the kernel.

Source

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

Pin this link to bpffs.

Source

pub fn unpin(&mut self) -> Result<()>

Unpin from bpffs

Source

pub fn pin_path(&self) -> Option<PathBuf>

Returns path to BPF FS file or None if not pinned.

Source

pub fn detach(&self) -> Result<()>

Detach the link.

Trait Implementations§

Source§

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

Borrows the file descriptor. Read more
Source§

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

Retrieve the underlying libbpf_sys::bpf_link.

Source§

type LibbpfType = bpf_link

The underlying libbpf type.
Source§

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

Formats the value using the given formatter. Read more
Source§

fn drop(&mut self)

Executes the destructor for this type. 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>,

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.