3
3
#![ deny( missing_docs) ]
4
4
5
5
use self :: config:: Config ;
6
- use futures:: future:: { abortable, AbortHandle as FutureAbortHandle , BoxFuture , Future } ;
7
6
#[ cfg( windows) ]
8
- use futures:: { channel:: mpsc, StreamExt } ;
7
+ use futures:: channel:: mpsc;
8
+ use futures:: future:: { abortable, AbortHandle as FutureAbortHandle , BoxFuture , Future } ;
9
9
#[ cfg( target_os = "linux" ) ]
10
10
use once_cell:: sync:: Lazy ;
11
11
#[ cfg( target_os = "android" ) ]
@@ -26,6 +26,8 @@ use talpid_routing as routing;
26
26
use talpid_routing:: { self , RequiredRoute } ;
27
27
#[ cfg( not( windows) ) ]
28
28
use talpid_tunnel:: tun_provider;
29
+ #[ cfg( not( target_os = "android" ) ) ]
30
+ use talpid_tunnel:: IPV4_HEADER_SIZE ;
29
31
use talpid_tunnel:: { tun_provider:: TunProvider , TunnelArgs , TunnelEvent , TunnelMetadata } ;
30
32
31
33
use ipnetwork:: IpNetwork ;
@@ -42,9 +44,6 @@ use tunnel_obfuscation::{
42
44
create_obfuscator, Error as ObfuscationError , Settings as ObfuscationSettings , Udp2TcpSettings ,
43
45
} ;
44
46
45
- #[ cfg( any( target_os = "linux" , target_os = "macos" ) ) ]
46
- use talpid_tunnel:: { IPV4_HEADER_SIZE , IPV6_HEADER_SIZE , WIREGUARD_HEADER_SIZE } ;
47
-
48
47
/// WireGuard config data-types
49
48
pub mod config;
50
49
mod connectivity_check;
@@ -270,7 +269,7 @@ impl WireguardMonitor {
270
269
> (
271
270
mut config : Config ,
272
271
psk_negotiation : bool ,
273
- #[ cfg( target_os = "linux" ) ] detect_mtu : bool ,
272
+ #[ cfg( any ( target_os = "linux" , windows ) ) ] detect_mtu : bool ,
274
273
log_path : Option < & Path > ,
275
274
args : TunnelArgs < ' _ , F > ,
276
275
) -> Result < WireguardMonitor > {
@@ -389,7 +388,8 @@ impl WireguardMonitor {
389
388
)
390
389
. await ?;
391
390
}
392
- #[ cfg( target_os = "linux" ) ]
391
+
392
+ #[ cfg( any( target_os = "linux" , windows) ) ]
393
393
if detect_mtu {
394
394
let iface_name_clone = iface_name. clone ( ) ;
395
395
tokio:: task:: spawn ( async move {
@@ -411,7 +411,20 @@ impl WireguardMonitor {
411
411
412
412
if verified_mtu != config. mtu {
413
413
log:: warn!( "Lowering MTU from {} to {verified_mtu}" , config. mtu) ;
414
- if let Err ( e) = unix:: set_mtu ( & iface_name_clone, verified_mtu) {
414
+ #[ cfg( target_os = "linux" ) ]
415
+ let res = unix:: set_mtu ( & iface_name_clone, verified_mtu) ;
416
+ #[ cfg( windows) ]
417
+ let res = talpid_windows:: net:: luid_from_alias ( iface_name_clone) . and_then (
418
+ |luid| {
419
+ talpid_windows:: net:: set_mtu (
420
+ luid,
421
+ verified_mtu as u32 ,
422
+ config. ipv6_gateway . is_some ( ) ,
423
+ )
424
+ } ,
425
+ ) ;
426
+
427
+ if let Err ( e) = res {
415
428
log:: error!( "{}" , e. display_chain_with_msg( "Failed to set MTU" ) )
416
429
} ;
417
430
} else {
@@ -664,6 +677,8 @@ impl WireguardMonitor {
664
677
addresses : & [ IpAddr ] ,
665
678
mut setup_done_rx : mpsc:: Receiver < std:: result:: Result < ( ) , BoxedError > > ,
666
679
) -> std:: result:: Result < ( ) , CloseMsg > {
680
+ use futures:: StreamExt ;
681
+
667
682
setup_done_rx
668
683
. next ( )
669
684
. await
@@ -936,6 +951,8 @@ impl WireguardMonitor {
936
951
937
952
#[ cfg( any( target_os = "linux" , target_os = "macos" ) ) ]
938
953
fn apply_route_mtu_for_multihop ( route : RequiredRoute , config : & Config ) -> RequiredRoute {
954
+ use talpid_tunnel:: { IPV6_HEADER_SIZE , WIREGUARD_HEADER_SIZE } ;
955
+
939
956
if !config. is_multihop ( ) {
940
957
route
941
958
} else {
@@ -991,7 +1008,7 @@ impl WireguardMonitor {
991
1008
///
992
1009
/// The detection works by sending evenly spread out range of pings between 576 and the given
993
1010
/// current tunnel MTU, and returning the maximum packet size that was returned within a timeout.
994
- #[ cfg( target_os = "linux" ) ]
1011
+ #[ cfg( any ( target_os = "linux" , windows ) ) ]
995
1012
async fn auto_mtu_detection (
996
1013
gateway : std:: net:: Ipv4Addr ,
997
1014
#[ cfg( any( target_os = "macos" , target_os = "linux" ) ) ] iface_name : String ,
@@ -1068,7 +1085,7 @@ async fn auto_mtu_detection(
1068
1085
1069
1086
/// Creates a linear spacing of MTU values with the given step size. Always includes the given end
1070
1087
/// points.
1071
- #[ cfg( target_os = "linux" ) ]
1088
+ #[ cfg( any ( target_os = "linux" , windows ) ) ]
1072
1089
fn mtu_spacing ( mtu_min : u16 , mtu_max : u16 , step_size : u16 ) -> Vec < u16 > {
1073
1090
assert ! ( mtu_min < mtu_max) ;
1074
1091
assert ! ( step_size < mtu_max) ;
@@ -1084,7 +1101,7 @@ fn mtu_spacing(mtu_min: u16, mtu_max: u16, step_size: u16) -> Vec<u16> {
1084
1101
ret
1085
1102
}
1086
1103
1087
- #[ cfg( all( test, target_os = "linux" ) ) ]
1104
+ #[ cfg( all( test, any ( target_os = "linux" , windows ) ) ) ]
1088
1105
mod tests {
1089
1106
use crate :: mtu_spacing;
1090
1107
use proptest:: prelude:: * ;
0 commit comments