From 2b06925cab3c06917a5757b9df7b351ffe9f3e84 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 27 Oct 2024 14:38:36 +0100 Subject: [PATCH] fix tun mode --- CHANGELOG.md | 1 + src/messages.rs | 13 ++++++++++++- src/packet_sources/tun.rs | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8baae17..276dfb83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Unreleased: mitmproxy_rs next +- Assign a local IP address to our `tun` interface for Linux compatibility. ## 27 October 2024: mitmproxy_rs 0.10.0 diff --git a/src/messages.rs b/src/messages.rs index ae8dcba3..f38d03b5 100755 --- a/src/messages.rs +++ b/src/messages.rs @@ -1,4 +1,5 @@ use std::fmt; +use std::fmt::Formatter; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; use anyhow::{anyhow, Result}; @@ -112,12 +113,22 @@ impl TransportCommand { } /// Generic IPv4/IPv6 packet type that wraps smoltcp's IPv4 and IPv6 packet buffers -#[derive(Debug, Clone)] +#[derive(Clone)] pub enum SmolPacket { V4(Ipv4Packet>), V6(Ipv6Packet>), } +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() + } +} + impl From>> for SmolPacket { fn from(packet: Ipv4Packet>) -> Self { SmolPacket::V4(packet) diff --git a/src/packet_sources/tun.rs b/src/packet_sources/tun.rs index 010f61fe..4b47fa48 100644 --- a/src/packet_sources/tun.rs +++ b/src/packet_sources/tun.rs @@ -29,6 +29,8 @@ impl PacketSourceConf for TunConf { ) -> Result<(Self::Task, Self::Data)> { let mut config = tun2::Configuration::default(); config.mtu(MAX_PACKET_SIZE as u16); + // Setting a local address is required on Linux. + config.address("169.254.0.1"); config.up(); if let Some(tun_name) = self.tun_name { config.tun_name(&tun_name);