mirror of https://github.com/aya-rs/aya
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.4 KiB
Rust
42 lines
1.4 KiB
Rust
3 years ago
|
use aya::{
|
||
|
include_bytes_aligned,
|
||
|
programs::{Extension, Xdp, XdpFlags},
|
||
|
Bpf, BpfLoader,
|
||
|
};
|
||
|
|
||
2 years ago
|
mod common;
|
||
|
use common::kernel_version;
|
||
3 years ago
|
|
||
2 years ago
|
#[test]
|
||
2 years ago
|
fn xdp() {
|
||
2 years ago
|
let bytes = include_bytes_aligned!("../../../target/bpfel-unknown-none/release/pass");
|
||
2 years ago
|
let mut bpf = Bpf::load(bytes).unwrap();
|
||
3 years ago
|
let dispatcher: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
|
||
|
dispatcher.load().unwrap();
|
||
|
dispatcher.attach("lo", XdpFlags::default()).unwrap();
|
||
|
}
|
||
|
|
||
2 years ago
|
#[test]
|
||
2 years ago
|
fn extension() {
|
||
|
let (major, minor, _) = kernel_version().unwrap();
|
||
2 years ago
|
if major < 5 || (minor == 5 && minor < 9) {
|
||
2 years ago
|
eprintln!(
|
||
3 years ago
|
"skipping as {}.{} does not meet version requirement of 5.9",
|
||
|
major, minor
|
||
|
);
|
||
2 years ago
|
return;
|
||
3 years ago
|
}
|
||
|
// TODO: Check kernel version == 5.9 or later
|
||
|
let main_bytes =
|
||
2 years ago
|
include_bytes_aligned!("../../../target/bpfel-unknown-none/release/main.bpf.o");
|
||
2 years ago
|
let mut bpf = Bpf::load(main_bytes).unwrap();
|
||
3 years ago
|
let pass: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
|
||
|
pass.load().unwrap();
|
||
|
pass.attach("lo", XdpFlags::default()).unwrap();
|
||
|
|
||
2 years ago
|
let ext_bytes = include_bytes_aligned!("../../../target/bpfel-unknown-none/release/ext.bpf.o");
|
||
3 years ago
|
let mut bpf = BpfLoader::new().extension("drop").load(ext_bytes).unwrap();
|
||
|
let drop_: &mut Extension = bpf.program_mut("drop").unwrap().try_into().unwrap();
|
||
|
drop_.load(pass.fd().unwrap(), "xdp_pass").unwrap();
|
||
|
}
|