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

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.

Attaches the extension

Attaches the extension effectively replacing the original target function. Detaching the returned link restores the original function.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the RawFd of the program if it has been loaded, or None

Returns the RawFd of the program if it has been loaded, or None

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.