$ show aya-rs/aya
Aya is a Rust framework for developing, loading, and managing eBPF (extended Berkeley Packet Filter) programs. It provides a pure-Rust alternative to libbpf and bcc, allowing developers to write eBPF programs in Rust without leaving the language ecosystem. The framework supports various eBPF program types (XDP, socket filters, tracepoints, kprobes, uprobes, LSM, etc.) and map types (arrays, hash maps, perf event arrays, ring buffers, etc.), with strong emphasis on type safety and developer experience. Aya implements BTF (BPF Type Format) support for compile-once-run-everywhere portability across kernel versions and provides procedural macros to reduce boilerplate when defining eBPF entities. The architecture consists of multiple crates separating userspace and kernel-space concerns, with extensive integration tests validating functionality against actual kernels.
The LLM identified 3 files worth highlighting for reuse:
Provides procedural macros for defining eBPF programs and maps with minimal boilerplate. Handles complex attribute parsing, ELF section generation, and context wrapping. The macros follow a uniform pattern across different program types (kprobe, xdp, tracepoint, etc.) and map types, significantly reducing the complexity of writing eBPF programs in Rust while maintaining type safety.
Implements a type-safe wrapper around BPF hash maps with get, set, and delete operations. Demonstrates skilled resource management through proper handling of BPF file descriptors, error propagation from syscalls, and zero-cost abstractions. The implementation shows non-obvious skill in balancing safety with performance, using Rust's type system to prevent common eBPF programming errors while maintaining compatibility with BPF syscalls.
Defines a uniform Link trait for attaching eBPF programs to various kernel hooks (XDP, kprobe, tracepoint, etc.) with multiple implementations (FdLink, PinnedLink, etc.). Shows excellent abstraction design by providing a consistent interface across different attach types while handling the complexity of file descriptor management, automatic detachment, and pinned links for persistent programs.