@@ -6,11 +6,11 @@ use self::config::Config;
6
6
#[ cfg( windows) ]
7
7
use futures:: channel:: mpsc;
8
8
use futures:: future:: { abortable, AbortHandle as FutureAbortHandle , BoxFuture , Future } ;
9
- #[ cfg( target_os = "linux" ) ]
9
+ #[ cfg( all ( target_os = "linux" , not ( feature = "daita" ) ) ) ]
10
10
use once_cell:: sync:: Lazy ;
11
11
#[ cfg( target_os = "android" ) ]
12
12
use std:: borrow:: Cow ;
13
- #[ cfg( target_os = "linux" ) ]
13
+ #[ cfg( all ( target_os = "linux" , not ( feature = "daita" ) ) ) ]
14
14
use std:: env;
15
15
#[ cfg( windows) ]
16
16
use std:: io;
@@ -199,7 +199,7 @@ impl Drop for ObfuscatorHandle {
199
199
}
200
200
}
201
201
202
- #[ cfg( target_os = "linux" ) ]
202
+ #[ cfg( all ( target_os = "linux" , not ( feature = "daita" ) ) ) ]
203
203
/// Overrides the preference for the kernel module for WireGuard.
204
204
static FORCE_USERSPACE_WIREGUARD : Lazy < bool > = Lazy :: new ( || {
205
205
env:: var ( "TALPID_FORCE_USERSPACE_WIREGUARD" )
@@ -753,21 +753,20 @@ impl WireguardMonitor {
753
753
Ok ( ephemeral. psk )
754
754
}
755
755
756
- #[ cfg( all( not( target_os = "windows" ) , not( feature = "daita" ) ) ) ]
757
- #[ allow( unused_variables) ]
756
+ // TODO(markus): De-duplicate parts of different `open_tunnel`implementations.
757
+
758
+ /// Linux can use the kernel implementation of Wireguard and fall back to WireguardGo.
759
+ /// Note that when DAITA is enabled, only WireguardGo may be used.
760
+ #[ cfg( all( target_os = "linux" , not( feature = "daita" ) ) ) ]
758
761
fn open_tunnel (
759
762
runtime : tokio:: runtime:: Handle ,
760
763
config : & Config ,
761
764
log_path : Option < & Path > ,
762
- resource_dir : & Path ,
765
+ _resource_dir : & Path ,
763
766
tun_provider : Arc < Mutex < TunProvider > > ,
764
- #[ cfg( target_os = "android" ) ] gateway_only : bool ,
765
767
) -> Result < TunnelT > {
766
768
log:: debug!( "Tunnel MTU: {}" , config. mtu) ;
767
-
768
- let daita = true ;
769
- #[ cfg( target_os = "linux" ) ]
770
- if !daita && !* FORCE_USERSPACE_WIREGUARD {
769
+ if !* FORCE_USERSPACE_WIREGUARD {
771
770
if will_nm_manage_dns ( ) {
772
771
match wireguard_kernel:: NetworkManagerTunnel :: new ( runtime, config) {
773
772
Ok ( tunnel) => {
@@ -801,15 +800,14 @@ impl WireguardMonitor {
801
800
}
802
801
}
803
802
803
+ // TODO: `wireguard_go` is *currently* implied when building for Linux, but that might not
804
+ // always be true. When that assumptions is not uphold anymore, the kernel-only version of
805
+ // this function will have to return any errors instead of falling back to WireguardGo.
804
806
#[ cfg( wireguard_go) ]
805
807
{
806
808
let routes =
807
809
Self :: get_tunnel_destinations ( config) . flat_map ( Self :: replace_default_prefixes) ;
808
810
809
- #[ cfg( target_os = "android" ) ]
810
- let config = Self :: patch_allowed_ips ( config, gateway_only) ;
811
-
812
- #[ cfg( target_os = "linux" ) ]
813
811
log:: debug!( "Using userspace WireGuard implementation" ) ;
814
812
Ok ( Box :: new (
815
813
WgGoTunnel :: start_tunnel (
@@ -826,7 +824,34 @@ impl WireguardMonitor {
826
824
}
827
825
}
828
826
829
- #[ cfg( all( not( target_os = "windows" ) , feature = "daita" , wireguard_go) ) ]
827
+ #[ cfg( all( target_os = "linux" , feature = "daita" ) ) ]
828
+ fn open_tunnel (
829
+ _runtime : tokio:: runtime:: Handle ,
830
+ config : & Config ,
831
+ log_path : Option < & Path > ,
832
+ resource_dir : & Path ,
833
+ tun_provider : Arc < Mutex < TunProvider > > ,
834
+ ) -> Result < TunnelT > {
835
+ log:: debug!( "Tunnel MTU: {}" , config. mtu) ;
836
+
837
+ let routes = Self :: get_tunnel_destinations ( config) . flat_map ( Self :: replace_default_prefixes) ;
838
+
839
+ Ok ( Box :: new (
840
+ WgGoTunnel :: start_tunnel (
841
+ #[ allow( clippy:: needless_borrow) ]
842
+ & config,
843
+ log_path,
844
+ tun_provider,
845
+ routes,
846
+ #[ cfg( feature = "daita" ) ]
847
+ resource_dir,
848
+ )
849
+ . map_err ( Error :: TunnelError ) ?,
850
+ ) )
851
+ }
852
+
853
+ /// Both Android and macOS uses WireguardGo.
854
+ #[ cfg( any( target_os = "macos" , target_os = "android" ) ) ]
830
855
#[ allow( unused_variables) ]
831
856
fn open_tunnel (
832
857
runtime : tokio:: runtime:: Handle ,
@@ -838,14 +863,11 @@ impl WireguardMonitor {
838
863
) -> Result < TunnelT > {
839
864
log:: debug!( "Tunnel MTU: {}" , config. mtu) ;
840
865
841
- let daita = true ;
842
866
let routes = Self :: get_tunnel_destinations ( config) . flat_map ( Self :: replace_default_prefixes) ;
843
867
844
868
#[ cfg( target_os = "android" ) ]
845
869
let config = Self :: patch_allowed_ips ( config, gateway_only) ;
846
870
847
- #[ cfg( target_os = "linux" ) ]
848
- log:: debug!( "Using userspace WireGuard implementation" ) ;
849
871
Ok ( Box :: new (
850
872
WgGoTunnel :: start_tunnel (
851
873
#[ allow( clippy:: needless_borrow) ]
@@ -860,6 +882,7 @@ impl WireguardMonitor {
860
882
) )
861
883
}
862
884
885
+ /// Windows uses it's own version of `open_tunnel`.
863
886
#[ cfg( target_os = "windows" ) ]
864
887
#[ allow( unused_variables) ]
865
888
fn open_tunnel (
@@ -1171,6 +1194,7 @@ pub enum TunnelError {
1171
1194
}
1172
1195
1173
1196
#[ cfg( target_os = "linux" ) ]
1197
+ #[ allow( dead_code) ]
1174
1198
fn will_nm_manage_dns ( ) -> bool {
1175
1199
use talpid_dbus:: network_manager:: NetworkManager ;
1176
1200
0 commit comments