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.

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.

Detaches the extension.

Detaching restores the original code overridden by the extension program. See Extension::attach.

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.

Unloads the program from the kernel.

Links will be detached before unloading the program. Note that owned links obtained using take_link() will not be detached.

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.