diff --git a/dataplane/ebpf/src/egress/icmp.rs b/dataplane/ebpf/src/egress/icmp.rs index bc8c1dd5..1dc2ea58 100644 --- a/dataplane/ebpf/src/egress/icmp.rs +++ b/dataplane/ebpf/src/egress/icmp.rs @@ -9,7 +9,7 @@ use aya_log_ebpf::info; use crate::{ bindings::{iphdr, icmphdr}, - utils::{csum_fold_helper, ip_from_int, ptr_at, ETH_HDR_LEN, IP_HDR_LEN}, + utils::{csum_fold_helper, ptr_at, ETH_HDR_LEN, IP_HDR_LEN}, BLIXT_CONNTRACK, }; @@ -38,16 +38,8 @@ pub fn handle_icmp_egress(ctx: TcContext) -> Result { let new_src = unsafe { BLIXT_CONNTRACK.get(&dest_addr) }.ok_or(TC_ACT_PIPE)?; - let daddr_dot_dec = ip_from_int(unsafe { (*ip_hdr).daddr }); - info!( - &ctx, - "Received a ICMP Unreachable packet destined for svc ip: {}.{}.{}.{}", - daddr_dot_dec[0], - daddr_dot_dec[1], - daddr_dot_dec[2], - daddr_dot_dec[3], - ); - + info!(&ctx, "Received a ICMP Unreachable packet destined for svc ip: {:ipv4} ", u32::from_be(unsafe { (*ip_hdr).daddr })); + // redirect icmp unreachable message back to client unsafe { (*ip_hdr).saddr = *new_src; diff --git a/dataplane/ebpf/src/ingress/tcp.rs b/dataplane/ebpf/src/ingress/tcp.rs index 4be1ffce..499856d7 100644 --- a/dataplane/ebpf/src/ingress/tcp.rs +++ b/dataplane/ebpf/src/ingress/tcp.rs @@ -9,7 +9,7 @@ use aya_log_ebpf::info; use crate::{ bindings::{iphdr, tcphdr}, - utils::{csum_fold_helper, ip_from_int, ptr_at, ETH_HDR_LEN, IP_HDR_LEN}, + utils::{csum_fold_helper, ptr_at, ETH_HDR_LEN, IP_HDR_LEN}, BACKENDS, }; use common::BackendKey; @@ -28,16 +28,7 @@ pub fn handle_tcp_ingress(ctx: TcContext) -> Result { let backend = unsafe { BACKENDS.get(&key) }.ok_or(TC_ACT_OK)?; - let daddr_dot_dec = ip_from_int(unsafe { (*ip_hdr).daddr }); - info!( - &ctx, - "Received a TCP packet destined for svc ip: {}.{}.{}.{} at port: {}", - daddr_dot_dec[0], - daddr_dot_dec[1], - daddr_dot_dec[2], - daddr_dot_dec[3], - u16::from_be(unsafe { (*tcp_hdr).dest }) - ); + info!(&ctx, "Received a TCP packet destined for svc ip: {:ipv4} at Port: {} ", u32::from_be(unsafe { (*ip_hdr).daddr }), u16::from_be(unsafe { (*tcp_hdr).dest} )); unsafe { (*ip_hdr).daddr = backend.daddr.to_be(); diff --git a/dataplane/ebpf/src/ingress/udp.rs b/dataplane/ebpf/src/ingress/udp.rs index 847e826f..bd07d383 100644 --- a/dataplane/ebpf/src/ingress/udp.rs +++ b/dataplane/ebpf/src/ingress/udp.rs @@ -9,7 +9,7 @@ use aya_log_ebpf::info; use crate::{ bindings::{iphdr, udphdr}, - utils::{csum_fold_helper, ip_from_int, ptr_at, ETH_HDR_LEN, IP_HDR_LEN}, + utils::{csum_fold_helper, ptr_at, ETH_HDR_LEN, IP_HDR_LEN}, BACKENDS, BLIXT_CONNTRACK, }; @@ -30,17 +30,8 @@ pub fn handle_udp_ingress(ctx: TcContext) -> Result { }; let backend = unsafe { BACKENDS.get(&key) }.ok_or(TC_ACT_PIPE)?; - - let daddr_dot_dec = ip_from_int(unsafe { (*ip_hdr).daddr }); - info!( - &ctx, - "Received a UDP packet destined for svc ip: {}.{}.{}.{} at port: {}", - daddr_dot_dec[0], - daddr_dot_dec[1], - daddr_dot_dec[2], - daddr_dot_dec[3], - u16::from_be(unsafe { (*udp_hdr).dest }) - ); + + info!(&ctx, "Received a UDP packet destined for svc ip: {:ipv4} at Port: {} ", u32::from_be(unsafe { (*ip_hdr).daddr }), u16::from_be(unsafe { (*udp_hdr).dest} )); unsafe { BLIXT_CONNTRACK.insert(&(*ip_hdr).saddr, &original_daddr, 0 as u64)?; diff --git a/dataplane/ebpf/src/utils.rs b/dataplane/ebpf/src/utils.rs index 256caa6b..29e698df 100644 --- a/dataplane/ebpf/src/utils.rs +++ b/dataplane/ebpf/src/utils.rs @@ -35,21 +35,6 @@ pub unsafe fn ptr_at(ctx: &TcContext, offset: usize) -> Result<*mut T, i64> { Ok((start + offset) as *mut T) } -// Produces an IPv4 address as a [u8;4] which is easy to print out in -// dot-decimal notation using the info!() macro. -// -// TODO: use a type alias and implement print formatting for this? -#[inline(always)] -pub fn ip_from_int(ip: u32) -> [u8; 4] { - let mut addr: [u8; 4] = [0; 4]; - - addr[0] = ((ip >> 0) & 0xFF) as u8; - addr[1] = ((ip >> 8) & 0xFF) as u8; - addr[2] = ((ip >> 16) & 0xFF) as u8; - addr[3] = ((ip >> 24) & 0xFF) as u8; - - addr -} // Converts a checksum into u16 #[inline(always)]