@@ -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,42 @@ 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
+ #[ cfg( wireguard_go) ]
826
+ fn open_wireguard_go_tunnel (
827
+ config : & Config ,
828
+ log_path : Option < & Path > ,
829
+ #[ cfg( any( target_os = "windows" , target_os = "linux" ) ) ] resource_dir : & Path ,
830
+ tun_provider : Arc < Mutex < TunProvider > > ,
831
+ ) -> Result < WgGoTunnel > {
832
+ let routes = Self :: get_tunnel_destinations ( config) . flat_map ( Self :: replace_default_prefixes) ;
833
+
834
+ #[ cfg( target_os = "android" ) ]
835
+ let config = Self :: patch_allowed_ips ( config, gateway_only) ;
836
+
837
+ let tunnel = WgGoTunnel :: start_tunnel (
838
+ config,
839
+ log_path,
840
+ tun_provider,
841
+ routes,
842
+ #[ cfg( any( target_os = "windows" , target_os = "linux" ) ) ]
843
+ resource_dir,
844
+ )
845
+ . map_err ( Error :: TunnelError ) ?;
846
+
847
+ Ok ( tunnel)
848
+ }
849
+
828
850
/// Blocks the current thread until tunnel disconnects
829
851
pub fn wait ( mut self ) -> Result < ( ) > {
830
852
let wait_result = match self . close_msg_receiver . recv ( ) {
0 commit comments