Struct redbpf::ModuleBuilder[][src]

pub struct ModuleBuilder<'a> { /* fields omitted */ }
Expand description

A builder of Module

In most cases redbpf::load::Loader::load or redbpf::Module::parse is enough to achieve your goal. These functions parse maps and programs from the ELF relocatable file and then load them into kernel directly. But sometimes you need to manipulate the maps or the programs before load them. That’s why ModuleBuilder exists.

By ModuleBuilder you can achieve one goal at this moment: sharing maps among multiple independent BPF programs and their corresponding userspace programs by calling ModuleBuilder::replace_map

cf. Here, “independent BPF programs” means that each BPF program had been compiled into a different ELF relocatable file. You don’t have to deal with ModuleBuilder if all BPF programs are compiled into one ELF relocatable file.

Implementations

Parse binary data of ELF relocatable file

Example
use redbpf::ModuleBuilder;
let mut builder = ModuleBuilder::parse(probe_code()).expect("error on ModuleBuilder::parse");

Create Module from ModuleBuilder

When this method is called, ModuleBuilder is moved out so the instance can not be used any more.

Example
use redbpf::ModuleBuilder;
let module = ModuleBuilder::parse(bytes).expect("error on ModuleBuilder::parse").to_module();

Replace a map whose name is map_name with a new Map

This method can fail if there does not exist a map whose name is map_name or definitions of new map and a map whose name is map_name do not match each other. The compared definition includes key size, value size, map type and the max entry number.

Example
use redbpf::{ModuleBuilder, Map};
let mut builder = ModuleBuilder::parse(bytes).expect("error on ModuleBuilder::parse");
builder.replace_map("sharedmap", Map::from_pin_file("/sys/fs/bpf/sharedmap").expect("error on Map::from_pin_file")).expect("error on ModuleBuilder::replace_map");
let mut module = builder.to_module().expect("error on ModuleBuilder::to_module");

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

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more