Skip to content

Commit

Permalink
re-add debug assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Oct 28, 2024
1 parent 4c9fe48 commit 826b387
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 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

- tun mode: re-add debug logging.

## 27 October 2024: mitmproxy_rs 0.10.5

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ prost = "0.13.3"
tokio-util = { version = "0.7.12", features = ["codec"] }
futures-util = { version = "0.3.30", features = ["sink"] }
lru_time_cache = "0.11.11"
internet-packet = { version = "0.2.0", features = ["smoltcp"] }
internet-packet = { version = "0.2.0", features = ["smoltcp", "internet-checksum"] }
data-encoding = "2.4.0"
hickory-resolver = "0.24.1"
socket2 = "0.5.7"
Expand Down
23 changes: 19 additions & 4 deletions src/packet_sources/tun.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{Context, Result};
use internet_packet::InternetPacket;
use crate::messages::{
NetworkCommand, NetworkEvent, SmolPacket, TransportCommand, TransportEvent, TunnelInfo,
};
Expand Down Expand Up @@ -29,9 +30,9 @@ impl PacketSourceConf for TunConf {
let mut config = tun2::Configuration::default();
config.mtu(MAX_PACKET_SIZE as u16);
// Setting a local address and a destination is required on Linux.
config.address("169.254.0.2");
config.destination("169.254.0.1");
config.netmask("0.0.0.0");
config.address("169.254.0.1");
// config.netmask("0.0.0.0");
// config.destination("169.254.0.1");
config.up();
if let Some(tun_name) = self.tun_name {
config.tun_name(&tun_name);
Expand Down Expand Up @@ -91,6 +92,7 @@ impl PacketSourceTask for TunTask {
log::error!("Skipping invalid packet from tun interface: {:?}", &buf[..len]);
continue;
};
dbg!(&packet);
permit.take().unwrap().send(NetworkEvent::ReceivePacket {
packet,
tunnel_info: TunnelInfo::None,
Expand All @@ -107,7 +109,20 @@ impl PacketSourceTask for TunTask {
Some(command) = self.net_rx.recv(), if packet_to_send.is_empty() => {
match command {
NetworkCommand::SendPacket(packet) => {
packet_to_send = packet.into_inner();
dbg!(&packet);
// FIXME: Speculative checksum fix
match TryInto::<InternetPacket>::try_into(packet.clone()) {
Ok(mut p) => {
p.recalculate_tcp_checksum();
p.recalculate_udp_checksum();
p.recalculate_ip_checksum();
dbg!("checksum fixed");
packet_to_send = p.inner();
}
Err(_) => {
packet_to_send = packet.into_inner();
}
}
}
}
}
Expand Down

0 comments on commit 826b387

Please sign in to comment.