Skip to content

Commit

Permalink
fix tun mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Oct 27, 2024
1 parent 7a1c2e0 commit 2b06925
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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

- Assign a local IP address to our `tun` interface for Linux compatibility.

## 27 October 2024: mitmproxy_rs 0.10.0

Expand Down
13 changes: 12 additions & 1 deletion src/messages.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt;
use std::fmt::Formatter;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};

use anyhow::{anyhow, Result};
Expand Down Expand Up @@ -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<Vec<u8>>),
V6(Ipv6Packet<Vec<u8>>),
}

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<Ipv4Packet<Vec<u8>>> for SmolPacket {
fn from(packet: Ipv4Packet<Vec<u8>>) -> Self {
SmolPacket::V4(packet)
Expand Down
2 changes: 2 additions & 0 deletions src/packet_sources/tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2b06925

Please sign in to comment.