Struct aya::Bpf

source · []
pub struct Bpf { /* private fields */ }
Expand description

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

Implementations

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 BpfLoader.

Examples
use aya::Bpf;

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

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 BpfLoader.

Examples
use aya::{Bpf, Btf};
use std::fs;

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

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.

Errors

Returns MapError::MapNotFound if the map does not exist. If the map is already borrowed mutably with map_mut then MapError::BorrowError is returned.

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.

Errors

Returns MapError::MapNotFound if the map does not exist. If the map is already borrowed mutably with map_mut then MapError::BorrowError is returned.

An iterator over all the maps.

Examples
for (name, map) in bpf.maps() {
    println!(
        "found map `{}` of type `{:?}`",
        name,
        map?.map_type().unwrap()
    );
}

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());

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;
use std::convert::TryInto;

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

An iterator over all the programs.

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

An iterator mutably referencing all of the programs.

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

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.