mirror of https://github.com/aya-rs/aya
commit
69cc844bbf
@ -0,0 +1,37 @@
|
||||
//! ```cargo
|
||||
//! [dependencies]
|
||||
//! aya-bpf = { path = "../../../../bpf/aya-bpf" }
|
||||
//! ```
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use aya_bpf::{
|
||||
bindings::xdp_action,
|
||||
macros::{map, xdp},
|
||||
programs::XdpContext,
|
||||
maps::Array,
|
||||
};
|
||||
|
||||
#[map]
|
||||
static mut FOO: Array<u32> = Array::<u32>::with_max_entries(10, 0);
|
||||
|
||||
#[map(name = "BAR")]
|
||||
static mut BAZ: Array<u32> = Array::<u32>::with_max_entries(10, 0);
|
||||
|
||||
#[xdp]
|
||||
pub fn pass(ctx: XdpContext) -> u32 {
|
||||
match unsafe { try_pass(ctx) } {
|
||||
Ok(ret) => ret,
|
||||
Err(_) => xdp_action::XDP_ABORTED,
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn try_pass(_ctx: XdpContext) -> Result<u32, u32> {
|
||||
Ok(xdp_action::XDP_PASS)
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
unsafe { core::hint::unreachable_unchecked() }
|
||||
}
|
Binary file not shown.
@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
# SUMMARY: Check that maps are correctly represented in ELF files
|
||||
# LABELS:
|
||||
|
||||
set -ex
|
||||
|
||||
# Source libraries. Uncomment if needed/defined
|
||||
#. "${RT_LIB}"
|
||||
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
|
||||
|
||||
NAME=map_test
|
||||
|
||||
clean_up() {
|
||||
rm -rf ebpf user ${NAME}.o
|
||||
}
|
||||
|
||||
trap clean_up EXIT
|
||||
|
||||
# Test code goes here
|
||||
compile_ebpf ${NAME}.ebpf.rs
|
||||
|
||||
readelf --sections ${NAME}.o | grep -q "maps"
|
||||
readelf --syms ${NAME}.o | grep -q "BAR"
|
||||
|
||||
exit 0
|
@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
# SUMMARY: Tests to check ELF from aya-bpf
|
||||
# LABELS:
|
||||
|
||||
# Source libraries. Uncomment if needed/defined
|
||||
# . "${RT_LIB}"
|
||||
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
|
||||
|
||||
set -e
|
||||
|
||||
group_init() {
|
||||
# Group initialisation code goes here
|
||||
return 0
|
||||
}
|
||||
|
||||
group_deinit() {
|
||||
# Group de-initialisation code goes here
|
||||
return 0
|
||||
}
|
||||
|
||||
CMD=$1
|
||||
case $CMD in
|
||||
init)
|
||||
group_init
|
||||
res=$?
|
||||
;;
|
||||
deinit)
|
||||
group_deinit
|
||||
res=$?
|
||||
;;
|
||||
*)
|
||||
res=1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit $res
|
Loading…
Reference in New Issue