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");
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
impl<'a> RefUnwindSafe for ModuleBuilder<'a>
impl<'a> Send for ModuleBuilder<'a>
impl<'a> Sync for ModuleBuilder<'a>
impl<'a> Unpin for ModuleBuilder<'a>
impl<'a> UnwindSafe for ModuleBuilder<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more
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