Expand description
Rust API to load BPF programs.
§Overview
The redbpf crate provides an idiomatic Rust API to load and interact with BPF programs. It is part of the larger redbpf project.
BPF programs used with redbpf
are typically created and built with
cargo-bpf
, and use the
redbpf-probes
and
redbpf-macros
APIs.
For full featured examples on how to use redbpf see https://github.com/foniod/redbpf/tree/master/redbpf-tools.
§Example
The following example loads all the kprobes
defined in the file iotop.elf
.
use redbpf::load::Loader;
let mut loader = Loader::load_file("iotop.elf").expect("error loading probe");
// attach all the kprobes defined in iotop.elf
for kprobe in loader.kprobes_mut() {
kprobe
.attach_kprobe(&kprobe.name(), 0)
.expect(&format!("error attaching program {}", kprobe.name()));
}
Modules§
Structs§
- Array
- Array map corresponding to BPF_MAP_TYPE_ARRAY
- BPFIter
- A structure for reading data from BPF iterators
- BpfStack
Frames - HashMap
- A BPF hash map structure
- KProbe
- Type to work with
kprobes
orkretprobes
. - Lost
Samples - LruHash
Map - A BPF LRU hash map structure
- LruPer
CpuHash Map - An LRU per-cpu BPF hash map structure
- Map
- A base BPF map data structure
- MapIter
- Module
- Module
Builder - A builder of Module
- PerCpu
Array - Per-cpu array map corresponding to BPF_MAP_TYPE_PERCPU_ARRAY
- PerCpu
Hash Map - A per-cpu BPF hash map structure
- PerCpu
Values - A structure representing values of per-cpu map structures such as
PerCpuArray
- PerfMap
- Program
Array - Program array map.
- Relocation
Info - Sample
- SkLookup
- Type to work with
sk_lookup
BPF programs. - SockMap
- SockMap structure for storing file descriptors of TCP sockets by userspace program.
- Socket
Filter - Type to work with
socket filters
. - Stack
Trace - A stacktrace BPF map structure
- Stream
Parser - Type to work with
stream_parser
BPF programs. - Stream
Verdict - Type to work with
stream_verdict
BPF programs. - Task
Iter - A structure supporting BPF iterators that handle
task
- Trace
Point - UProbe
- Type to work with
uprobes
oruretprobes
. - XDP
- Type to work with
XDP
programs.