7 个版本
0.2.0 | 2024 年 2 月 28 日 |
---|---|
0.1.13 | 2022 年 11 月 16 日 |
0.1.11 | 2022 年 9 月 1 日 |
0.1.10 | 2022 年 6 月 8 日 |
0.1.1 | 2021 年 10 月 15 日 |
573 in Unix API
2,133 monthly downloads
570KB
12K SLoC
aya-log - 为 eBPF 程序提供的日志库
概述
aya-log
是一个使用 aya 编写的 eBPF 程序日志库。它可以看作是 eBPF 的 log 包。
安装
用户空间
将 aya-log
添加到 Cargo.toml
[dependencies]
aya-log = { git = "https://github.com/aya-rs/aya", branch = "main" }
eBPF 端
将 aya-log-ebpf
添加到 Cargo.toml
[dependencies]
aya-log-ebpf = { git = "https://github.com/aya-rs/aya", branch = "main" }
示例
以下是一个示例,展示了如何使用 aya-log
和 env_logger 包将 eBPF 消息记录到终端。
用户空间代码
use aya_log::BpfLogger;
env_logger::init();
// Will log using the default logger, which is TermLogger in this case
BpfLogger::init(&mut bpf).unwrap();
eBPF 代码
use aya_log_ebpf::info;
fn try_xdp_firewall(ctx: XdpContext) -> Result<u32, ()> {
if let Some(port) = tcp_dest_port(&ctx)? {
if block_port(port) {
info!(&ctx, "❌ blocked incoming connection on port: {}", port);
return Ok(XDP_DROP);
}
}
Ok(XDP_PASS)
}
依赖关系
~7–16MB
~193K SLoC