diff options
| author | David Lönnhager <david.l@mullvad.net> | 2024-02-13 09:50:33 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2024-02-13 09:50:33 +0100 |
| commit | b0e4315a003e08f2b11160418e1dccac6f462924 (patch) | |
| tree | 4bf30e25253ec2fb142604fba36b27f21471e63d | |
| parent | da4e1c2b9e93e8a54e80c6d78131898733bf41bd (diff) | |
| parent | fd502da5aae7323798134af5c579292c15e9a399 (diff) | |
| download | mullvadvpn-b0e4315a003e08f2b11160418e1dccac6f462924.tar.xz mullvadvpn-b0e4315a003e08f2b11160418e1dccac6f462924.zip | |
Merge branch 'mtu-detection-windows-patch'
| -rw-r--r-- | talpid-windows/src/net.rs | 21 | ||||
| -rw-r--r-- | talpid-wireguard/src/mtu_detection.rs | 22 |
2 files changed, 23 insertions, 20 deletions
diff --git a/talpid-windows/src/net.rs b/talpid-windows/src/net.rs index 1545b85e4a..196d6a66b6 100644 --- a/talpid-windows/src/net.rs +++ b/talpid-windows/src/net.rs @@ -333,25 +333,12 @@ pub fn add_ip_address_for_interface(luid: NET_LUID_LH, address: IpAddr) -> Resul } /// Sets MTU on the specified network interface identified by `luid`. -pub fn set_mtu(luid: NET_LUID_LH, mtu: u32, use_ipv6: bool) -> io::Result<()> { - let ip_families: &[AddressFamily] = if use_ipv6 { - &[AddressFamily::Ipv4, AddressFamily::Ipv6] - } else { - &[AddressFamily::Ipv4] - }; - for family in ip_families { - let mut row = match get_ip_interface_entry(*family, &luid) { - Ok(row) => row, - Err(error) if error.raw_os_error() == Some(ERROR_NOT_FOUND as i32) => continue, - Err(error) => return Err(error), - }; - - row.NlMtu = mtu; +pub fn set_mtu(mtu: u32, luid: NET_LUID_LH, ip_family: AddressFamily) -> io::Result<()> { + let mut row = get_ip_interface_entry(ip_family, &luid)?; - set_ip_interface_entry(&mut row)?; - } + row.NlMtu = mtu; - Ok(()) + set_ip_interface_entry(&mut row) } /// Returns the unicast IP address table. If `family` is `None`, then addresses for all families are diff --git a/talpid-wireguard/src/mtu_detection.rs b/talpid-wireguard/src/mtu_detection.rs index 139dfbc9b5..54bbcb7b4d 100644 --- a/talpid-wireguard/src/mtu_detection.rs +++ b/talpid-wireguard/src/mtu_detection.rs @@ -57,15 +57,31 @@ pub async fn automatic_mtu_correction( #[cfg(any(target_os = "linux", target_os = "macos"))] crate::unix::set_mtu(&iface_name, verified_mtu).map_err(Error::SetMtu)?; #[cfg(windows)] - talpid_windows::net::luid_from_alias(iface_name) - .and_then(|luid| talpid_windows::net::set_mtu(luid, verified_mtu as u32, ipv6)) - .map_err(Error::SetMtu)?; + set_mtu_windows(verified_mtu, iface_name, ipv6).map_err(Error::SetMtu)?; } else { log::debug!("MTU {verified_mtu} verified to not drop packets"); }; Ok(()) } +#[cfg(windows)] +fn set_mtu_windows(verified_mtu: u16, iface_name: String, ipv6: bool) -> io::Result<()> { + use talpid_windows::net::{set_mtu, AddressFamily}; + + let luid = talpid_windows::net::luid_from_alias(iface_name)?; + set_mtu(u32::from(verified_mtu), luid, AddressFamily::Ipv4)?; + if ipv6 { + let clamped_mtu = if verified_mtu < talpid_tunnel::MIN_IPV6_MTU { + log::warn!("Cannot set MTU to {verified_mtu} for IPv6, setting to the minimum value 1280 instead"); + talpid_tunnel::MIN_IPV6_MTU + } else { + verified_mtu + }; + set_mtu(u32::from(clamped_mtu), luid, AddressFamily::Ipv6)?; + } + Ok(()) +} + /// Detects the maximum MTU that does not cause dropped packets. /// /// The detection works by sending evenly spread out range of pings between 576 and the given |
