7 releases

0.2.0 Feb 28, 2024
0.1.13 Nov 16, 2022
0.1.11 Sep 1, 2022
0.1.10 Jun 8, 2022
0.1.1 Oct 15, 2021

#573 in Unix APIs

Download history 230/week @ 2024-03-13 358/week @ 2024-03-20 229/week @ 2024-03-27 327/week @ 2024-04-03 294/week @ 2024-04-10 358/week @ 2024-04-17 375/week @ 2024-04-24 569/week @ 2024-05-01 333/week @ 2024-05-08 467/week @ 2024-05-15 542/week @ 2024-05-22 500/week @ 2024-05-29 525/week @ 2024-06-05 655/week @ 2024-06-12 469/week @ 2024-06-19 406/week @ 2024-06-26

2,133 downloads per month

MIT/Apache

570KB
12K SLoC

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::BpfLogger;

env_logger::init();

// Will log using the default logger, which is TermLogger in this case
BpfLogger::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)
}

Dependencies

~7–16MB
~193K SLoC