1 个不稳定版本
0.3.3 | 2023 年 5 月 15 日 |
---|
#1032 in 开发工具
61KB
1.5K SLoC
eunomia-bpf:通过 CO-RE[^1] 和 WebAssembly[^2] 简化和增强 eBPF
一个编译器和运行时框架,帮助您更轻松地构建和分发 eBPF 程序。
简介
eunomia-bpf
是一个动态加载库/运行时和编译工具链框架,旨在帮助您更轻松地构建和分发 eBPF 程序。
使用 eunnomia-bpf,您可以
- 一个简化
编写
eBPF 程序的库- 简化构建 CO-RE[^1]
libbpf
eBPF 应用程序:只需 编写 eBPF 内核代码,并自动通过perf event
或ring buffer
从内核中公开您的数据。 - 自动采集数据 并在用户空间中打印
hists
。 - 自动生成 和配置 eBPF 程序的
命令行参数
。 - 您可以使用
BCC
和libbpf
风格编写内核部分。
- 简化构建 CO-RE[^1]
- 使用
Wasm
[^2] 构建 eBPF 程序:参见Wasm-bpf
项目- 运行时、库和工具链,在 C/C++、Rust、Go 等语言中使用 Wasm 编写 eBPF,涵盖从
tracing
、networking
、security
等用例。
- 运行时、库和工具链,在 C/C++、Rust、Go 等语言中使用 Wasm 编写 eBPF,涵盖从
- 简化
分发
eBPF 程序- 一个用于推送、拉取和运行预编译 eBPF 程序作为 Wasm 模块的
OCI
图像的工具 - 从
云
或URL
中运行 eBPF 程序,无需重新编译,不受内核版本和架构限制,只需在1
行 bash 中运行即可。 - 使用
JSON
配置文件或Wasm
模块动态加载 eBPF 程序。
- 一个用于推送、拉取和运行预编译 eBPF 程序作为 Wasm 模块的
更多信息,请参阅 documents/introduction.md。
[^1]: CO-RE: 编译一次 – 运行任何地方 [^2]: WebAssembly 或 Wasm: https://webassembly.net.cn/
入门指南
- Github 模板:eunomia-bpf/ebpm-template
- 示例 bpf 程序:examples/bpftools
- 教程:eunomia-bpf/bpf-developer-tutorial
作为 CLI 工具或服务器运行
您可以在 1
行 bash 中从云获取预编译的 eBPF 程序,并运行到内核中
# download the release from https://github.com/eunomia-bpf/eunomia-bpf/releases/latest/download/ecli
$ wget https://aka.pw/bpf-ecli -O ecli && chmod +x ./ecli
$ sudo ./ecli run https://eunomia-bpf.github.io/eunomia-bpf/sigsnoop/package.json # simply run a pre-compiled ebpf code from a url
INFO [bpf_loader_lib::skeleton] Running ebpf program...
TIME PID TPID SIG RET COMM
01:54:49 77297 8042 0 0 node
01:54:50 77297 8042 0 0 node
01:54:50 78788 78787 17 0 which
01:54:50 78787 8084 17 0 sh
01:54:50 78790 78789 17 0 ps
01:54:50 78789 8084 17 0 sh
01:54:50 78793 78792 17 0 sed
01:54:50 78794 78792 17 0 cat
01:54:50 78795 78792 17 0 cat
$ sudo ./ecli run ghcr.io/eunomia-bpf/execve:latest # run with a name and download the latest version bpf tool from our repo
[79130] node -> /bin/sh -c which ps
[79131] sh -> which ps
[79132] node -> /bin/sh -c /usr/bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,c
[79133] sh -> /usr/bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=
[79134] node -> /bin/sh -c "/home/yunwei/.vscode-server/bin/2ccd690cbf
[79135] sh -> /home/yunwei/.vscode-server/bin/2ccd690cbff 78132 79119 79120 79121
[79136] cpuUsage.sh -> sed -n s/^cpu\s//p /proc/stat
您还可以使用服务器来管理和动态安装 eBPF 程序。
启动服务器
$ sudo ./ecli-server
[2023-08-08 02:02:03.864009 +08:00] INFO [server/src/main.rs:95] Serving at 127.0.0.1:8527
使用 ecli 控制远程服务器并管理多个 eBPF 程序
$ ./ecli client start sigsnoop.json # start the program
1
$ ./ecli client log 1 # get the log of the program
TIME PID TPID SIG RET COMM
02:05:58 79725 78132 17 0 bash
02:05:59 77325 77297 0 0 node
02:05:59 77297 8042 0 0 node
02:05:59 77297 8042 0 0 node
02:05:59 79727 79726 17 0 which
02:05:59 79726 8084 17 0 sh
02:05:59 79731 79730 17 0 which
更多信息,请参阅 documents/src/ecli/server.md。
安装项目
-
安装
ecli
工具以从云运行 eBPF 程序$ wget https://aka.pw/bpf-ecli -O ecli && chmod +x ./ecli $ ./ecli -h ecli subcommands, including run, push, pull, login, logout Usage: ecli-rs [PROG] [EXTRA_ARGS]... [COMMAND] Commands: run run ebpf program client Client operations push pull pull oci image from registry login login to oci registry logout logout from registry help Print this message or the help of the given subcommand(s) Arguments: [PROG] Not preferred. Only for compatibility to older versions. Ebpf program URL or local path, set it `-` to read the program from stdin [EXTRA_ARGS]... Not preferred. Only for compatibility to older versions. Extra args to the program; For wasm program, it will be passed directly to it; For JSON program, it will be passed to the generated argument parser Options: -h, --help Print help ....
-
安装
ecc
编译器工具链以将 eBPF 内核代码编译为config
文件或Wasm
模块(编译时需要安装clang
、llvm
和libclang
)$ wget https://github.com/eunomia-bpf/eunomia-bpf/releases/latest/download/ecc && chmod +x ./ecc $ ./ecc -h eunomia-bpf compiler Usage: ecc [OPTIONS] <SOURCE_PATH> [EXPORT_EVENT_HEADER] ....
或使用 Docker 镜像进行编译
# for x86_64 and aarch64 docker run -it -v `pwd`/:/src/ ghcr.io/eunomia-bpf/ecc-`uname -m`:latest # compile with docker. `pwd` should contains *.bpf.c files and *.h files.
-
构建编译器、运行时库和工具
有关构建详情,请参阅 build。
示例
有关简单 eBPF 工具和 eunomia-bpf 库使用的详细信息,请参阅 examples。
有关 Wasm eBPF 程序和示例,请参阅 github.com/eunomia-bpf/wasm-bpf/tree/main/examples。
我们还有一个概念验证视频:在 Wasm 中编写 eBPF 程序。
许可
MIT 许可证
依赖关系
~12–24MB
~293K SLoC