mirror of https://github.com/aya-rs/aya
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88f5ac3114
Purpose of this commit is to add detections for whether a field is available in `ProgramInfo`. - For `program_type()`, we return the new enum `ProgramType` instead of the integer representation. - For fields that we know cannot be zero, we return `Option<NonZero*>` type. - For `name_as_str()`, it now also uses the feature probe `bpf_name()` to detect if field is available or not. - Two additional feature probes are added for the fields: - `prog_info_map_ids()` probe -> `map_ids()` field - `prog_info_gpl_compatible()` probe -> `gpl_compatible()` field With the `prog_info_map_ids()` probe, the previous implementation that I had for `bpf_prog_get_info_by_fd()` is shortened to use the probe instead of having to make 2 potential syscalls. The `test_loaded_at()` test is also moved into info tests since it is better related to the info tests. `aya::programs::Programs::prog_type(&self)` now returns `ProgramType` instead of the generated FFI from aya-obj. Also previously, `loaded_programs()` could be accessed either through `aya` or `aya::programs`. To avoid confusion and duplicate export of the item, the function should now only be exposed through `aya::programs`. |
5 months ago | |
---|---|---|
.. | ||
src | 5 months ago | |
CHANGELOG.md | 11 months ago | |
Cargo.toml | 11 months ago | |
README.md | 11 months ago | |
release.toml | 3 years ago |
README.md
aya-log - a logging library for eBPF programs
Overview
aya-log
is a logging library for eBPF programs written using aya. Think of
it as the log crate for eBPF.
Installation
User space
Add aya-log
to Cargo.toml
:
[dependencies]
aya-log = { git = "https://github.com/aya-rs/aya", branch = "main" }
eBPF side
Add aya-log-ebpf
to Cargo.toml
:
[dependencies]
aya-log-ebpf = { git = "https://github.com/aya-rs/aya", branch = "main" }
Example
Here's an example that uses aya-log
in conjunction with the env_logger crate
to log eBPF messages to the terminal.
User space code
use aya_log::EbpfLogger;
env_logger::init();
// Will log using the default logger, which is TermLogger in this case
EbpfLogger::init(&mut bpf).unwrap();
eBPF code
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)
}