Struct libbpf_rs::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.

§

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

§

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.