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
.
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.
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)?;