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