A Rust library providing basic abstractions and utilities for eBPF (Extended Berkeley Packet Filter) programming.
BPF-basic is a no_std Rust crate that provides essential abstractions and utilities for eBPF programming. It offers a unified interface for working with eBPF maps and helper functions, making it easier to write eBPF programs in Rust.
- Unified Map Interface: Provides a consistent interface for working with different types of eBPF maps
- Map Types Support:
- Array maps
- Hash maps
- LRU maps
- Queue maps
- Helper Functions: Common eBPF helper functions and utilities
- Kernel Auxiliary Operations: Trait for kernel-specific operations
- Error Handling: Custom error types for eBPF operations
The crate is designed to be used in eBPF programs. Here's a basic example of how to use it:
use bpf_basic::{KernelAuxiliaryOps, UnifiedMap, Result};
// Implement the KernelAuxiliaryOps trait for your environment
struct MyKernelOps;
impl KernelAuxiliaryOps for MyKernelOps {
// Implement required methods
}
fn kernel_create_map_syscall(){
let map = bpf_map_create::<MyKernelOps>();
}The crate defines a custom BpfError enum with the following variants:
InvalidArgument: Invalid argument providedNotSupported: Operation not supportedNotFound: Resource not foundNoSpace: Insufficient space
- See DragonOS eBPF with Kprobe for more details.
- See DragonOS eBPF with Tracepoint for more details.
- See Alien eBPF with Kprobe for more details.
- See Hermit eBPF with Tracepoint