Struct aya::Bpf[][src]

pub struct Bpf { /* fields omitted */ }
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.

Examples

use aya::Bpf;

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

Load eBPF bytecode.

Parses the object code contained in data and initializes the maps defined in it. If target_btf is not None and data includes BTF debug info, BTF relocations are applied as well.

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, Some(Btf::from_sys_fs()?));

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.

Errors

Returns ProgramError::NotFound if the program does not exist.

Examples

let program = bpf.program("SSL_read")?;
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.

Errors

Returns ProgramError::NotFound if the program does not exist.

Examples

use aya::programs::UProbe;
use std::convert::TryInto;

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

An iterator over all the programs.

Examples

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

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

Performs the conversion.

Performs the conversion.

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.