需要目标内核支持 BTF 才能实现跨内核版本运行;示例中加载的是预先编译好的 ebpf.o,需自行准备 eBPF 目标文件;链接 musl 才能获得真正自包含的单二进制
aya
aya-rsApache-2.0活跃维护用 Rust 写 eBPF 程序的库,主打开发体验和可运维性,省去 C 工具链和内核头文件依赖,编译即用。
Aya is an eBPF library for the Rust programming language, built with a focus on developer experience and operability.
纯 Rust 实现的 eBPF 库,不依赖 libbpf/bcc,让你在 Rust 里加载和管理内核 eBPF 程序
用 Rust 写 eBPF 程序的库,主打开发体验和可运维性,省去 C 工具链和内核头文件依赖,编译即用。
核心能力
- 纯 Rust 从零实现,仅依赖 libc crate 执行系统调用
- 支持 BTF,跨内核版本编译一次到处运行
- 支持函数调用重定位与全局变量/初始化器
- 提供 tokio 和 async-std 异步支持
- 无需内核源码、编译头文件甚至 C 工具链,构建只需数秒
容易踩的坑
- aya-ebpf-bindings-v0.3.0最新正式版2026-10-29 · 2026-10-29 13:54 UTC
What's Changed
- build(deps): bump rustls from 0.23.45 to 0.23.46 by @dependabot[bot] in https://github.com/aya-rs/aya/pull/1841
- build: refresh toolchains and workflow dependencies by @crabby-the-crab in https://github.com/aya-rs/aya/pull/1842
- build: refresh toolchains and workflow dependencies by @crabby-the-crab in https://github.com/aya-rs/aya/pull/1843
Full Changelog: https://github.com/aya-rs/aya/compare/aya-v0.16.0...aya-ebpf-bindings-v0.3.0
- aya-v0.16.02026-10-28 · 2026-10-28 11:16 UTC
查看更新说明
What's Changed
- build: refresh toolchains and workflow dependencies by @crabby-the-crab in https://github.com/aya-rs/aya/pull/1839
- chore(aya): Prepare release 0.16.0 by @vadorovsky in https://github.com/aya-rs/aya/pull/1840
Full Changelog: https://github.com/aya-rs/aya/compare/aya-obj-v0.6.0...aya-v0.16.0
- aya-obj-v0.6.02026-10-27 · 2026-10-27 16:11 UTC
查看更新说明
What's Changed
- Prepare releases ot aya-ebpf-macros and aya-obj by @vadorovsky in https://github.com/aya-rs/aya/pull/1838
Full Changelog: https://github.com/aya-rs/aya/compare/aya-ebpf-macros-v0.4.0...aya-obj-v0.6.0
- aya-ebpf-macros-v0.4.02026-10-27 · 2026-10-27 16:11 UTC
查看更新说明
What's Changed
- build: update Rust 1.99.1, nightly-2026-10-21 by @crabby-the-crab in https://github.com/aya-rs/aya/pull/1822
- test: trigger kprobe with a synchronous read by @tamird in https://github.com/aya-rs/aya/pull/1823
- ci: lock GitHub Actions dependencies by @tamird in https://github.com/aya-rs/aya/pull/1815
- aya-obj: validate BTF parser boundaries by @tamird in https://github.com/aya-rs/aya/pull/1824
- build: update Rust 1.99.1, nightly-2026-10-22 by @crabby-the-crab in https://github.com/aya-rs/aya/pull/1826
- aya-ebpf: support BTF map pinning by name by @tamird in https://github.com/aya-rs/aya/pull/1791
- ci: fix codegen and cross-target library lookup by @tamird in https://github.com/aya-rs/aya/pull/1827
- build: select bundled liblzma for Cargo by @tamird in https://github.com/aya-rs/aya/pull/1828
- build: update Rust 1.99.1, nightly-2026-10-23 by @crabby-the-crab in https://github.com/aya-rs/aya/pull/1830
- ci: refresh locked workflow dependencies by @tamird in https://github.com/aya-rs/aya/pull/1829
- build(deps): bump rstest from 0.27.0 to 0.28.0 in the cargo-crates group by @dependabot[bot] in https://github.com/aya-rs/aya/pull/1833
- aya: validate pinned maps before reuse by @tamird in https://github.com/aya-rs/aya/pull/1825
- build: refresh toolchains and workflow dependencies by @crabby-the-crab in https://github.com/aya-rs/aya/pull/1835
- build: refresh toolchains and workflow dependencies by @crabby-the-crab in https://github.com/aya-rs/aya/pull/1836
Full Changelog: https://github.com/aya-rs/aya/compare/aya-log-parser-v0.3.0...aya-ebpf-macros-v0.4.0
- aya-v0.15.02026-10-27 · 2026-10-27 14:37 UTC
查看更新说明
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
API Documentation
Community
Join the conversation on Discord to discuss anything related to Aya or discover and contribute to a list of Awesome Aya projects.
Overview
eBPF is a technology that allows running user-supplied programs inside the Linux kernel. For more info see What is eBPF.
Aya is an eBPF library built with a focus on operability and developer experience. It does not rely on libbpf nor bcc - it's built from the ground up purely in Rust, using only the libc crate to execute syscalls. With BTF support and when linked with musl, it offers a true compile once, run everywhere solution, where a single self-contained binary can be deployed on many linux distributions and kernel versions.
Some of the major features provided include:
- Support for the BPF Type Format (BTF), which is transparently enabled when supported by the target kernel. This allows eBPF programs compiled against one kernel version to run on different kernel versions without the need to recompile.
- Support for function call relocation and global data maps, which allows eBPF programs to make function calls and use global variables and initializers.
- Async support with both tokio and async-std.
- Easy to deploy and fast to build: aya doesn't require a kernel build or compiled headers, and not even a C toolchain; a release build completes in a matter of seconds.
Example
Aya supports a large chunk of the eBPF API. The following example shows how to
use a BPF_PROG_TYPE_CGROUP_SKB program with aya:
use std::fs::File;
use aya::Ebpf;
use aya::programs::{CgroupSkb, CgroupSkbAttachType, CgroupAttachMode};
// load the BPF code
let mut ebpf = Ebpf::load_file("ebpf.o")?;
// get the `ingress_filter` program compiled into `ebpf.o`.
let ingress: &mut CgroupSkb = ebpf.program_mut("ingress_filter")?.try_into()?;
// load the program into the kernel
ingress.load()?;
// attach the program to the root cgroup. `ingress_filter` will be called for all
// incoming packets.
let cgroup = File::open("/sys/fs/cgroup/unified")?;
ingress.attach(cgroup, CgroupSkbAttachType::Ingress, CgroupAttachMode::AllowOverride)?;
Contributing
Please see the contributing guide.
License
Aya is distributed under the terms of either the MIT license or the Apache License (version 2.0), at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.