Skip to content

Commit

Permalink
refactor for the new API (#22)
Browse files Browse the repository at this point in the history
* refactor for the new aya API
  • Loading branch information
dmitris authored Aug 2, 2023
1 parent 89e3927 commit f38ddae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions tcbpftest-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PacketLog> =
PerfEventArray::<PacketLog>::with_max_entries(1024, 0);

#[classifier(name = "tcbpftest")]
#[classifier]
pub fn tcbpftest(ctx: TcContext) -> i32 {
match unsafe { try_tcbpftest(ctx) } {
Ok(ret) => ret,
Expand Down
12 changes: 10 additions & 2 deletions tcbpftest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f38ddae

Please sign in to comment.