Merge branch 'aya-rs:main' into move-sudo--E-to-config-file

reviewable/pr155/r1
Ez-FlawLess 3 weeks ago committed by GitHub
commit a2545effc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -47,15 +47,15 @@ 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 }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@nightly
with:
@ -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

@ -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`.

@ -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)"

@ -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)
;;

@ -183,7 +183,7 @@ pub fn {{crate_name}}(ctx: SkBuffContext) -> i32 {
fn try_{{crate_name}}(ctx: SkBuffContext) -> Result<i32, i32> {
info!(&ctx, "received a packet");
Ok(0)
Ok(1)
}
{%- when "tracepoint" %}
use aya_ebpf::{macros::tracepoint, programs::TracePointContext};

@ -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())
}

@ -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")]
@ -96,10 +96,23 @@ async fn main() -> anyhow::Result<()> {
env!("OUT_DIR"),
"/{{project-name}}"
)))?;
if let Err(e) = aya_log::EbpfLogger::init(&mut ebpf) {
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" %}
let program: &mut KProbe = ebpf.program_mut("{{crate_name}}").unwrap().try_into()?;
@ -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 =

Loading…
Cancel
Save