pub struct Bpf { /* private fields */ }
Expand description
The main entry point into the library, used to work with eBPF programs and maps.
Implementations
sourceimpl Bpf
impl Bpf
sourcepub fn load_file<P: AsRef<Path>>(path: P) -> Result<Bpf, BpfError>
pub fn load_file<P: AsRef<Path>>(path: P) -> Result<Bpf, BpfError>
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")?;
sourcepub fn load(data: &[u8]) -> Result<Bpf, BpfError>
pub fn load(data: &[u8]) -> Result<Bpf, BpfError>
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)?;
sourcepub fn map(&self, name: &str) -> Result<MapRef, MapError>
pub fn map(&self, name: &str) -> Result<MapRef, MapError>
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.
sourcepub fn map_mut(&self, name: &str) -> Result<MapRefMut, MapError>
pub fn map_mut(&self, name: &str) -> Result<MapRefMut, MapError>
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.
sourcepub fn maps(&self) -> impl Iterator<Item = (&str, Result<MapRef, MapError>)>
pub fn maps(&self) -> impl Iterator<Item = (&str, Result<MapRef, MapError>)>
An iterator over all the maps.
Examples
for (name, map) in bpf.maps() {
println!(
"found map `{}` of type `{:?}`",
name,
map?.map_type().unwrap()
);
}
sourcepub fn program(&self, name: &str) -> Option<&Program>
pub fn program(&self, name: &str) -> Option<&Program>
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());
sourcepub fn program_mut(&mut self, name: &str) -> Option<&mut Program>
pub fn program_mut(&mut self, name: &str) -> Option<&mut Program>
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)?;
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Bpf
impl !Send for Bpf
impl !Sync for Bpf
impl Unpin for Bpf
impl !UnwindSafe for Bpf
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more