From 612c78daedc10f6de2ec2fc7059a02de0be32c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Franke?= Date: Sun, 10 Nov 2024 18:17:33 +0100 Subject: [PATCH] feat: update latest aya --- net-tc-filter/net-tc-filter-ebpf/src/main.rs | 2 +- sock-filter/sock-filter-ebpf/src/main.rs | 26 +++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/net-tc-filter/net-tc-filter-ebpf/src/main.rs b/net-tc-filter/net-tc-filter-ebpf/src/main.rs index da363aa..050cc3c 100644 --- a/net-tc-filter/net-tc-filter-ebpf/src/main.rs +++ b/net-tc-filter/net-tc-filter-ebpf/src/main.rs @@ -143,5 +143,5 @@ const ETH_HDR_LEN: usize = mem::size_of::(); #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { - unsafe { core::hint::unreachable_unchecked() } + loop {} } diff --git a/sock-filter/sock-filter-ebpf/src/main.rs b/sock-filter/sock-filter-ebpf/src/main.rs index 70a745c..e4581bd 100644 --- a/sock-filter/sock-filter-ebpf/src/main.rs +++ b/sock-filter/sock-filter-ebpf/src/main.rs @@ -9,7 +9,7 @@ use aya_ebpf::{ maps::HashMap, programs::SkBuffContext, }; -use aya_log_ebpf::info; +use aya_log_ebpf::{info, warn}; mod bindings; use bindings::{ethhdr, iphdr, ipv6hdr}; @@ -95,8 +95,26 @@ fn try_sock_egress(ctx: SkBuffContext) -> Result { }; // determine destination of the packet let destination: u128 = match ip_version { - 4 => u32::from_be(ctx.load(ETH_HDR_LEN + offset_of!(iphdr, daddr)).unwrap()) as u128, - 6 => u128::from_be(ctx.load(ETH_HDR_LEN + offset_of!(ipv6hdr, daddr)).unwrap()), + 4 => { + let ipv4_bytes = match ctx.load(ETH_HDR_LEN + offset_of!(iphdr, daddr)) { + Ok(bytes) => bytes, + Err(_) => { + warn!(&ctx, "Internal error reading IPv4 header"); + return Ok(0); + } + }; + u32::from_be(ipv4_bytes) as u128 + } + 6 => { + let ipv6_bytes = match ctx.load(ETH_HDR_LEN + offset_of!(ipv6hdr, daddr)) { + Ok(bytes) => bytes, + Err(_) => { + warn!(&ctx, "Internal error reading IPv6 header"); + return Ok(0); + } + }; + u128::from_be(ipv6_bytes) + } _ => 0, }; @@ -144,5 +162,5 @@ const ETH_HDR_LEN: usize = mem::size_of::(); #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { - unsafe { core::hint::unreachable_unchecked() } + loop {} }