diff --git a/test/cases/000_smoke/010_ext/ext.bpf.c b/test/cases/000_smoke/010_ext/ext.bpf.c new file mode 100644 index 00000000..f0da9445 --- /dev/null +++ b/test/cases/000_smoke/010_ext/ext.bpf.c @@ -0,0 +1,11 @@ +#include +#include +#include + +SEC("xdp/drop") +int xdp_drop(struct xdp_md *ctx) +{ + return XDP_DROP; +} + +char _license[] SEC("license") = "GPL"; \ No newline at end of file diff --git a/test/cases/000_smoke/010_ext/ext.rs b/test/cases/000_smoke/010_ext/ext.rs new file mode 100755 index 00000000..909a848b --- /dev/null +++ b/test/cases/000_smoke/010_ext/ext.rs @@ -0,0 +1,24 @@ +//! ```cargo +//! [dependencies] +//! aya = { path = "../../../../aya" } +//! ``` + +use aya::{ + Bpf, BpfLoader, + programs::{Extension, ProgramFd, Xdp, XdpFlags}, +}; +use std::convert::TryInto; + +fn main() { + println!("Loading Root XDP program"); + let mut bpf = Bpf::load_file("main.o").unwrap(); + let pass: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); + pass.load().unwrap(); + pass.attach("lo", XdpFlags::default()).unwrap(); + + println!("Loading Extension Program"); + let mut bpf = BpfLoader::new().extension("drop").load_file("ext.o").unwrap(); + let drop_: &mut Extension = bpf.program_mut("drop").unwrap().try_into().unwrap(); + drop_.load(pass.fd().unwrap(), "xdp_pass").unwrap(); + println!("Success..."); +} diff --git a/test/cases/000_smoke/010_ext/main.bpf.c b/test/cases/000_smoke/010_ext/main.bpf.c new file mode 100644 index 00000000..fbe4600b --- /dev/null +++ b/test/cases/000_smoke/010_ext/main.bpf.c @@ -0,0 +1,11 @@ +#include +#include +#include + +SEC("xdp/pass") +int xdp_pass(struct xdp_md *ctx) +{ + return XDP_PASS; +} + +char _license[] SEC("license") = "GPL"; \ No newline at end of file diff --git a/test/cases/000_smoke/010_ext/test.sh b/test/cases/000_smoke/010_ext/test.sh new file mode 100755 index 00000000..d8d1559f --- /dev/null +++ b/test/cases/000_smoke/010_ext/test.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# SUMMARY: Check that a simple XDP program an be loaded +# LABELS: + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +NAME=ext + +clean_up() { + rm -rf main.o ${NAME}.o ${NAME} + exec_vm rm -f main.o ${NAME}.o ${NAME} +} + +trap clean_up EXIT + +# Test code goes here +compile_c_ebpf "$(pwd)/main.bpf.c" +compile_c_ebpf "$(pwd)/${NAME}.bpf.c" +compile_user "$(pwd)/${NAME}.rs" + +scp_vm main.o +scp_vm ${NAME}.o +scp_vm ${NAME} + +exec_vm sudo ./${NAME} + +exit 0 \ No newline at end of file