forked from aya-rs/aya
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This forces all maps to the maps section so we remain compatible with libbpf. This requires aya-rs#181 to avoid breaking userspace. Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
- Loading branch information
1 parent
5472ac0
commit f12c026
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |