summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2024-06-10 13:46:29 +0200
committerMarkus Pettersson <markus.pettersson@mullvad.net>2024-06-25 17:31:36 +0200
commitb41704c8a47d1b1568a0918f782f543277ae6acc (patch)
tree91f5d6412fe119c3795a3431cbe01fde9b5c12f0
parent7475c53d540768a49ccda0517a1437bf50a06e2d (diff)
downloadmullvadvpn-b41704c8a47d1b1568a0918f782f543277ae6acc.tar.xz
mullvadvpn-b41704c8a47d1b1568a0918f782f543277ae6acc.zip
Use Wireguard-go when DAITA is enabled
-rw-r--r--talpid-wireguard/Cargo.toml1
-rw-r--r--talpid-wireguard/src/lib.rs65
-rw-r--r--talpid-wireguard/src/wireguard_go/mod.rs5
3 files changed, 53 insertions, 18 deletions
diff --git a/talpid-wireguard/Cargo.toml b/talpid-wireguard/Cargo.toml
index 09b7baa57f..e7db72cac6 100644
--- a/talpid-wireguard/Cargo.toml
+++ b/talpid-wireguard/Cargo.toml
@@ -45,6 +45,7 @@ tokio-stream = { version = "0.1", features = ["io-util"] }
[target.'cfg(unix)'.dependencies]
nix = "0.23"
+[target.'cfg(target_os = "linux")'.dependencies]
rtnetlink = "0.11"
netlink-packet-core = "0.4.2"
netlink-packet-route = "0.13"
diff --git a/talpid-wireguard/src/lib.rs b/talpid-wireguard/src/lib.rs
index e8334f43d1..d18f5c9fb2 100644
--- a/talpid-wireguard/src/lib.rs
+++ b/talpid-wireguard/src/lib.rs
@@ -761,6 +761,14 @@ impl WireguardMonitor {
#[cfg(target_os = "linux")]
if !*FORCE_USERSPACE_WIREGUARD {
+ // If DAITA is enabled, wireguard-go has to be used.
+ if config.daita {
+ let tunnel =
+ Self::open_wireguard_go_tunnel(config, log_path, resource_dir, tun_provider)
+ .map(Box::new)?;
+ return Ok(tunnel);
+ }
+
if will_nm_manage_dns() {
match wireguard_kernel::NetworkManagerTunnel::new(runtime, config) {
Ok(tunnel) => {
@@ -803,28 +811,51 @@ impl WireguardMonitor {
#[cfg(wireguard_go)]
{
- let routes =
- Self::get_tunnel_destinations(config).flat_map(Self::replace_default_prefixes);
-
- #[cfg(target_os = "android")]
- let config = Self::patch_allowed_ips(config, gateway_only);
-
#[cfg(target_os = "linux")]
log::debug!("Using userspace WireGuard implementation");
- Ok(Box::new(
- WgGoTunnel::start_tunnel(
- #[allow(clippy::needless_borrow)]
- &config,
- log_path,
- tun_provider,
- routes,
- resource_dir,
- )
- .map_err(Error::TunnelError)?,
- ))
+
+ let tunnel = Self::open_wireguard_go_tunnel(
+ config,
+ log_path,
+ #[cfg(any(target_os = "windows", target_os = "linux"))]
+ resource_dir,
+ tun_provider,
+ #[cfg(target_os = "android")]
+ gateway_only,
+ )
+ .map(Box::new)?;
+ Ok(tunnel)
}
}
+ /// Configure and start a Wireguard-go tunnel.
+ #[cfg(wireguard_go)]
+ fn open_wireguard_go_tunnel(
+ config: &Config,
+ log_path: Option<&Path>,
+ #[cfg(any(target_os = "windows", target_os = "linux"))] resource_dir: &Path,
+ tun_provider: Arc<Mutex<TunProvider>>,
+ #[cfg(target_os = "android")] gateway_only: bool,
+ ) -> Result<WgGoTunnel> {
+ let routes = Self::get_tunnel_destinations(config).flat_map(Self::replace_default_prefixes);
+
+ #[cfg(target_os = "android")]
+ let config = Self::patch_allowed_ips(config, gateway_only);
+
+ let tunnel = WgGoTunnel::start_tunnel(
+ #[allow(clippy::needless_borrow)]
+ &config,
+ log_path,
+ tun_provider,
+ routes,
+ #[cfg(any(target_os = "windows", target_os = "linux"))]
+ resource_dir,
+ )
+ .map_err(Error::TunnelError)?;
+
+ Ok(tunnel)
+ }
+
/// Blocks the current thread until tunnel disconnects
pub fn wait(mut self) -> Result<()> {
let wait_result = match self.close_msg_receiver.recv() {
diff --git a/talpid-wireguard/src/wireguard_go/mod.rs b/talpid-wireguard/src/wireguard_go/mod.rs
index 32181beaea..de5e3e0f83 100644
--- a/talpid-wireguard/src/wireguard_go/mod.rs
+++ b/talpid-wireguard/src/wireguard_go/mod.rs
@@ -54,6 +54,7 @@ pub struct WgGoTunnel {
tun_provider: Arc<Mutex<TunProvider>>,
#[cfg(any(target_os = "windows", target_os = "linux"))]
resource_dir: PathBuf,
+ #[cfg(any(target_os = "windows", target_os = "linux"))]
config: Config,
}
@@ -63,7 +64,7 @@ impl WgGoTunnel {
log_path: Option<&Path>,
tun_provider: Arc<Mutex<TunProvider>>,
routes: impl Iterator<Item = IpNetwork>,
- resource_dir: &Path,
+ #[cfg(any(target_os = "windows", target_os = "linux"))] resource_dir: &Path,
) -> Result<Self> {
#[cfg(target_os = "android")]
let tun_provider_clone = tun_provider.clone();
@@ -100,6 +101,7 @@ impl WgGoTunnel {
_logging_context: logging_context,
#[cfg(target_os = "android")]
tun_provider: tun_provider_clone,
+ #[cfg(any(target_os = "windows", target_os = "linux"))]
resource_dir: resource_dir.to_owned(),
#[cfg(any(target_os = "windows", target_os = "linux"))]
config: config.clone(),
@@ -240,6 +242,7 @@ impl Tunnel for WgGoTunnel {
})
}
+ #[cfg(any(target_os = "windows", target_os = "linux"))]
fn start_daita(&mut self) -> Result<()> {
static MAYBENOT_MACHINES: OnceCell<CString> = OnceCell::new();
let machines = MAYBENOT_MACHINES.get_or_try_init(|| {