@@ -989,11 +989,11 @@ impl WireguardMonitor {
989
989
}
990
990
}
991
991
992
- #[ cfg( target_os = "linux" ) ]
993
992
/// Detects the maximum MTU that does not cause dropped packets.
994
993
///
995
994
/// The detection works by sending evenly spread out range of pings between 576 and the given
996
995
/// current tunnel MTU, and returning the maximum packet size that war returned within a timeout.
996
+ #[ cfg( target_os = "linux" ) ]
997
997
async fn auto_mtu_detection (
998
998
gateway : std:: net:: Ipv4Addr ,
999
999
#[ cfg( any( target_os = "macos" , target_os = "linux" ) ) ] iface_name : String ,
@@ -1009,26 +1009,24 @@ async fn auto_mtu_detection(
1009
1009
let config_builder = Config :: builder ( ) . kind ( surge_ping:: ICMP :: V4 ) ;
1010
1010
#[ cfg( any( target_os = "macos" , target_os = "linux" ) ) ]
1011
1011
let config_builder = config_builder. interface ( & iface_name) ;
1012
- let config = config_builder. build ( ) ;
1013
- let client = Client :: new ( & config) . unwrap ( ) ;
1012
+ let client = Client :: new ( & config_builder. build ( ) ) . unwrap ( ) ;
1014
1013
1015
1014
let step_size = 20 ;
1016
-
1017
1015
let linspace = mtu_spacing ( MIN_IPV4_MTU , current_mtu, step_size) ;
1018
- let largest_payload = vec ! [ 0 ; current_mtu as usize ] ;
1019
1016
1020
- let ping_stream : FuturesUnordered < _ > = linspace
1017
+ let payload_buf = vec ! [ 0 ; current_mtu as usize ] ;
1021
1018
. iter ( )
1022
1019
. enumerate ( )
1023
1020
. map ( |( i, & mtu) | {
1024
1021
let client = client. clone ( ) ;
1025
- let payload = & largest_payload[ 0 ..( mtu - IPV4_HEADER_SIZE - ICMP_HEADER_SIZE ) as usize ] ;
1022
+ let payload_size = ( mtu - IPV4_HEADER_SIZE - ICMP_HEADER_SIZE ) as usize ;
1023
+ let payload = & payload_buf[ 0 ..payload_size] ;
1026
1024
async move {
1027
1025
log:: trace!( "Sending ICMP ping of total size {mtu}" ) ;
1028
1026
client
1029
1027
. pinger ( IpAddr :: V4 ( gateway) , PingIdentifier ( 111 ) ) //? Is a static identified ok, or should we randomize?
1030
1028
. await
1031
- . timeout ( PING_TIMEOUT ) // TODO: choose a good timeout
1029
+ . timeout ( PING_TIMEOUT )
1032
1030
. ping ( PingSequence ( i as u16 ) , payload)
1033
1031
. await
1034
1032
}
0 commit comments