pub struct Extension { /* private fields */ }
Expand description
A program used to extend existing BPF programs
Extension
programs can be loaded to replace a global
function in a program that has already been loaded.
Minimum kernel version
The minimum kernel version required to use this feature is 5.9
Examples
use aya::{BpfLoader, programs::{Xdp, XdpFlags, Extension, ProgramFd}};
use std::convert::TryInto;
let mut bpf = BpfLoader::new().extension("extension").load_file("app.o")?;
let prog: &mut Xdp = bpf.program_mut("main").unwrap().try_into()?;
prog.load()?;
prog.attach("eth0", XdpFlags::default())?;
let prog_fd = prog.fd().unwrap();
let ext: &mut Extension = bpf.program_mut("extension").unwrap().try_into()?;
ext.load(prog_fd, "function_to_replace")?;
ext.attach()?;
Ok::<(), aya::BpfError>(())
Implementations
sourceimpl Extension
impl Extension
sourcepub fn load<T: AsRawFd>(
&mut self,
program: T,
func_name: &str
) -> Result<(), ProgramError>
pub fn load<T: AsRawFd>(
&mut self,
program: T,
func_name: &str
) -> Result<(), ProgramError>
Loads the extension inside the kernel.
Prepares the code included in the extension to replace the code of the function
func_name
within the eBPF program represented by the program
file descriptor.
This requires that both the Extension
and program
have had their BTF
loaded into the kernel as the verifier must check that the function signatures
match.
The extension code will be loaded but inactive until it’s attached. There are no restrictions on what functions may be replaced, so you could replace the main entry point of your program with an extension.
See also Program::load
.
sourcepub fn attach(&mut self) -> Result<LinkRef, ProgramError>
pub fn attach(&mut self) -> Result<LinkRef, ProgramError>
Attaches the extension
Attaches the extension effectively replacing the original target function. Detaching the returned link restores the original function.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Extension
impl !Send for Extension
impl !Sync for Extension
impl Unpin for Extension
impl !UnwindSafe for Extension
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