From 9e9bd5a2b872af2adcab8928f1241d864961e611 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Thu, 27 Jul 2023 15:09:55 -0400 Subject: [PATCH] putting together bpf loader --- protomask/Cargo.toml | 1 + protomask/src/bpf.rs | 15 +++++++++++++++ protomask/src/main.rs | 1 + 3 files changed, 17 insertions(+) create mode 100644 protomask/src/bpf.rs diff --git a/protomask/Cargo.toml b/protomask/Cargo.toml index 783a62b..bf0e9ce 100644 --- a/protomask/Cargo.toml +++ b/protomask/Cargo.toml @@ -17,3 +17,4 @@ tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread", "sync"] } clap = { version = "4.3.11", features = ["derive"] } aya = { git = "https://github.com/aya-rs/aya", rev = "f334cbd86ee8c83b29940ee80f0ab80a6d58e5d1", features = ["async_tokio"] } aya-log = { git = "https://github.com/aya-rs/aya", rev = "f334cbd86ee8c83b29940ee80f0ab80a6d58e5d1" } +cfg-if = "1.0.0" \ No newline at end of file diff --git a/protomask/src/bpf.rs b/protomask/src/bpf.rs new file mode 100644 index 0000000..5380869 --- /dev/null +++ b/protomask/src/bpf.rs @@ -0,0 +1,15 @@ +use aya::include_bytes_aligned; +use aya::Bpf; +use aya::BpfError; +use cfg_if::cfg_if; + +#[cfg(all(target_os = "linux", target_arch = "x86_64", debug_assertions))] +pub fn load_bpf() -> Result { + Bpf::load(&include_bytes_aligned!("../../target/bpfel-unknown-none/debug/protomask-ebpf")) +} + +#[cfg(all(target_os = "linux", target_arch = "x86_64", not(debug_assertions)))] +pub fn load_bpf() -> Result { + Bpf::load(&include_bytes_aligned!("../../target/bpfel-unknown-none/release/protomask-ebpf")) +} + diff --git a/protomask/src/main.rs b/protomask/src/main.rs index 9d38cbe..20a1e7b 100644 --- a/protomask/src/main.rs +++ b/protomask/src/main.rs @@ -1,3 +1,4 @@ +mod bpf; #[tokio::main] pub async fn main(){