@@ -761,6 +761,14 @@ impl WireguardMonitor {
761
761
762
762
#[ cfg( target_os = "linux" ) ]
763
763
if !* FORCE_USERSPACE_WIREGUARD {
764
+ // If DAITA is enabled, wireguard-go has to be used.
765
+ if config. daita {
766
+ let tunnel =
767
+ Self :: open_wireguard_go_tunnel ( config, log_path, resource_dir, tun_provider)
768
+ . map ( Box :: new) ?;
769
+ return Ok ( tunnel) ;
770
+ }
771
+
764
772
if will_nm_manage_dns ( ) {
765
773
match wireguard_kernel:: NetworkManagerTunnel :: new ( runtime, config) {
766
774
Ok ( tunnel) => {
@@ -803,28 +811,41 @@ impl WireguardMonitor {
803
811
804
812
#[ cfg( wireguard_go) ]
805
813
{
806
- let routes =
807
- Self :: get_tunnel_destinations ( config) . flat_map ( Self :: replace_default_prefixes) ;
808
-
809
- #[ cfg( target_os = "android" ) ]
810
- let config = Self :: patch_allowed_ips ( config, gateway_only) ;
811
-
812
814
#[ cfg( target_os = "linux" ) ]
813
815
log:: debug!( "Using userspace WireGuard implementation" ) ;
814
- Ok ( Box :: new (
815
- WgGoTunnel :: start_tunnel (
816
- #[ allow( clippy:: needless_borrow) ]
817
- & config,
818
- log_path,
819
- tun_provider,
820
- routes,
821
- resource_dir,
822
- )
823
- . map_err ( Error :: TunnelError ) ?,
824
- ) )
816
+
817
+ let tunnel =
818
+ Self :: open_wireguard_go_tunnel ( config, log_path, resource_dir, tun_provider)
819
+ . map ( Box :: new) ?;
820
+ Ok ( tunnel)
825
821
}
826
822
}
827
823
824
+ /// Configure and start a Wireguard-go tunnel.
825
+ fn open_wireguard_go_tunnel (
826
+ config : & Config ,
827
+ log_path : Option < & Path > ,
828
+ #[ cfg( any( target_os = "windows" , target_os = "linux" ) ) ] resource_dir : & Path ,
829
+ tun_provider : Arc < Mutex < TunProvider > > ,
830
+ ) -> Result < WgGoTunnel > {
831
+ let routes = Self :: get_tunnel_destinations ( config) . flat_map ( Self :: replace_default_prefixes) ;
832
+
833
+ #[ cfg( target_os = "android" ) ]
834
+ let config = Self :: patch_allowed_ips ( config, gateway_only) ;
835
+
836
+ let tunnel = WgGoTunnel :: start_tunnel (
837
+ config,
838
+ log_path,
839
+ tun_provider,
840
+ routes,
841
+ #[ cfg( any( target_os = "windows" , target_os = "linux" ) ) ]
842
+ resource_dir,
843
+ )
844
+ . map_err ( Error :: TunnelError ) ?;
845
+
846
+ Ok ( tunnel)
847
+ }
848
+
828
849
/// Blocks the current thread until tunnel disconnects
829
850
pub fn wait ( mut self ) -> Result < ( ) > {
830
851
let wait_result = match self . close_msg_receiver . recv ( ) {
0 commit comments