summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2024-09-21 14:42:32 +0200
committerDavid Lönnhager <david.l@mullvad.net>2024-09-24 15:54:39 +0200
commit55f9b3a706c8134d2a92ec7b02c42a405455a3e0 (patch)
tree343594d999e908e45cc4ad3e78e0dd21a5759fe0
parent1fc8ebd81cd7d677097fc1492b7da9341e41f081 (diff)
downloadmullvadvpn-55f9b3a706c8134d2a92ec7b02c42a405455a3e0.tar.xz
mullvadvpn-55f9b3a706c8134d2a92ec7b02c42a405455a3e0.zip
Do not set IP_USER_MTU on on tunnel config socket
-rw-r--r--talpid-tunnel-config-client/src/lib.rs53
1 files changed, 7 insertions, 46 deletions
diff --git a/talpid-tunnel-config-client/src/lib.rs b/talpid-tunnel-config-client/src/lib.rs
index 4172a0023a..1ebb7fef5a 100644
--- a/talpid-tunnel-config-client/src/lib.rs
+++ b/talpid-tunnel-config-client/src/lib.rs
@@ -22,21 +22,13 @@ mod proto {
tonic::include_proto!("ephemeralpeer");
}
-#[cfg(not(target_os = "ios"))]
-use libc::setsockopt;
-
#[cfg(not(any(target_os = "windows", target_os = "ios")))]
mod sys {
- pub use libc::{socklen_t, IPPROTO_TCP, TCP_MAXSEG};
+ pub use libc::{setsockopt, socklen_t, IPPROTO_TCP, TCP_MAXSEG};
pub use std::os::fd::{AsRawFd, RawFd};
}
-#[cfg(target_os = "windows")]
-mod sys {
- pub use std::os::windows::io::{AsRawSocket, RawSocket};
- pub use windows_sys::Win32::Networking::WinSock::{IPPROTO_IP, IP_USER_MTU};
-}
-#[cfg(not(target_os = "ios"))]
+#[cfg(not(any(target_os = "windows", target_os = "ios")))]
use sys::*;
#[derive(Debug)]
@@ -102,15 +94,11 @@ pub type RelayConfigService = proto::ephemeral_peer_client::EphemeralPeerClient<
pub const CONFIG_SERVICE_PORT: u16 = 1337;
/// MTU to set on the tunnel config client socket. We want a low value to prevent fragmentation.
-/// This is needed for two reasons:
-/// 1. Especially on Android, we've found that the real MTU is often lower than the default MTU, and
-/// we cannot lower it further. This causes the outer packets to be dropped. Also, MTU detection
-/// will likely occur after the PQ handshake, so we cannot assume that the MTU is already
-/// correctly configured.
-/// 2. MH + PQ on macOS has connection issues during the handshake due to PF blocking packet
-/// fragments for not having a port. In the longer term this might be fixed by allowing the
-/// handshake to work even if there is fragmentation.
-#[cfg(not(target_os = "ios"))]
+/// Especially on Android, we've found that the real MTU is often lower than the default MTU, and
+/// we cannot lower it further. This causes the outer packets to be dropped. Also, MTU detection
+/// will likely occur after the PQ handshake, so we cannot assume that the MTU is already
+/// correctly configured.
+#[cfg(not(any(target_os = "windows", target_os = "ios")))]
const CONFIG_CLIENT_MTU: u16 = 576;
pub struct EphemeralPeer {
@@ -253,9 +241,6 @@ async fn new_client(addr: Ipv4Addr) -> Result<RelayConfigService, Error> {
.connect_with_connector(service_fn(move |_| async move {
let sock = TcpSocket::new_v4()?;
- #[cfg(target_os = "windows")]
- try_set_tcp_sock_mtu(sock.as_raw_socket(), CONFIG_CLIENT_MTU);
-
#[cfg(not(target_os = "windows"))]
try_set_tcp_sock_mtu(&addr, sock.as_raw_fd(), CONFIG_CLIENT_MTU);
@@ -268,30 +253,6 @@ async fn new_client(addr: Ipv4Addr) -> Result<RelayConfigService, Error> {
Ok(RelayConfigService::new(conn))
}
-#[cfg(windows)]
-fn try_set_tcp_sock_mtu(sock: RawSocket, mtu: u16) {
- let mtu = u32::from(mtu);
- log::debug!("Config client socket MTU: {mtu}");
-
- let raw_sock = usize::try_from(sock).unwrap();
-
- let result = unsafe {
- setsockopt(
- raw_sock,
- IPPROTO_IP,
- IP_USER_MTU,
- &mtu as *const _ as _,
- std::ffi::c_int::try_from(std::mem::size_of_val(&mtu)).unwrap(),
- )
- };
- if result != 0 {
- log::error!(
- "Failed to set user MTU on config client socket: {}",
- std::io::Error::last_os_error()
- );
- }
-}
-
#[cfg(not(any(target_os = "windows", target_os = "ios")))]
fn try_set_tcp_sock_mtu(dest: &IpAddr, sock: RawFd, mut mtu: u16) {
const IPV4_HEADER_SIZE: u16 = 20;