File tree Expand file tree Collapse file tree 5 files changed +101
-1
lines changed Expand file tree Collapse file tree 5 files changed +101
-1
lines changed Original file line number Diff line number Diff line change @@ -49,11 +49,13 @@ impl Map {
49
49
}
50
50
51
51
pub fn expand ( & self ) -> Result < TokenStream > {
52
- let section_name = format ! ( "maps/{}" , self . name) ;
52
+ let section_name = "maps" . to_string ( ) ;
53
+ let name = & self . name ;
53
54
let item = & self . item ;
54
55
Ok ( quote ! {
55
56
#[ no_mangle]
56
57
#[ link_section = #section_name]
58
+ #[ export_name = #name]
57
59
#item
58
60
} )
59
61
}
Original file line number Diff line number Diff line change
1
+ //! ```cargo
2
+ //! [dependencies]
3
+ //! aya-bpf = { path = "../../../../bpf/aya-bpf" }
4
+ //! ```
5
+
6
+ #![ no_std]
7
+ #![ no_main]
8
+
9
+ use aya_bpf:: {
10
+ bindings:: xdp_action,
11
+ macros:: { map, xdp} ,
12
+ programs:: XdpContext ,
13
+ maps:: Array ,
14
+ } ;
15
+
16
+ #[ map]
17
+ static mut FOO : Array < u32 > = Array :: < u32 > :: with_max_entries ( 10 , 0 ) ;
18
+
19
+ #[ map( name = "BAR" ) ]
20
+ static mut BAZ : Array < u32 > = Array :: < u32 > :: with_max_entries ( 10 , 0 ) ;
21
+
22
+ #[ xdp]
23
+ pub fn pass ( ctx : XdpContext ) -> u32 {
24
+ match unsafe { try_pass ( ctx) } {
25
+ Ok ( ret) => ret,
26
+ Err ( _) => xdp_action:: XDP_ABORTED ,
27
+ }
28
+ }
29
+
30
+ unsafe fn try_pass ( _ctx : XdpContext ) -> Result < u32 , u32 > {
31
+ Ok ( xdp_action:: XDP_PASS )
32
+ }
33
+
34
+ #[ panic_handler]
35
+ fn panic ( _info : & core:: panic:: PanicInfo ) -> ! {
36
+ unsafe { core:: hint:: unreachable_unchecked ( ) }
37
+ }
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ # SUMMARY: Check that maps are correctly represented in ELF files
3
+ # LABELS:
4
+
5
+ set -ex
6
+
7
+ # Source libraries. Uncomment if needed/defined
8
+ # . "${RT_LIB}"
9
+ . " ${RT_PROJECT_ROOT} /_lib/lib.sh"
10
+
11
+ NAME=map_test
12
+
13
+ clean_up () {
14
+ rm -rf ebpf user ${NAME} .o
15
+ }
16
+
17
+ trap clean_up EXIT
18
+
19
+ # Test code goes here
20
+ compile_ebpf ${NAME} .ebpf.rs
21
+
22
+ readelf --sections ${NAME} .o | grep -q " maps"
23
+ readelf --syms ${NAME} .o | grep -q " BAR"
24
+
25
+ exit 0
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ # SUMMARY: Tests to check ELF from aya-bpf
3
+ # LABELS:
4
+
5
+ # Source libraries. Uncomment if needed/defined
6
+ # . "${RT_LIB}"
7
+ . " ${RT_PROJECT_ROOT} /_lib/lib.sh"
8
+
9
+ set -e
10
+
11
+ group_init () {
12
+ # Group initialisation code goes here
13
+ return 0
14
+ }
15
+
16
+ group_deinit () {
17
+ # Group de-initialisation code goes here
18
+ return 0
19
+ }
20
+
21
+ CMD=$1
22
+ case $CMD in
23
+ init)
24
+ group_init
25
+ res=$?
26
+ ;;
27
+ deinit)
28
+ group_deinit
29
+ res=$?
30
+ ;;
31
+ * )
32
+ res=1
33
+ ;;
34
+ esac
35
+
36
+ exit $res
You can’t perform that action at this time.
0 commit comments