File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -175,6 +175,10 @@ impl TunnelMonitor {
175
175
)
176
176
. map ( |mtu| Self :: clamp_mtu ( params, mtu) )
177
177
. unwrap_or ( default_mtu) ;
178
+
179
+ #[ cfg( target_os = "linux" ) ]
180
+ let detect_mtu = params. options . mtu . is_none ( ) ;
181
+
178
182
let config = talpid_wireguard:: config:: Config :: from_parameters ( params, default_mtu) ?;
179
183
let monitor = talpid_wireguard:: WireguardMonitor :: start (
180
184
config,
Original file line number Diff line number Diff line change @@ -270,6 +270,7 @@ impl WireguardMonitor {
270
270
> (
271
271
mut config : Config ,
272
272
psk_negotiation : bool ,
273
+ #[ cfg( target_os = "linux" ) ] detect_mtu : bool ,
273
274
log_path : Option < & Path > ,
274
275
args : TunnelArgs < ' _ , F > ,
275
276
) -> Result < WireguardMonitor > {
@@ -388,7 +389,36 @@ impl WireguardMonitor {
388
389
)
389
390
. await ?;
390
391
}
392
+ #[ cfg( target_os = "linux" ) ]
393
+ if detect_mtu {
394
+ let iface_name_clone = iface_name. clone ( ) ;
395
+ tokio:: task:: spawn ( async move {
396
+ log:: debug!( "Starting MTU detection" ) ;
397
+ let verified_mtu = match auto_mtu_detection (
398
+ gateway,
399
+ #[ cfg( any( target_os = "macos" , target_os = "linux" ) ) ]
400
+ iface_name_clone. clone ( ) ,
401
+ config. mtu ,
402
+ )
403
+ . await
404
+ {
405
+ Ok ( mtu) => mtu,
406
+ Err ( e) => {
407
+ log:: error!( "{}" , e. display_chain_with_msg( "Failed to detect MTU" ) ) ;
408
+ return ;
409
+ }
410
+ } ;
391
411
412
+ if verified_mtu != config. mtu {
413
+ log:: warn!( "Lowering MTU from {} to {verified_mtu}" , config. mtu) ;
414
+ if let Err ( e) = unix:: set_mtu ( & iface_name_clone, verified_mtu) {
415
+ log:: error!( "{}" , e. display_chain_with_msg( "Failed to set MTU" ) )
416
+ } ;
417
+ } else {
418
+ log:: debug!( "MTU {verified_mtu} verified to not drop packets" ) ;
419
+ }
420
+ } ) ;
421
+ }
392
422
let mut connectivity_monitor = tokio:: task:: spawn_blocking ( move || {
393
423
match connectivity_monitor. establish_connectivity ( args. retry_attempt ) {
394
424
Ok ( true ) => Ok ( connectivity_monitor) ,
You can’t perform that action at this time.
0 commit comments