File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
net-tc-filter/net-tc-filter-ebpf/src
sock-filter/sock-filter-ebpf/src Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -143,5 +143,5 @@ const ETH_HDR_LEN: usize = mem::size_of::<ethhdr>();
143
143
144
144
#[ panic_handler]
145
145
fn panic ( _info : & core:: panic:: PanicInfo ) -> ! {
146
- unsafe { core :: hint :: unreachable_unchecked ( ) }
146
+ loop { }
147
147
}
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ use aya_ebpf::{
9
9
maps:: HashMap ,
10
10
programs:: SkBuffContext ,
11
11
} ;
12
- use aya_log_ebpf:: info;
12
+ use aya_log_ebpf:: { info, warn } ;
13
13
mod bindings;
14
14
use bindings:: { ethhdr, iphdr, ipv6hdr} ;
15
15
@@ -95,8 +95,26 @@ fn try_sock_egress(ctx: SkBuffContext) -> Result<i64, i64> {
95
95
} ;
96
96
// determine destination of the packet
97
97
let destination: u128 = match ip_version {
98
- 4 => u32:: from_be ( ctx. load ( ETH_HDR_LEN + offset_of ! ( iphdr, daddr) ) . unwrap ( ) ) as u128 ,
99
- 6 => u128:: from_be ( ctx. load ( ETH_HDR_LEN + offset_of ! ( ipv6hdr, daddr) ) . unwrap ( ) ) ,
98
+ 4 => {
99
+ let ipv4_bytes = match ctx. load ( ETH_HDR_LEN + offset_of ! ( iphdr, daddr) ) {
100
+ Ok ( bytes) => bytes,
101
+ Err ( _) => {
102
+ warn ! ( & ctx, "Internal error reading IPv4 header" ) ;
103
+ return Ok ( 0 ) ;
104
+ }
105
+ } ;
106
+ u32:: from_be ( ipv4_bytes) as u128
107
+ }
108
+ 6 => {
109
+ let ipv6_bytes = match ctx. load ( ETH_HDR_LEN + offset_of ! ( ipv6hdr, daddr) ) {
110
+ Ok ( bytes) => bytes,
111
+ Err ( _) => {
112
+ warn ! ( & ctx, "Internal error reading IPv6 header" ) ;
113
+ return Ok ( 0 ) ;
114
+ }
115
+ } ;
116
+ u128:: from_be ( ipv6_bytes)
117
+ }
100
118
_ => 0 ,
101
119
} ;
102
120
@@ -144,5 +162,5 @@ const ETH_HDR_LEN: usize = mem::size_of::<ethhdr>();
144
162
145
163
#[ panic_handler]
146
164
fn panic ( _info : & core:: panic:: PanicInfo ) -> ! {
147
- unsafe { core :: hint :: unreachable_unchecked ( ) }
165
+ loop { }
148
166
}
You can’t perform that action at this time.
0 commit comments