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.
sourcepub fn attach(&mut self) -> Result<ExtensionLinkId, ProgramError>
pub fn attach(&mut self) -> Result<ExtensionLinkId, ProgramError>
Attaches the extension.
Attaches the extension effectively replacing the original target function.
The returned value can be used to detach the extension and restore the original function, see Extension::detach.
sourcepub fn detach(&mut self, link_id: ExtensionLinkId) -> Result<(), ProgramError>
pub fn detach(&mut self, link_id: ExtensionLinkId) -> Result<(), ProgramError>
Detaches the extension.
Detaching restores the original code overridden by the extension program. See Extension::attach.
sourcepub fn take_link(
&mut self,
link_id: ExtensionLinkId
) -> Result<OwnedLink<ExtensionLink>, ProgramError>
pub fn take_link(
&mut self,
link_id: ExtensionLinkId
) -> Result<OwnedLink<ExtensionLink>, ProgramError>
Takes ownership of the link referenced by the provided link_id.
The link will be detached on Drop
and the caller is now responsible
for managing its lifetime.
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