From f38ddae97785fb031def98b4cd4f7ef62b28047d Mon Sep 17 00:00:00 2001 From: Dmitry Savintsev Date: Wed, 2 Aug 2023 14:28:04 +0200 Subject: [PATCH] refactor for the new API (#22) * refactor for the new aya API --- tcbpftest-ebpf/src/main.rs | 6 +++--- tcbpftest/src/main.rs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tcbpftest-ebpf/src/main.rs b/tcbpftest-ebpf/src/main.rs index 8634d15..eebed0a 100644 --- a/tcbpftest-ebpf/src/main.rs +++ b/tcbpftest-ebpf/src/main.rs @@ -26,14 +26,14 @@ use tcbpftest_common::PacketLog; #[allow(dead_code)] #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { - unreachable!() + unsafe { core::hint::unreachable_unchecked() } } -#[map(name = "EVENTS")] +#[map] static mut EVENTS: PerfEventArray = PerfEventArray::::with_max_entries(1024, 0); -#[classifier(name = "tcbpftest")] +#[classifier] pub fn tcbpftest(ctx: TcContext) -> i32 { match unsafe { try_tcbpftest(ctx) } { Ok(ret) => ret, diff --git a/tcbpftest/src/main.rs b/tcbpftest/src/main.rs index 023ae17..a8e07b7 100644 --- a/tcbpftest/src/main.rs +++ b/tcbpftest/src/main.rs @@ -49,12 +49,20 @@ async fn main() -> Result<(), anyhow::Error> { // 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); - let program: &mut SchedClassifier = bpf.program_mut("tcbpftest").unwrap().try_into()?; + // this is just for information and debugging - show the found programs. + for (name, program) in bpf.programs() { + println!( + "[INFO] found program `{}` of type `{:?}`", + name, + program.prog_type() + ); + } + let program: &mut SchedClassifier = bpf.program_mut("classifier").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")?)?; + let mut perf_array = AsyncPerfEventArray::try_from(bpf.map_mut("EVENTS").unwrap())?; let cpus = online_cpus()?; let num_cpus = cpus.len();