From 3bccc86b673ac1cf7061538fccbede400e152280 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 27 Oct 2024 15:48:08 +0100 Subject: [PATCH] refine logging, add more debug logs --- CHANGELOG.md | 1 + src/messages.rs | 35 ++++++++++++++++++++++++++--------- src/network/core.rs | 1 + 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5005b383..4faef441 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Unreleased: mitmproxy_rs next +- Add more debug info. ## 27 October 2024: mitmproxy_rs 0.10.2 diff --git a/src/messages.rs b/src/messages.rs index f38d03b5..bfe5c53e 100755 --- a/src/messages.rs +++ b/src/messages.rs @@ -121,11 +121,24 @@ pub enum SmolPacket { impl fmt::Debug for SmolPacket { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - f.debug_struct("SmolPacket") - .field("src_ip", &self.src_ip()) - .field("dst_ip", &self.dst_ip()) - .field("transport_protocol", &self.transport_protocol()) - .finish() + + match TryInto::::try_into(self.clone()) { + Ok(p) => { + f.debug_struct("SmolPacket") + .field("src", &p.src()) + .field("dst", &p.dst()) + .field("protocol", &p.protocol()) + .field("tcp_flags_str", &p.tcp_flag_str()) + .finish() + } + Err(_) => { + f.debug_struct("SmolPacket") + .field("src_ip", &self.src_ip()) + .field("dst_ip", &self.dst_ip()) + .field("transport_protocol", &self.transport_protocol()) + .finish() + } + } } } @@ -186,10 +199,14 @@ impl SmolPacket { pub fn transport_protocol(&self) -> IpProtocol { match self { SmolPacket::V4(packet) => packet.next_header(), - SmolPacket::V6(packet) => { - log::debug!("TODO: Implement IPv6 next_header logic."); - packet.next_header() - } + SmolPacket::V6(packet) => match packet.next_header() { + IpProtocol::Tcp => IpProtocol::Tcp, + IpProtocol::Udp => IpProtocol::Udp, + other => { + log::debug!("TODO: Implement IPv6 next_header logic: {}", other); + other + } + }, } } diff --git a/src/network/core.rs b/src/network/core.rs index c9f62a36..f4d2b76f 100644 --- a/src/network/core.rs +++ b/src/network/core.rs @@ -58,6 +58,7 @@ impl<'a> NetworkStack<'a> { Ok(()) } IpProtocol::Icmp => self.receive_packet_icmp(packet), + IpProtocol::Icmpv6 => self.receive_packet_icmp(packet), _ => { log::debug!( "Received IP packet for unknown protocol: {}",