Skip to content

Commit 1415816

Browse files
Fix use Wireguard-go when DAITA is enabled
1 parent f22e3ea commit 1415816

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

talpid-wireguard/src/lib.rs

+39-17
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,14 @@ impl WireguardMonitor {
761761

762762
#[cfg(target_os = "linux")]
763763
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+
764772
if will_nm_manage_dns() {
765773
match wireguard_kernel::NetworkManagerTunnel::new(runtime, config) {
766774
Ok(tunnel) => {
@@ -803,28 +811,42 @@ impl WireguardMonitor {
803811

804812
#[cfg(wireguard_go)]
805813
{
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-
812814
#[cfg(target_os = "linux")]
813815
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)
825821
}
826822
}
827823

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+
828850
/// Blocks the current thread until tunnel disconnects
829851
pub fn wait(mut self) -> Result<()> {
830852
let wait_result = match self.close_msg_receiver.recv() {

0 commit comments

Comments
 (0)