Skip to content

Commit a59f282

Browse files
Add daita as a cargo feature
Fix `wireguard-go` compilation on Android by adding a feature flag, `daita`, which is used to differentiate targets which supports daita, rather than using the targets themselves.
1 parent b3cf5d7 commit a59f282

File tree

30 files changed

+252
-116
lines changed

30 files changed

+252
-116
lines changed

mullvad-cli/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ rust-version.workspace = true
1010
[lints]
1111
workspace = true
1212

13+
[features]
14+
daita = ["talpid-types/daita"]
15+
1316
[[bin]]
1417
name = "mullvad"
1518
path = "src/main.rs"

mullvad-cli/src/cmds/relay.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl Relay {
542542
allowed_ips: all_of_the_internet(),
543543
endpoint: SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), port),
544544
psk: None,
545-
#[cfg(any(target_os = "windows", target_os = "linux"))]
545+
#[cfg(feature = "daita")]
546546
constant_packet_size: false,
547547
},
548548
exit_peer: None,

mullvad-cli/src/cmds/tunnel.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use clap::Subcommand;
33
use mullvad_management_interface::MullvadProxyClient;
4-
#[cfg(any(target_os = "windows", target_os = "linux"))]
4+
#[cfg(feature = "daita")]
55
use mullvad_types::wireguard::DaitaSettings;
66
use mullvad_types::{
77
constraints::Constraint,
@@ -41,7 +41,7 @@ pub enum TunnelOptions {
4141
#[arg(long)]
4242
quantum_resistant: Option<QuantumResistantState>,
4343
/// Configure whether to enable DAITA
44-
#[cfg(any(target_os = "windows", target_os = "linux"))]
44+
#[cfg(feature = "daita")]
4545
#[arg(long)]
4646
daita: Option<BooleanOption>,
4747
/// The key rotation interval. Number of hours, or 'any'
@@ -101,7 +101,7 @@ impl Tunnel {
101101
tunnel_options.wireguard.quantum_resistant,
102102
);
103103

104-
#[cfg(any(target_os = "windows", target_os = "linux"))]
104+
#[cfg(feature = "daita")]
105105
print_option!("DAITA", tunnel_options.wireguard.daita.enabled);
106106

107107
let key = rpc.get_wireguard_key().await?;
@@ -138,15 +138,15 @@ impl Tunnel {
138138
TunnelOptions::Wireguard {
139139
mtu,
140140
quantum_resistant,
141-
#[cfg(any(target_os = "windows", target_os = "linux"))]
141+
#[cfg(feature = "daita")]
142142
daita,
143143
rotation_interval,
144144
rotate_key,
145145
} => {
146146
Self::handle_wireguard(
147147
mtu,
148148
quantum_resistant,
149-
#[cfg(any(target_os = "windows", target_os = "linux"))]
149+
#[cfg(feature = "daita")]
150150
daita,
151151
rotation_interval,
152152
rotate_key,
@@ -178,7 +178,7 @@ impl Tunnel {
178178
async fn handle_wireguard(
179179
mtu: Option<Constraint<u16>>,
180180
quantum_resistant: Option<QuantumResistantState>,
181-
#[cfg(any(target_os = "windows", target_os = "linux"))] daita: Option<BooleanOption>,
181+
#[cfg(feature = "daita")] daita: Option<BooleanOption>,
182182
rotation_interval: Option<Constraint<RotationInterval>>,
183183
rotate_key: Option<RotateKey>,
184184
) -> Result<()> {
@@ -194,7 +194,7 @@ impl Tunnel {
194194
println!("Quantum resistant setting has been updated");
195195
}
196196

197-
#[cfg(any(target_os = "windows", target_os = "linux"))]
197+
#[cfg(feature = "daita")]
198198
if let Some(daita) = daita {
199199
rpc.set_daita_settings(DaitaSettings { enabled: *daita })
200200
.await?;

mullvad-cli/src/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ fn format_relay_connection(
174174
"\nQuantum resistant tunnel: no"
175175
};
176176

177-
#[cfg(any(target_os = "windows", target_os = "linux"))]
177+
#[cfg(feature = "daita")]
178178
let daita = if !verbose {
179179
""
180180
} else if endpoint.daita {
181181
"\nDAITA: yes"
182182
} else {
183183
"\nDAITA: no"
184184
};
185-
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
185+
#[cfg(not(feature = "daita"))]
186186
let daita = "";
187187

188188
let mut bridge_type = String::new();

mullvad-daemon/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use mullvad_relay_selector::{
4343
};
4444
#[cfg(target_os = "android")]
4545
use mullvad_types::account::{PlayPurchase, PlayPurchasePaymentToken};
46-
#[cfg(any(target_os = "windows", target_os = "linux"))]
46+
#[cfg(feature = "daita")]
4747
use mullvad_types::wireguard::DaitaSettings;
4848
use mullvad_types::{
4949
access_method::{AccessMethod, AccessMethodSetting},
@@ -258,7 +258,7 @@ pub enum DaemonCommand {
258258
/// Set whether to enable PQ PSK exchange in the tunnel
259259
SetQuantumResistantTunnel(ResponseTx<(), settings::Error>, QuantumResistantState),
260260
/// Set DAITA settings for the tunnel
261-
#[cfg(any(target_os = "windows", target_os = "linux"))]
261+
#[cfg(feature = "daita")]
262262
SetDaitaSettings(ResponseTx<(), settings::Error>, DaitaSettings),
263263
/// Set DNS options or servers to use
264264
SetDnsOptions(ResponseTx<(), settings::Error>, DnsOptions),
@@ -1229,7 +1229,7 @@ where
12291229
self.on_set_quantum_resistant_tunnel(tx, quantum_resistant_state)
12301230
.await
12311231
}
1232-
#[cfg(any(target_os = "windows", target_os = "linux"))]
1232+
#[cfg(feature = "daita")]
12331233
SetDaitaSettings(tx, daita_settings) => {
12341234
self.on_set_daita_settings(tx, daita_settings).await
12351235
}
@@ -2285,7 +2285,7 @@ where
22852285
}
22862286
}
22872287

2288-
#[cfg(any(target_os = "windows", target_os = "linux"))]
2288+
#[cfg(feature = "daita")]
22892289
async fn on_set_daita_settings(
22902290
&mut self,
22912291
tx: ResponseTx<(), settings::Error>,
@@ -2842,9 +2842,9 @@ impl DaemonShutdownHandle {
28422842
fn new_selector_config(settings: &Settings) -> SelectorConfig {
28432843
let additional_constraints = AdditionalRelayConstraints {
28442844
wireguard: AdditionalWireguardConstraints {
2845-
#[cfg(target_os = "windows")]
2845+
#[cfg(feature = "daita")]
28462846
daita: settings.tunnel_options.wireguard.daita.enabled,
2847-
#[cfg(not(target_os = "windows"))]
2847+
#[cfg(not(feature = "daita"))]
28482848
daita: false,
28492849
},
28502850
};

mullvad-daemon/src/management_interface.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl ManagementService for ManagementServiceImpl {
325325
Ok(Response::new(()))
326326
}
327327

328-
#[cfg(any(target_os = "windows", target_os = "linux"))]
328+
#[cfg(feature = "daita")]
329329
async fn set_daita_settings(
330330
&self,
331331
request: Request<types::DaitaSettings>,
@@ -339,7 +339,7 @@ impl ManagementService for ManagementServiceImpl {
339339
Ok(Response::new(()))
340340
}
341341

342-
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
342+
#[cfg(not(feature = "daita"))]
343343
async fn set_daita_settings(&self, _: Request<types::DaitaSettings>) -> ServiceResult<()> {
344344
Ok(Response::new(()))
345345
}

mullvad-management-interface/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ rust-version.workspace = true
1010
[lints]
1111
workspace = true
1212

13+
[features]
14+
daita = ["talpid-types/daita"]
15+
1316
[dependencies]
1417
chrono = { workspace = true }
1518
thiserror = { workspace = true }

mullvad-management-interface/src/client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::types;
44
use futures::{Stream, StreamExt};
5-
#[cfg(any(target_os = "windows", target_os = "linux"))]
5+
#[cfg(feature = "daita")]
66
use mullvad_types::wireguard::DaitaSettings;
77
use mullvad_types::{
88
access_method::{self, AccessMethod, AccessMethodSetting},
@@ -346,7 +346,7 @@ impl MullvadProxyClient {
346346
Ok(())
347347
}
348348

349-
#[cfg(any(target_os = "windows", target_os = "linux"))]
349+
#[cfg(feature = "daita")]
350350
pub async fn set_daita_settings(&mut self, settings: DaitaSettings) -> Result<()> {
351351
let settings = types::DaitaSettings::from(settings);
352352
self.0

mullvad-management-interface/src/types/conversions/custom_tunnel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl TryFrom<proto::ConnectionConfig> for mullvad_types::ConnectionConfig {
9191
allowed_ips,
9292
endpoint,
9393
psk: None,
94-
#[cfg(any(target_os = "windows", target_os = "linux"))]
94+
#[cfg(feature = "daita")]
9595
constant_packet_size: false,
9696
},
9797
exit_peer: None,

mullvad-management-interface/src/types/conversions/net.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ impl From<talpid_types::net::TunnelEndpoint> for proto::TunnelEndpoint {
4040
tunnel_metadata: endpoint
4141
.tunnel_interface
4242
.map(|tunnel_interface| proto::TunnelMetadata { tunnel_interface }),
43-
#[cfg(any(target_os = "windows", target_os = "linux"))]
43+
#[cfg(feature = "daita")]
4444
daita: endpoint.daita,
45-
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
45+
#[cfg(not(feature = "daita"))]
4646
daita: false,
4747
}
4848
}
@@ -127,7 +127,7 @@ impl TryFrom<proto::TunnelEndpoint> for talpid_types::net::TunnelEndpoint {
127127
tunnel_interface: endpoint
128128
.tunnel_metadata
129129
.map(|tunnel_metadata| tunnel_metadata.tunnel_interface),
130-
#[cfg(any(target_os = "windows", target_os = "linux"))]
130+
#[cfg(feature = "daita")]
131131
daita: endpoint.daita,
132132
})
133133
}

mullvad-management-interface/src/types/conversions/settings.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ impl From<&mullvad_types::settings::TunnelOptions> for proto::TunnelOptions {
9797
.expect("Failed to convert std::time::Duration to prost_types::Duration for tunnel_options.wireguard.rotation_interval")
9898
}),
9999
quantum_resistant: Some(proto::QuantumResistantState::from(options.wireguard.quantum_resistant)),
100-
#[cfg(any(target_os = "windows", target_os = "linux"))]
100+
#[cfg(feature = "daita")]
101101
daita: Some(proto::DaitaSettings::from(options.wireguard.daita.clone())),
102-
#[cfg(not(any(target_os = "windows", target_os = "linux")))]
102+
#[cfg(not(feature = "daita"))]
103103
daita: None,
104104
}),
105105
generic: Some(proto::tunnel_options::GenericOptions {
@@ -286,7 +286,7 @@ impl TryFrom<proto::TunnelOptions> for mullvad_types::settings::TunnelOptions {
286286
.ok_or(FromProtobufTypeError::InvalidArgument(
287287
"missing quantum resistant state",
288288
))??,
289-
#[cfg(any(target_os = "windows", target_os = "linux"))]
289+
#[cfg(feature = "daita")]
290290
daita: wireguard_options
291291
.daita
292292
.map(mullvad_types::wireguard::DaitaSettings::from)

mullvad-management-interface/src/types/conversions/wireguard.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl TryFrom<proto::QuantumResistantState> for mullvad_types::wireguard::Quantum
7373
}
7474
}
7575

76-
#[cfg(any(target_os = "windows", target_os = "linux"))]
76+
#[cfg(feature = "daita")]
7777
impl From<mullvad_types::wireguard::DaitaSettings> for proto::DaitaSettings {
7878
fn from(settings: mullvad_types::wireguard::DaitaSettings) -> Self {
7979
proto::DaitaSettings {
@@ -82,7 +82,7 @@ impl From<mullvad_types::wireguard::DaitaSettings> for proto::DaitaSettings {
8282
}
8383
}
8484

85-
#[cfg(any(target_os = "windows", target_os = "linux"))]
85+
#[cfg(feature = "daita")]
8686
impl From<proto::DaitaSettings> for mullvad_types::wireguard::DaitaSettings {
8787
fn from(settings: proto::DaitaSettings) -> Self {
8888
mullvad_types::wireguard::DaitaSettings {

mullvad-relay-selector/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ rust-version.workspace = true
1010
[lints]
1111
workspace = true
1212

13+
[features]
14+
daita = ["talpid-types/daita"]
15+
1316
[dependencies]
1417
chrono = { workspace = true }
1518
thiserror = { workspace = true }

mullvad-relay-selector/src/relay_selector/detailer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn wireguard_singlehop_endpoint(
8585
// This will be filled in later, not the relay selector's problem
8686
psk: None,
8787
// This will be filled in later
88-
#[cfg(any(target_os = "windows", target_os = "linux"))]
88+
#[cfg(feature = "daita")]
8989
constant_packet_size: false,
9090
};
9191
Ok(MullvadWireguardEndpoint {
@@ -126,7 +126,7 @@ fn wireguard_multihop_endpoint(
126126
// This will be filled in later, not the relay selector's problem
127127
psk: None,
128128
// This will be filled in later
129-
#[cfg(any(target_os = "windows", target_os = "linux"))]
129+
#[cfg(feature = "daita")]
130130
constant_packet_size: false,
131131
};
132132

@@ -144,7 +144,7 @@ fn wireguard_multihop_endpoint(
144144
// This will be filled in later
145145
psk: None,
146146
// This will be filled in later
147-
#[cfg(any(target_os = "windows", target_os = "linux"))]
147+
#[cfg(feature = "daita")]
148148
constant_packet_size: false,
149149
};
150150

mullvad-types/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ rust-version.workspace = true
1010
[lints]
1111
workspace = true
1212

13+
[features]
14+
daita = ["talpid-types/daita"]
15+
1316
[dependencies]
1417
chrono = { workspace = true, features = ["clock", "serde"] }
1518
thiserror = { workspace = true }

mullvad-types/src/wireguard.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ impl FromStr for QuantumResistantState {
5555
#[error("Not a valid state")]
5656
pub struct QuantumResistantStateParseError;
5757

58-
#[cfg(any(target_os = "windows", target_os = "linux"))]
58+
#[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
}
@@ -208,7 +210,7 @@ pub struct TunnelOptions {
208210
/// Obtain a PSK using the relay config client.
209211
pub quantum_resistant: QuantumResistantState,
210212
/// Configure DAITA
211-
#[cfg(any(target_os = "windows", target_os = "linux"))]
213+
#[cfg(feature = "daita")]
212214
pub daita: DaitaSettings,
213215
/// Interval used for automatic key rotation
214216
#[cfg_attr(target_os = "android", jnix(skip))]
@@ -221,7 +223,7 @@ impl Default for TunnelOptions {
221223
TunnelOptions {
222224
mtu: None,
223225
quantum_resistant: QuantumResistantState::Auto,
224-
#[cfg(any(target_os = "windows", target_os = "linux"))]
226+
#[cfg(feature = "daita")]
225227
daita: DaitaSettings::default(),
226228
rotation_interval: None,
227229
}
@@ -237,7 +239,7 @@ impl TunnelOptions {
237239
QuantumResistantState::On => true,
238240
QuantumResistantState::Off => false,
239241
},
240-
#[cfg(any(target_os = "windows", target_os = "linux"))]
242+
#[cfg(feature = "daita")]
241243
daita: self.daita.enabled,
242244
}
243245
}

talpid-types/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ rust-version.workspace = true
1010
[lints]
1111
workspace = true
1212

13+
[features]
14+
daita = []
15+
1316
[dependencies]
1417
serde = { version = "1.0", features = ["derive"] }
1518
ipnetwork = "0.16"

talpid-types/src/net/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl TunnelParameters {
4040
obfuscation: None,
4141
entry_endpoint: None,
4242
tunnel_interface: None,
43-
#[cfg(any(target_os = "windows", target_os = "linux"))]
43+
#[cfg(feature = "daita")]
4444
daita: false,
4545
},
4646
TunnelParameters::Wireguard(params) => TunnelEndpoint {
@@ -57,7 +57,7 @@ impl TunnelParameters {
5757
.get_exit_endpoint()
5858
.map(|_| params.connection.get_endpoint()),
5959
tunnel_interface: None,
60-
#[cfg(any(target_os = "windows", target_os = "linux"))]
60+
#[cfg(feature = "daita")]
6161
daita: params.options.daita,
6262
},
6363
}
@@ -187,7 +187,7 @@ pub struct TunnelEndpoint {
187187
pub entry_endpoint: Option<Endpoint>,
188188
#[cfg_attr(target_os = "android", jnix(skip))]
189189
pub tunnel_interface: Option<String>,
190-
#[cfg(any(target_os = "windows", target_os = "linux"))]
190+
#[cfg(feature = "daita")]
191191
pub daita: bool,
192192
}
193193

0 commit comments

Comments
 (0)