Skip to content

Commit

Permalink
refine logging, add more debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Oct 27, 2024
1 parent df24e59 commit 3bccc86
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased: mitmproxy_rs next

- Add more debug info.

## 27 October 2024: mitmproxy_rs 0.10.2

Expand Down
35 changes: 26 additions & 9 deletions src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<InternetPacket>::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()
}
}
}
}

Expand Down Expand Up @@ -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
}
},
}
}

Expand Down
1 change: 1 addition & 0 deletions src/network/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}",
Expand Down

0 comments on commit 3bccc86

Please sign in to comment.