summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2024-10-03 12:53:09 +0200
committerDavid Lönnhager <david.l@mullvad.net>2024-10-04 16:15:47 +0200
commit6fa34faa00229306d3a2fd84b664570b0327d61e (patch)
treed80caaf5f573b414eaf59cdb462c367f4a3cb5a2
parent0e32a2114752c7fc55b71c9f065613ff777f7cd0 (diff)
downloadmullvadvpn-6fa34faa00229306d3a2fd84b664570b0327d61e.tar.xz
mullvadvpn-6fa34faa00229306d3a2fd84b664570b0327d61e.zip
Do not duplicate incoming ICMP
-rw-r--r--talpid-core/src/split_tunnel/macos/tun.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/talpid-core/src/split_tunnel/macos/tun.rs b/talpid-core/src/split_tunnel/macos/tun.rs
index 0e260a1517..2482fadcb7 100644
--- a/talpid-core/src/split_tunnel/macos/tun.rs
+++ b/talpid-core/src/split_tunnel/macos/tun.rs
@@ -19,10 +19,11 @@ use pnet_packet::{
udp::MutableUdpPacket,
MutablePacket, Packet,
};
+use talpid_types::net::{ALLOWED_LAN_NETS, ALLOWED_LAN_MULTICAST_NETS};
use std::{
ffi::{c_uint, CStr},
io::{self, IoSlice, Write},
- net::{Ipv4Addr, Ipv6Addr},
+ net::{Ipv4Addr, Ipv6Addr, IpAddr},
};
use talpid_routing::RouteManagerHandle;
use tokio::{
@@ -676,6 +677,9 @@ async fn handle_incoming_data_v4(
log::trace!("Dropping packet to VPN IP on default interface");
return;
}
+ if is_non_vpn_destination(IpAddr::from(ip.get_destination())) {
+ return;
+ }
fix_ipv4_checksums(&mut ip, None, Some(vpn_addr));
@@ -698,6 +702,9 @@ async fn handle_incoming_data_v6(
log::trace!("Dropping packet to VPN IP on default interface");
return;
}
+ if is_non_vpn_destination(IpAddr::from(ip.get_destination())) {
+ return;
+ }
fix_ipv6_checksums(&mut ip, None, Some(vpn_addr));
@@ -710,6 +717,15 @@ async fn handle_incoming_data_v6(
}
}
+/// Packets routed outside of the split tunneling interface should not be duplicated on the VPN
+/// utun. As a shortcut we do not duplicate any private IPs.
+fn is_non_vpn_destination(ip: IpAddr) -> bool {
+ ALLOWED_LAN_NETS
+ .iter()
+ .chain(ALLOWED_LAN_MULTICAST_NETS.iter())
+ .any(|net| net.contains(ip))
+}
+
// Recalculate L3 and L4 checksums. Silently fail on error
fn fix_ipv4_checksums(
ip: &mut MutableIpv4Packet<'_>,