Skip to content

Commit

Permalink
fix for the new Aya API (#24)
Browse files Browse the repository at this point in the history
* refactor for the new API
  • Loading branch information
dmitris authored Aug 2, 2023
1 parent f38ddae commit ad25e6e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tcbpftest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 9 additions & 5 deletions tcbpftest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -46,23 +47,26 @@ 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 `{:?}`",
name,
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();
Expand Down

0 comments on commit ad25e6e

Please sign in to comment.