Skip to content

Commit

Permalink
feat: update latest aya
Browse files Browse the repository at this point in the history
  • Loading branch information
jornfranke committed Nov 10, 2024
1 parent e515c5c commit 612c78d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion net-tc-filter/net-tc-filter-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,5 @@ const ETH_HDR_LEN: usize = mem::size_of::<ethhdr>();

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}
26 changes: 22 additions & 4 deletions sock-filter/sock-filter-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -95,8 +95,26 @@ fn try_sock_egress(ctx: SkBuffContext) -> Result<i64, i64> {
};
// 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,
};

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

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

0 comments on commit 612c78d

Please sign in to comment.