File tree Expand file tree Collapse file tree 9 files changed +26
-17
lines changed
cgroup-skb-egress/cgroup-skb-egress-ebpf/src
kprobetcp/kprobetcp-ebpf/src
lsm-nice/lsm-nice-ebpf/src
tc-egress/tc-egress-ebpf/src
xdp-drop/xdp-drop-ebpf/src
xdp-hello/xdp-hello-ebpf/src Expand file tree Collapse file tree 9 files changed +26
-17
lines changed Original file line number Diff line number Diff line change @@ -24,11 +24,12 @@ The logic for this program is located in `xdp-hello-ebpf/src/main.rs` and curren
24
24
25
25
1 . ` #![no_std] ` is required since we cannot use the standard library.
26
26
2 . ` #![no_main] ` is required as we have no main function.
27
- 3 . The ` #[panic_handler] ` is required to keep the compiler happy, although it is never used since we cannot panic.
28
- 4 . This indicates that this function is an XDP program.
29
- 5 . Our main entry point defers to another function and performs error handling, returning ` XDP_ABORTED ` , which will drop the packet.
30
- 6 . Write a log entry every time a packet is received.
31
- 7 . This function returns a ` Result ` that permits all traffic.
27
+ 3 . ` #![no_builtins] ` is required as we cannot use LLVM intrinsics.
28
+ 4 . The ` #[panic_handler] ` is required to keep the compiler happy, although it is never used since we cannot panic.
29
+ 5 . This indicates that this function is an XDP program.
30
+ 6 . Our main entry point defers to another function and performs error handling, returning ` XDP_ABORTED ` , which will drop the packet.
31
+ 7 . Write a log entry every time a packet is received.
32
+ 8 . This function returns a ` Result ` that permits all traffic.
32
33
33
34
Now we can compile this using ` cargo xtask build-ebpf ` .
34
35
Original file line number Diff line number Diff line change 1
- #![ no_std ]
1
+ #![ no_builtins ]
2
2
#![ no_main]
3
+ #![ no_std]
3
4
4
5
#[ allow( non_upper_case_globals) ]
5
6
#[ allow( non_snake_case) ]
Original file line number Diff line number Diff line change 1
- #![ no_std ]
1
+ #![ no_builtins ]
2
2
#![ no_main]
3
+ #![ no_std]
3
4
4
5
use aya_bpf:: {
5
6
macros:: { cgroup_skb, map} ,
Original file line number Diff line number Diff line change 1
- #![ no_std ]
1
+ #![ no_builtins ]
2
2
#![ no_main]
3
+ #![ no_std]
3
4
4
5
#[ allow( non_upper_case_globals) ]
5
6
#[ allow( non_snake_case) ]
Original file line number Diff line number Diff line change 1
- #![ no_std ]
1
+ #![ no_builtins ]
2
2
#![ no_main]
3
+ #![ no_std]
3
4
4
5
use aya_bpf:: { cty:: c_int, macros:: lsm, programs:: LsmContext } ;
5
6
use aya_log_ebpf:: info;
Original file line number Diff line number Diff line change 1
- #![ no_std ]
1
+ #![ no_builtins ]
2
2
#![ no_main]
3
+ #![ no_std]
3
4
4
5
use aya_bpf:: {
5
6
bindings:: { TC_ACT_PIPE , TC_ACT_SHOT } ,
Original file line number Diff line number Diff line change 1
- #![ no_std ]
1
+ #![ no_builtins ]
2
2
#![ no_main]
3
+ #![ no_std]
3
4
#![ allow( nonstandard_style, dead_code) ]
4
5
5
6
use aya_bpf:: {
Original file line number Diff line number Diff line change 1
1
#![ no_std] // (1)
2
2
#![ no_main] // (2)
3
+ #![ no_builtins] // (3)
3
4
4
5
use aya_bpf:: { bindings:: xdp_action, macros:: xdp, programs:: XdpContext } ;
5
6
use aya_log_ebpf:: info;
6
7
7
- #[ xdp( name = "xdp_hello" ) ] // (4 )
8
+ #[ xdp( name = "xdp_hello" ) ] // (5 )
8
9
pub fn xdp_hello ( ctx : XdpContext ) -> u32 {
9
- // (5 )
10
+ // (6 )
10
11
match unsafe { try_xdp_hello ( ctx) } {
11
12
Ok ( ret) => ret,
12
13
Err ( _) => xdp_action:: XDP_ABORTED ,
13
14
}
14
15
}
15
16
16
17
unsafe fn try_xdp_hello ( ctx : XdpContext ) -> Result < u32 , u32 > {
17
- // (6)
18
- info ! ( & ctx, "received a packet" ) ;
19
18
// (7)
19
+ info ! ( & ctx, "received a packet" ) ;
20
+ // (8)
20
21
Ok ( xdp_action:: XDP_PASS )
21
22
}
22
23
23
- #[ panic_handler] // (3 )
24
+ #[ panic_handler] // (4 )
24
25
fn panic ( _info : & core:: panic:: PanicInfo ) -> ! {
25
26
unsafe { core:: hint:: unreachable_unchecked ( ) }
26
27
}
Original file line number Diff line number Diff line change 1
- #![ no_std ]
1
+ #![ no_builtins ]
2
2
#![ no_main]
3
+ #![ no_std]
3
4
4
5
use aya_bpf:: { bindings:: xdp_action, macros:: xdp, programs:: XdpContext } ;
5
6
use aya_log_ebpf:: info;
You can’t perform that action at this time.
0 commit comments