diff --git a/tcbpftest/Cargo.toml b/tcbpftest/Cargo.toml index 975b474..308c754 100644 --- a/tcbpftest/Cargo.toml +++ b/tcbpftest/Cargo.toml @@ -5,7 +5,8 @@ edition = "2021" publish = false [dependencies] -aya = { version = ">=0.11", features = ["async_tokio"] } +aya = { git = "https://github.com/aya-rs/aya", features = ["async_tokio"] } +aya-log = { git = "https://github.com/aya-rs/aya" } tcbpftest-common = { path = "../tcbpftest-common", features = ["user"] } anyhow = "1" bytes = "1" diff --git a/tcbpftest/src/main.rs b/tcbpftest/src/main.rs index a8e07b7..9cd87be 100644 --- a/tcbpftest/src/main.rs +++ b/tcbpftest/src/main.rs @@ -5,9 +5,10 @@ use aya::{ util::online_cpus, Bpf, }; +use aya_log::BpfLogger; use bytes::BytesMut; use clap::Parser; -use log::info; +use log::{info, warn}; use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode}; use std::net::Ipv4Addr; use tokio::{signal, task}; @@ -46,10 +47,14 @@ async fn main() -> Result<(), anyhow::Error> { let mut bpf = Bpf::load(include_bytes_aligned!( "../../target/bpfel-unknown-none/release/tcbpftest" ))?; + if let Err(e) = BpfLogger::init(&mut bpf) { + // This can happen if you remove all log statements from your eBPF program. + warn!("failed to initialize eBPF logger: {}", e); + } // error adding clsact to the interface if it is already added is harmless // the full cleanup can be done with 'sudo tc qdisc del dev eth0 clsact'. let _ = tc::qdisc_add_clsact(&args.iface); - // this is just for information and debugging - show the found programs. + // this is just for information and debugging - show all the found programs. for (name, program) in bpf.programs() { println!( "[INFO] found program `{}` of type `{:?}`", @@ -57,12 +62,11 @@ async fn main() -> Result<(), anyhow::Error> { program.prog_type() ); } - let program: &mut SchedClassifier = bpf.program_mut("classifier").unwrap().try_into()?; + let program: &mut SchedClassifier = bpf.program_mut("tcbpftest").unwrap().try_into()?; program.load()?; - // program.attach(&args.iface, TcAttachType::Egress)?; program.attach(&args.iface, TcAttachType::Ingress)?; - let mut perf_array = AsyncPerfEventArray::try_from(bpf.map_mut("EVENTS").unwrap())?; + let mut perf_array = AsyncPerfEventArray::try_from(bpf.take_map("EVENTS").unwrap())?; let cpus = online_cpus()?; let num_cpus = cpus.len();