pub struct ModuleBuilder<'a> { /* private fields */ }
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§
Source§impl<'a> ModuleBuilder<'a>
impl<'a> ModuleBuilder<'a>
Sourcepub fn parse(bytes: &'a [u8]) -> Result<Self>
pub fn parse(bytes: &'a [u8]) -> Result<Self>
Parse binary data of ELF relocatable file
§Example
use redbpf::ModuleBuilder;
let mut builder = ModuleBuilder::parse(probe_code()).expect("error on ModuleBuilder::parse");
Sourcepub fn replace_map(&mut self, map_name: &str, new: Map) -> Result<&mut Self>
pub fn replace_map(&mut self, map_name: &str, new: Map) -> Result<&mut Self>
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");