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
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. In order to allow sharing of a single BTF object among multiple
eBPF programs, target_btf
is passed by reference.
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, Btf::from_sys_fs().ok().as_ref());
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)?;