Skip to content

Commit 612c78d

Browse files
committed
feat: update latest aya
1 parent e515c5c commit 612c78d

File tree

2 files changed

+23
-5
lines changed
  • net-tc-filter/net-tc-filter-ebpf/src
  • sock-filter/sock-filter-ebpf/src

2 files changed

+23
-5
lines changed

net-tc-filter/net-tc-filter-ebpf/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,5 @@ const ETH_HDR_LEN: usize = mem::size_of::<ethhdr>();
143143

144144
#[panic_handler]
145145
fn panic(_info: &core::panic::PanicInfo) -> ! {
146-
unsafe { core::hint::unreachable_unchecked() }
146+
loop {}
147147
}

sock-filter/sock-filter-ebpf/src/main.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use aya_ebpf::{
99
maps::HashMap,
1010
programs::SkBuffContext,
1111
};
12-
use aya_log_ebpf::info;
12+
use aya_log_ebpf::{info, warn};
1313
mod bindings;
1414
use bindings::{ethhdr, iphdr, ipv6hdr};
1515

@@ -95,8 +95,26 @@ fn try_sock_egress(ctx: SkBuffContext) -> Result<i64, i64> {
9595
};
9696
// determine destination of the packet
9797
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+
}
100118
_ => 0,
101119
};
102120

@@ -144,5 +162,5 @@ const ETH_HDR_LEN: usize = mem::size_of::<ethhdr>();
144162

145163
#[panic_handler]
146164
fn panic(_info: &core::panic::PanicInfo) -> ! {
147-
unsafe { core::hint::unreachable_unchecked() }
165+
loop {}
148166
}

0 commit comments

Comments
 (0)