https://github.com/flier/rust-ebpf
https://github.com/flier/rust-ebpf
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/flier/rust-ebpf
- Owner: flier
- Created: 2019-06-14T10:51:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-21T10:43:09.000Z (about 7 years ago)
- Last Synced: 2025-03-24T07:13:53.324Z (over 1 year ago)
- Language: Rust
- Size: 162 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rust-ebpf
`rust-ebpf` is a experimental project that provides a toolchain to compile, load and run eBPF program.
## Build
`rust-ebpf` support to compile rust code to eBPF object.
First, add the `ebpf-build` crate to your `Cargo.toml`.
```toml
[build-dependencies]
ebpf-build = "0.1"
```
Then, compile and build the kernel file to eBPF object.
```rust
extern crate ebpf_build;
fn main() {
ebpf_build::Builder::new().build().expect("build kernel");
}
```
Then, the generated kernel file will be point by the `KERNEL` envrionment variable.
```rust
const KERNEL: &[u8] = include_bytes!(env!("KERNEL"));
```
**Note:** Build eBPF object need install `llvm` first, and you can point to `llc` command with `LLC` envrionment variable.
## Load
`rust-ebpf` support to load the eBPF programs from a ELF file.
First, add the `ebpf-loader` crate to your `Cargo.toml`.
```toml
[dependencies]
ebpf-loader = "0.1"
```
Then, load or parse the ELF file for programs.
```rust
let obj = ebpf_loader::parse(KERNEL)?;
```
## Run
## Reference
* [PoC: compiling to eBPF from Rust](http://unhandledexpression.com/general/rust/2018/02/02/poc-compiling-to-ebpf-from-rust.html)