From 648b7b791d427ce63d2d14b94565dbd1ffe2a961 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sat, 6 Sep 2025 07:08:37 -0400 Subject: [PATCH 1/6] Supply LLVM version feature to fix mac CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b69a51..c9aee43 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,7 +83,7 @@ jobs: - run: brew update && brew install filosottile/musl-cross/musl-cross llvm if: runner.os == 'macos' - - run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git --no-default-features + - run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git --no-default-features --features llvm-21 if: runner.os == 'macos' - run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git From a5f3162412d3b67fa4be1a6d3b1afc21506620b1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 6 Sep 2025 12:04:14 +0000 Subject: [PATCH 2/6] Bump actions/checkout from 4 to 5 Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9aee43..3356e76 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,7 @@ jobs: runs-on: ${{ matrix.runner }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - uses: dtolnay/rust-toolchain@nightly with: From b263338358b8bd99505cbf16878d4f022dce36e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=84=91=E8=A2=8B=E9=87=8C=E8=BF=9B=E8=8A=B1=E7=94=9F?= =?UTF-8?q?=E4=BA=86?= <109732988+Redmomn@users.noreply.github.com> Date: Sat, 6 Sep 2025 20:38:15 +0800 Subject: [PATCH 3/6] fix: use the correct return value for cgroup_skb `cgroup_skb` returns 0 will block traffic in the current direction. An example program should not block traffic, this can cause difficulties for beginners. --- {{project-name}}-ebpf/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{project-name}}-ebpf/src/main.rs b/{{project-name}}-ebpf/src/main.rs index 18233ae..7a780d4 100644 --- a/{{project-name}}-ebpf/src/main.rs +++ b/{{project-name}}-ebpf/src/main.rs @@ -183,7 +183,7 @@ pub fn {{crate_name}}(ctx: SkBuffContext) -> i32 { fn try_{{crate_name}}(ctx: SkBuffContext) -> Result { info!(&ctx, "received a packet"); - Ok(0) + Ok(1) } {%- when "tracepoint" %} use aya_ebpf::{macros::tracepoint, programs::TracePointContext}; From 0158e1b8e0d60c18546b08f2879992d8294e3feb Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sat, 12 Jul 2025 11:59:38 -0400 Subject: [PATCH 4/6] Adapt to removal of `async_tokio` feature See https://github.com/aya-rs/aya/commit/35332f2288b0bbb8981233ae464715. --- Cargo.toml | 10 +++++----- {{project-name}}/build.rs | 6 +++--- {{project-name}}/src/main.rs | 21 +++++++++++++++++---- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d0d3678..68dd41f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,11 +12,11 @@ license = "MIT OR Apache-2.0" edition = "2024" [workspace.dependencies] -aya = { version = "0.13.1", default-features = false } -aya-build = { version = "0.1.2", default-features = false } -aya-ebpf = { version = "0.1.1", default-features = false } -aya-log = { version = "0.2.1", default-features = false } -aya-log-ebpf = { version = "0.1.1", default-features = false } +aya = { git = "https://github.com/aya-rs/aya", default-features = false } +aya-build = { git = "https://github.com/aya-rs/aya", default-features = false } +aya-ebpf = { git = "https://github.com/aya-rs/aya", default-features = false } +aya-log = { git = "https://github.com/aya-rs/aya", default-features = false } +aya-log-ebpf = { git = "https://github.com/aya-rs/aya", default-features = false } anyhow = { version = "1", default-features = false } # `std` feature is currently required to build `clap`. diff --git a/{{project-name}}/build.rs b/{{project-name}}/build.rs index 6e2ce43..c30640a 100644 --- a/{{project-name}}/build.rs +++ b/{{project-name}}/build.rs @@ -1,5 +1,5 @@ use anyhow::{Context as _, anyhow}; -use aya_build::cargo_metadata; +use aya_build::{Toolchain, cargo_metadata}; fn main() -> anyhow::Result<()> { let cargo_metadata::Metadata { packages, .. } = cargo_metadata::MetadataCommand::new() @@ -8,7 +8,7 @@ fn main() -> anyhow::Result<()> { .context("MetadataCommand::exec")?; let ebpf_package = packages .into_iter() - .find(|cargo_metadata::Package { name, .. }| name == "{{project-name}}-ebpf") + .find(|cargo_metadata::Package { name, .. }| name.as_str() == "{{project-name}}-ebpf") .ok_or_else(|| anyhow!("{{project-name}}-ebpf package not found"))?; - aya_build::build_ebpf([ebpf_package]) + aya_build::build_ebpf([ebpf_package], Toolchain::default()) } diff --git a/{{project-name}}/src/main.rs b/{{project-name}}/src/main.rs index 5c6e8b9..b558ec8 100644 --- a/{{project-name}}/src/main.rs +++ b/{{project-name}}/src/main.rs @@ -96,9 +96,22 @@ async fn main() -> anyhow::Result<()> { env!("OUT_DIR"), "/{{project-name}}" )))?; - if let Err(e) = aya_log::EbpfLogger::init(&mut ebpf) { - // This can happen if you remove all log statements from your eBPF program. - warn!("failed to initialize eBPF logger: {e}"); + match aya_log::EbpfLogger::init(&mut ebpf) { + Err(e) => { + // This can happen if you remove all log statements from your eBPF program. + warn!("failed to initialize eBPF logger: {e}"); + } + Ok(logger) => { + let mut logger = + tokio::io::unix::AsyncFd::with_interest(logger, tokio::io::Interest::READABLE)?; + tokio::task::spawn(async move { + loop { + let mut guard = logger.readable_mut().await.unwrap(); + guard.get_inner_mut().flush(); + guard.clear_ready(); + } + }); + } } {%- case program_type -%} {%- when "kprobe", "kretprobe" %} @@ -119,7 +132,7 @@ async fn main() -> anyhow::Result<()> { let Opt { pid } = opt; let program: &mut UProbe = ebpf.program_mut("{{crate_name}}").unwrap().try_into()?; program.load()?; - program.attach(Some("{{uprobe_fn_name}}"), 0, "{{uprobe_target}}", pid)?; + program.attach("{{uprobe_fn_name}}", "{{uprobe_target}}", pid, None /* cookie */)?; {%- when "sock_ops", "cgroup_skb", "cgroup_sysctl", "cgroup_sockopt" %} let Opt { cgroup_path } = opt; let cgroup = From a515461033c976e3d1d03b3020fec21abd64bdde Mon Sep 17 00:00:00 2001 From: Joseph Ligier Date: Thu, 11 Sep 2025 10:45:14 +0200 Subject: [PATCH 5/6] Add xdp and classifier interface --- cargo-generate.toml | 4 ++++ test.sh | 8 +++++++- {{project-name}}/src/main.rs | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cargo-generate.toml b/cargo-generate.toml index efee760..493fb1c 100644 --- a/cargo-generate.toml +++ b/cargo-generate.toml @@ -28,6 +28,10 @@ choices = [ ] default = "xdp" +[conditional.'program_type == "classifier" || program_type == "xdp"'.placeholders.default_iface] +type = "string" +prompt = "Which interface to attach to by default? (e.g eth0)" + [conditional.'program_type == "kprobe" || program_type == "kretprobe"'.placeholders.kprobe] type = "string" prompt = "Where to attach the (k|kret)probe? (e.g try_to_wake_up)" diff --git a/test.sh b/test.sh index 76076ef..d9a2dd8 100755 --- a/test.sh +++ b/test.sh @@ -18,9 +18,15 @@ case ${PROG_TYPE} in "cgroup_sockopt") ADDITIONAL_ARGS=(-d sockopt_target=getsockopt) ;; -"classifier" | "cgroup_skb") +"cgroup_skb") ADDITIONAL_ARGS=(-d direction=Ingress) ;; +"classifier") + ADDITIONAL_ARGS=(-d direction=Ingress -d default_iface=eth0) + ;; +"xdp") + ADDITIONAL_ARGS=(-d default_iface=eth0) + ;; "fentry" | "fexit") ADDITIONAL_ARGS=(-d fn_name=try_to_wake_up) ;; diff --git a/{{project-name}}/src/main.rs b/{{project-name}}/src/main.rs index b558ec8..86cf0cf 100644 --- a/{{project-name}}/src/main.rs +++ b/{{project-name}}/src/main.rs @@ -58,7 +58,7 @@ use tokio::signal; struct Opt { {%- case program_type -%} {%- when "xdp", "classifier" %} - #[clap(short, long, default_value = "eth0")] + #[clap(short, long, default_value = "{{default_iface}}")] iface: String, {%- when "sock_ops", "cgroup_skb", "cgroup_sysctl", "cgroup_sockopt" %} #[clap(short, long, default_value = "/sys/fs/cgroup")] From c8970881ef73013e34ff5a855a39cb5dc9364a27 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 26 Sep 2025 04:46:40 -0400 Subject: [PATCH 6/6] Update to macOS 15 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3356e76..beac01a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,9 +47,9 @@ jobs: - tp_btf - tracepoint include: - - runner: macos-13 # x86 + - runner: macos-15-intel # x86 program: kprobe - - runner: macos-14 # arm64 + - runner: macos-15 # arm64 program: kprobe runs-on: ${{ matrix.runner }}