Struct aya::BpfLoader[][src]

pub struct BpfLoader<'a> { /* fields omitted */ }
Expand description

Builder style API for advanced loading of eBPF programs.

Loading eBPF code involves a few steps, including loading maps and applying relocations. You can use BpfLoader to customize some of the loading options.

Examples

use aya::{BpfLoader, Btf};
use std::fs;

let bpf = BpfLoader::new()
    // load the BTF data from /sys/kernel/btf/vmlinux
    .btf(Btf::from_sys_fs().ok().as_ref())
    // load pinned maps from /sys/fs/bpf/my-program
    .map_pin_path("/sys/fs/bpf/my-program")
    // finally load the code
    .load_file("file.o")?;

Implementations

Creates a new loader instance.

Sets the target BTF info.

The loader defaults to loading BTF info using Btf::from_sys_fs. Use this method if you want to load BTF from a custom location or pass None to disable BTF relocations entirely.

Example
use aya::{BpfLoader, Btf, Endianness};

let bpf = BpfLoader::new()
    // load the BTF data from a custom location
    .btf(Btf::parse_file("/custom_btf_file", Endianness::default()).ok().as_ref())
    .load_file("file.o")?;

Sets the base directory path for pinned maps.

Pinned maps will be loaded from path/MAP_NAME.

Example
use aya::BpfLoader;

let bpf = BpfLoader::new()
    .map_pin_path("/sys/fs/bpf/my-program")
    .load_file("file.o")?;

Loads eBPF bytecode from a file.

Examples
use aya::BpfLoader;

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

Loads eBPF bytecode from a buffer.

Examples
use aya::BpfLoader;
use std::fs;

let data = fs::read("file.o").unwrap();
let bpf = BpfLoader::new().load(&data)?;

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. 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.