Crate redbpf

Source
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§

btf
cpus
load
sys
uname
xdp

Structs§

Array
Array map corresponding to BPF_MAP_TYPE_ARRAY
BPFIter
A structure for reading data from BPF iterators
BpfStackFrames
HashMap
A BPF hash map structure
KProbe
Type to work with kprobes or kretprobes.
LostSamples
LruHashMap
A BPF LRU hash map structure
LruPerCpuHashMap
An LRU per-cpu BPF hash map structure
Map
A base BPF map data structure
MapIter
Module
ModuleBuilder
A builder of Module
PerCpuArray
Per-cpu array map corresponding to BPF_MAP_TYPE_PERCPU_ARRAY
PerCpuHashMap
A per-cpu BPF hash map structure
PerCpuValues
A structure representing values of per-cpu map structures such as PerCpuArray
PerfMap
ProgramArray
Program array map.
RelocationInfo
Sample
SkLookup
Type to work with sk_lookup BPF programs.
SockMap
SockMap structure for storing file descriptors of TCP sockets by userspace program.
SocketFilter
Type to work with socket filters.
StackTrace
A stacktrace BPF map structure
StreamParser
Type to work with stream_parser BPF programs.
StreamVerdict
Type to work with stream_verdict BPF programs.
TaskIter
A structure supporting BPF iterators that handle task
TracePoint
UProbe
Type to work with uprobes or uretprobes.
XDP
Type to work with XDP programs.

Enums§

Error
Event
Program
A BPF program defined in a Module.

Type Aliases§

DataPtr
MutDataPtr
Result