mirror of https://github.com/aya-rs/aya
test: Add smoke test for BPF_PROG_TYPE_EXT
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>pull/182/head
parent
657fb44525
commit
4bad464c92
@ -0,0 +1,11 @@
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_endian.h>
|
||||
|
||||
SEC("xdp/drop")
|
||||
int xdp_drop(struct xdp_md *ctx)
|
||||
{
|
||||
return XDP_DROP;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
@ -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...");
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_endian.h>
|
||||
|
||||
SEC("xdp/pass")
|
||||
int xdp_pass(struct xdp_md *ctx)
|
||||
{
|
||||
return XDP_PASS;
|
||||
}
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
@ -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
|
Loading…
Reference in New Issue