Merge pull request #248 from dave-tucker/map_sec

bpf: Maps live in maps section
pull/250/head
Alessandro Decina 3 years ago committed by GitHub
commit 69cc844bbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -49,11 +49,13 @@ impl Map {
}
pub fn expand(&self) -> Result<TokenStream> {
let section_name = format!("maps/{}", self.name);
let section_name = "maps".to_string();
let name = &self.name;
let item = &self.item;
Ok(quote! {
#[no_mangle]
#[link_section = #section_name]
#[export_name = #name]
#item
})
}

@ -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() }
}

@ -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…
Cancel
Save