summaryrefslogtreecommitdiffhomepage
path: root/talpid-core/src
diff options
context:
space:
mode:
authorJonathan <jonathan@mullvad.net>2022-08-17 12:38:28 +0200
committerJonathan <jonathan@mullvad.net>2022-08-18 11:36:25 +0200
commitf320e818dd68e775650794f9d3afeea3df42ddb2 (patch)
treede1690fb4fcacf42ee15a5ba902f0a4a0ecafbcc /talpid-core/src
parent635499187fcea493d5df1d185795105988f5a195 (diff)
downloadmullvadvpn-f320e818dd68e775650794f9d3afeea3df42ddb2.tar.xz
mullvadvpn-f320e818dd68e775650794f9d3afeea3df42ddb2.zip
Add a safety margin for the virtual interface MTU
Some users experienced problems when there was no safety margin on the MTU for our interface.
Diffstat (limited to 'talpid-core/src')
-rw-r--r--talpid-core/src/tunnel/mod.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs
index a0fda069f5..302c8003c9 100644
--- a/talpid-core/src/tunnel/mod.rs
+++ b/talpid-core/src/tunnel/mod.rs
@@ -223,8 +223,16 @@ impl TunnelMonitor {
})
}
+ /// Set the MTU in the tunnel parameters based on the inputted device MTU and some
+ /// calculations. `peer_mtu` is the detected device MTU.
#[cfg(any(target_os = "linux", target_os = "windows"))]
fn set_mtu(params: &mut wireguard_types::TunnelParameters, peer_mtu: u16) {
+ // Some users experience fragmentation issues even when we take the interface MTU and
+ // subtract the header sizes. This is likely due to some program that they use which does
+ // not change the interface MTU but adds its own header onto the outgoing packets. For this
+ // reason we subtract some extra bytes from our MTU in order to give other programs some
+ // safety margin.
+ const MTU_SAFETY_MARGIN: u16 = 60;
const IPV4_HEADER_SIZE: u16 = 20;
const IPV6_HEADER_SIZE: u16 = 40;
const WIREGUARD_HEADER_SIZE: u16 = 40;
@@ -234,8 +242,8 @@ impl TunnelMonitor {
true => IPV6_HEADER_SIZE,
};
// The largest peer MTU that we allow
- const MAX_PEER_MTU: u16 = 1500;
- // The minimum allowed MTU size for our tunnel in IPv6 is 1280
+ const MAX_PEER_MTU: u16 = 1500 - MTU_SAFETY_MARGIN;
+ // The minimum allowed MTU size for our tunnel in IPv6 is 1280 and 576 for IPv4
const MIN_IPV4_MTU: u16 = 576;
const MIN_IPV6_MTU: u16 = 1280;
let min_mtu = match params.generic_options.enable_ipv6 {
@@ -248,6 +256,8 @@ impl TunnelMonitor {
params.options.mtu = Some(tunnel_mtu);
}
+ /// Detects the MTU of the device, calculates what the virtual device MTU should be and sets
+ /// that in the tunnel parameters.
#[cfg(any(target_os = "linux", target_os = "windows"))]
async fn assign_mtu(
route_manager: &RouteManagerHandle,