Skip to content

Commit 0e32556

Browse files
fixup! Add daita as a cargo feature
1 parent f0c8b56 commit 0e32556

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed

mullvad-types/src/wireguard.rs

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ pub struct QuantumResistantStateParseError;
5757

5858
#[cfg(feature = "daita")]
5959
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
60+
#[cfg_attr(target_os = "android", derive(IntoJava, FromJava))]
61+
#[cfg_attr(target_os = "android", jnix(package = "net.mullvad.mullvadvpn.model"))]
6062
pub struct DaitaSettings {
6163
pub enabled: bool,
6264
}

talpid-wireguard/src/lib.rs

+43-19
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use self::config::Config;
66
#[cfg(windows)]
77
use futures::channel::mpsc;
88
use futures::future::{abortable, AbortHandle as FutureAbortHandle, BoxFuture, Future};
9-
#[cfg(target_os = "linux")]
9+
#[cfg(all(target_os = "linux", not(feature = "daita")))]
1010
use once_cell::sync::Lazy;
1111
#[cfg(target_os = "android")]
1212
use std::borrow::Cow;
13-
#[cfg(target_os = "linux")]
13+
#[cfg(all(target_os = "linux", not(feature = "daita")))]
1414
use std::env;
1515
#[cfg(windows)]
1616
use std::io;
@@ -199,7 +199,7 @@ impl Drop for ObfuscatorHandle {
199199
}
200200
}
201201

202-
#[cfg(target_os = "linux")]
202+
#[cfg(all(target_os = "linux", not(feature = "daita")))]
203203
/// Overrides the preference for the kernel module for WireGuard.
204204
static FORCE_USERSPACE_WIREGUARD: Lazy<bool> = Lazy::new(|| {
205205
env::var("TALPID_FORCE_USERSPACE_WIREGUARD")
@@ -753,21 +753,20 @@ impl WireguardMonitor {
753753
Ok(ephemeral.psk)
754754
}
755755

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")))]
758761
fn open_tunnel(
759762
runtime: tokio::runtime::Handle,
760763
config: &Config,
761764
log_path: Option<&Path>,
762-
resource_dir: &Path,
765+
_resource_dir: &Path,
763766
tun_provider: Arc<Mutex<TunProvider>>,
764-
#[cfg(target_os = "android")] gateway_only: bool,
765767
) -> Result<TunnelT> {
766768
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 {
771770
if will_nm_manage_dns() {
772771
match wireguard_kernel::NetworkManagerTunnel::new(runtime, config) {
773772
Ok(tunnel) => {
@@ -801,15 +800,14 @@ impl WireguardMonitor {
801800
}
802801
}
803802

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.
804806
#[cfg(wireguard_go)]
805807
{
806808
let routes =
807809
Self::get_tunnel_destinations(config).flat_map(Self::replace_default_prefixes);
808810

809-
#[cfg(target_os = "android")]
810-
let config = Self::patch_allowed_ips(config, gateway_only);
811-
812-
#[cfg(target_os = "linux")]
813811
log::debug!("Using userspace WireGuard implementation");
814812
Ok(Box::new(
815813
WgGoTunnel::start_tunnel(
@@ -826,7 +824,34 @@ impl WireguardMonitor {
826824
}
827825
}
828826

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"))]
830855
#[allow(unused_variables)]
831856
fn open_tunnel(
832857
runtime: tokio::runtime::Handle,
@@ -838,14 +863,11 @@ impl WireguardMonitor {
838863
) -> Result<TunnelT> {
839864
log::debug!("Tunnel MTU: {}", config.mtu);
840865

841-
let daita = true;
842866
let routes = Self::get_tunnel_destinations(config).flat_map(Self::replace_default_prefixes);
843867

844868
#[cfg(target_os = "android")]
845869
let config = Self::patch_allowed_ips(config, gateway_only);
846870

847-
#[cfg(target_os = "linux")]
848-
log::debug!("Using userspace WireGuard implementation");
849871
Ok(Box::new(
850872
WgGoTunnel::start_tunnel(
851873
#[allow(clippy::needless_borrow)]
@@ -860,6 +882,7 @@ impl WireguardMonitor {
860882
))
861883
}
862884

885+
/// Windows uses it's own version of `open_tunnel`.
863886
#[cfg(target_os = "windows")]
864887
#[allow(unused_variables)]
865888
fn open_tunnel(
@@ -1171,6 +1194,7 @@ pub enum TunnelError {
11711194
}
11721195

11731196
#[cfg(target_os = "linux")]
1197+
#[allow(dead_code)]
11741198
fn will_nm_manage_dns() -> bool {
11751199
use talpid_dbus::network_manager::NetworkManager;
11761200

talpid-wireguard/src/wireguard_kernel/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(not(feature = "daita"))]
12
use super::{Config, Tunnel, TunnelError};
23
use futures::future::{abortable, AbortHandle};
34
use netlink_packet_core::{constants::*, NetlinkDeserializable};

0 commit comments

Comments
 (0)