Ebpf

Struct Ebpf 

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

The main entry point into the library, used to work with eBPF programs and maps.

Implementations§

Source§

impl Ebpf

Source

pub fn load_file<P: AsRef<Path>>(path: P) -> Result<Self, EbpfError>

Loads eBPF bytecode from a file.

Parses the given object code file and initializes the maps defined in it. If the kernel supports BTF debug info, it is automatically loaded from /sys/kernel/btf/vmlinux.

For more loading options, see EbpfLoader.

§Examples
use aya::Ebpf;

let bpf = Ebpf::load_file("file.o")?;
Source

pub fn load(data: &[u8]) -> Result<Self, EbpfError>

Loads eBPF bytecode from a buffer.

Parses the object code contained in data and initializes the maps defined in it. If the kernel supports BTF debug info, it is automatically loaded from /sys/kernel/btf/vmlinux.

For more loading options, see EbpfLoader.

§Examples
use aya::{Ebpf, Btf};
use std::fs;

let data = fs::read("file.o").unwrap();
// load the BTF data from /sys/kernel/btf/vmlinux
let bpf = Ebpf::load(&data)?;
Source

pub fn map(&self, name: &str) -> Option<&Map>

Returns a reference to the map with the given name.

The returned type is mostly opaque. In order to do anything useful with it you need to convert it to a typed map.

For more details and examples on maps and their usage, see the maps module documentation.

Source

pub fn map_mut(&mut self, name: &str) -> Option<&mut Map>

Returns a mutable reference to the map with the given name.

The returned type is mostly opaque. In order to do anything useful with it you need to convert it to a typed map.

For more details and examples on maps and their usage, see the maps module documentation.

Source

pub fn take_map(&mut self, name: &str) -> Option<Map>

Takes ownership of a map with the given name.

Use this when borrowing with map or map_mut is not possible (eg when using the map from an async task). The returned map will be closed on Drop, therefore the caller is responsible for managing its lifetime.

The returned type is mostly opaque. In order to do anything useful with it you need to convert it to a typed map.

For more details and examples on maps and their usage, see the maps module documentation.

Source

pub fn maps(&self) -> impl Iterator<Item = (&str, &Map)>

An iterator over all the maps.

§Examples
for (name, map) in bpf.maps() {
    println!(
        "found map `{}`",
        name,
    );
}
Source

pub fn maps_mut(&mut self) -> impl Iterator<Item = (&str, &mut Map)>

A mutable iterator over all the maps.

§Examples
for (_, map) in bpf.maps_mut() {
    map.pin(pin_path)?;
}
Source

pub fn program(&self, name: &str) -> Option<&Program>

Returns a reference to the program with the given name.

You can use this to inspect a program and its properties. To load and attach a program, use program_mut instead.

For more details on programs and their usage, see the programs module documentation.

§Examples
let program = bpf.program("SSL_read").unwrap();
println!("program SSL_read is of type {:?}", program.prog_type());
Source

pub fn program_mut(&mut self, name: &str) -> Option<&mut Program>

Returns a mutable reference to the program with the given name.

Used to get a program before loading and attaching it. For more details on programs and their usage, see the programs module documentation.

§Examples
use aya::programs::UProbe;

let program: &mut UProbe = bpf.program_mut("SSL_read").unwrap().try_into()?;
program.load()?;
program.attach(Some("SSL_read"), 0, "libssl", None)?;
Source

pub fn programs(&self) -> impl Iterator<Item = (&str, &Program)>

An iterator over all the programs.

§Examples
for (name, program) in bpf.programs() {
    println!(
        "found program `{}` of type `{:?}`",
        name,
        program.prog_type()
    );
}
Source

pub fn programs_mut(&mut self) -> impl Iterator<Item = (&str, &mut Program)>

An iterator mutably referencing all of the programs.

§Examples
for (_, program) in bpf.programs_mut() {
    program.pin(pin_path)?;
}

Trait Implementations§

Source§

impl Debug for Ebpf

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Ebpf

§

impl RefUnwindSafe for Ebpf

§

impl Send for Ebpf

§

impl Sync for Ebpf

§

impl Unpin for Ebpf

§

impl UnwindSafe for Ebpf

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.