@@ -137,14 +137,30 @@ impl TunnelMonitor {
137
137
+ Clone
138
138
+ ' static ,
139
139
{
140
- #[ cfg( target_os = "linux" ) ]
141
- let detect_mtu = params. options . mtu . is_none ( ) ;
140
+ let default_mtu = if cfg ! ( target_os = "android" ) {
141
+ // Set the MTU to the lowest possible whilst still allowing for IPv6 to help
142
+ // with wireless carriers that do a lot of encapsulation.
143
+ 1280
144
+ } else {
145
+ 1380
146
+ } ;
142
147
143
148
#[ cfg( any( target_os = "linux" , target_os = "windows" ) ) ]
144
- args. runtime
145
- . block_on ( Self :: assign_mtu ( & args. route_manager , params) ) ;
146
- let config = talpid_wireguard:: config:: Config :: from_parameters ( params) ?;
149
+ // Detects the MTU of the device, calculates what the virtual device MTU should be use that
150
+ // as the default mtu
151
+ let default_mtu = args
152
+ . runtime
153
+ . block_on (
154
+ args. route_manager
155
+ . get_mtu_for_route ( params. connection . peer . endpoint . ip ( ) ) ,
156
+ )
157
+ . map ( |mtu| Self :: clamp_mtu ( params, mtu) )
158
+ . unwrap_or ( default_mtu) ;
147
159
160
+ #[ cfg( target_os = "linux" ) ]
161
+ let detect_mtu = params. options . mtu . is_none ( ) ;
162
+
163
+ let config = talpid_wireguard:: config:: Config :: from_parameters ( params, default_mtu) ?;
148
164
let monitor = talpid_wireguard:: WireguardMonitor :: start (
149
165
config,
150
166
params. options . quantum_resistant ,
@@ -157,11 +173,10 @@ impl TunnelMonitor {
157
173
monitor : InternalTunnelMonitor :: Wireguard ( monitor) ,
158
174
} )
159
175
}
160
-
161
- /// Set the MTU in the tunnel parameters based on the inputted device MTU and some
176
+ /// Calculates the MTU in the tunnel parameters based on the inputted device MTU and some
162
177
/// calculations. `peer_mtu` is the detected device MTU.
163
178
#[ cfg( any( target_os = "linux" , target_os = "windows" ) ) ]
164
- fn set_mtu ( params : & mut wireguard_types:: TunnelParameters , peer_mtu : u16 ) {
179
+ fn clamp_mtu ( params : & wireguard_types:: TunnelParameters , peer_mtu : u16 ) -> u16 {
165
180
// Some users experience fragmentation issues even when we take the interface MTU and
166
181
// subtract the header sizes. This is likely due to some program that they use which does
167
182
// not change the interface MTU but adds its own header onto the outgoing packets. For this
@@ -185,31 +200,10 @@ impl TunnelMonitor {
185
200
false => MIN_IPV4_MTU ,
186
201
true => MIN_IPV6_MTU ,
187
202
} ;
188
- let tunnel_mtu = peer_mtu
189
- . saturating_sub ( total_header_size)
190
- . clamp ( min_mtu, max_peer_mtu) ;
191
- params. options . mtu = Some ( tunnel_mtu) ;
192
- }
193
203
194
- /// Detects the MTU of the device, calculates what the virtual device MTU should be and sets
195
- /// that in the tunnel parameters.
196
- #[ cfg( any( target_os = "linux" , target_os = "windows" ) ) ]
197
- async fn assign_mtu (
198
- route_manager : & RouteManagerHandle ,
199
- params : & mut wireguard_types:: TunnelParameters ,
200
- ) {
201
- // Only calculate the mtu automatically if the user has not set any
202
- if params. options . mtu . is_none ( ) {
203
- match route_manager
204
- . get_mtu_for_route ( params. connection . peer . endpoint . ip ( ) )
205
- . await
206
- {
207
- Ok ( mtu) => Self :: set_mtu ( params, mtu) ,
208
- Err ( e) => {
209
- log:: error!( "Could not get the MTU for route {}" , e) ;
210
- }
211
- }
212
- }
204
+ peer_mtu
205
+ . saturating_sub ( total_header_size)
206
+ . clamp ( min_mtu, max_peer_mtu)
213
207
}
214
208
215
209
#[ cfg( not( target_os = "android" ) ) ]
0 commit comments