diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-10-19 12:12:40 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-10-22 09:33:59 +0200 |
| commit | 83290680cc26ced9963f1798cd2290f309b01132 (patch) | |
| tree | 5b819799d1713b433b2b5369d0b7d49b965783df | |
| parent | a4125e81f559bebf24e94934676537270e2dc917 (diff) | |
| download | mullvadvpn-83290680cc26ced9963f1798cd2290f309b01132.tar.xz mullvadvpn-83290680cc26ced9963f1798cd2290f309b01132.zip | |
Use custom DNS setting on Windows only
| -rw-r--r-- | mullvad-cli/src/cmds/mod.rs | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 8 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 8 | ||||
| -rw-r--r-- | mullvad-daemon/src/settings.rs | 4 | ||||
| -rw-r--r-- | mullvad-types/src/settings/mod.rs | 1 | ||||
| -rw-r--r-- | talpid-core/src/firewall/mod.rs | 1 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/connected_state.rs | 19 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/connecting_state.rs | 1 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/disconnected_state.rs | 1 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/disconnecting_state.rs | 3 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/error_state.rs | 1 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/mod.rs | 11 | ||||
| -rw-r--r-- | talpid-types/src/net/mod.rs | 1 |
13 files changed, 50 insertions, 10 deletions
diff --git a/mullvad-cli/src/cmds/mod.rs b/mullvad-cli/src/cmds/mod.rs index ae3739289e..d542eb7844 100644 --- a/mullvad-cli/src/cmds/mod.rs +++ b/mullvad-cli/src/cmds/mod.rs @@ -63,6 +63,7 @@ pub fn get_commands() -> HashMap<&'static str, Box<dyn Command>> { Box::new(Disconnect), Box::new(Reconnect), Box::new(Lan), + #[cfg(windows)] Box::new(CustomDns), Box::new(Relay), Box::new(Reset), diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 3acf4eb11d..7f5b85f7e0 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -41,6 +41,8 @@ use mullvad_types::{ wireguard::KeygenEvent, }; use settings::SettingsPersister; +#[cfg(windows)] +use std::net::IpAddr; #[cfg(not(target_os = "android"))] use std::path::Path; use std::{ @@ -48,7 +50,6 @@ use std::{ io, marker::PhantomData, mem, - net::IpAddr, path::PathBuf, sync::{mpsc as sync_mpsc, Arc, Weak}, time::Duration, @@ -194,6 +195,7 @@ pub enum DaemonCommand { /// Set if IPv6 should be enabled in the tunnel SetEnableIpv6(oneshot::Sender<()>, bool), /// Set custom DNS servers to use instead of passing requests to the gateway + #[cfg(windows)] SetCustomDns(oneshot::Sender<()>, Option<Vec<IpAddr>>), /// Set MTU for wireguard tunnels SetWireguardMtu(oneshot::Sender<()>, Option<u16>), @@ -575,10 +577,10 @@ where TargetState::Unsecured }; - let tunnel_command_tx = tunnel_state_machine::spawn( settings.allow_lan, settings.block_when_disconnected, + #[cfg(windows)] settings.tunnel_options.generic.custom_dns.clone(), tunnel_parameters_generator, log_dir, @@ -1043,6 +1045,7 @@ where } SetBridgeState(tx, bridge_state) => self.on_set_bridge_state(tx, bridge_state), SetEnableIpv6(tx, enable_ipv6) => self.on_set_enable_ipv6(tx, enable_ipv6), + #[cfg(windows)] SetCustomDns(tx, dns_servers) => self.on_set_custom_dns(tx, dns_servers), SetWireguardMtu(tx, mtu) => self.on_set_wireguard_mtu(tx, mtu), SetWireguardRotationInterval(tx, interval) => { @@ -1682,6 +1685,7 @@ where } } + #[cfg(windows)] fn on_set_custom_dns(&mut self, tx: oneshot::Sender<()>, servers: Option<Vec<IpAddr>>) { let save_result = self.settings.set_custom_dns(servers.clone()); match save_result { diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 50caacc005..a5cfebedc3 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -408,6 +408,7 @@ impl ManagementService for ManagementServiceImpl { .map_err(|_| Status::internal("internal error")) } + #[cfg(windows)] async fn set_custom_dns(&self, request: Request<types::CustomDns>) -> ServiceResult<()> { let servers = request.into_inner(); log::debug!("set_custom_dns({:?})", servers.addresses); @@ -434,6 +435,10 @@ impl ManagementService for ManagementServiceImpl { .map(Response::new) .map_err(|_| Status::internal("internal error")) } + #[cfg(not(windows))] + async fn set_custom_dns(&self, _: Request<types::CustomDns>) -> ServiceResult<()> { + Ok(Response::new(())) + } // Account management // @@ -1167,6 +1172,7 @@ fn convert_tunnel_options(options: &TunnelOptions) -> types::TunnelOptions { }), generic: Some(types::tunnel_options::GenericOptions { enable_ipv6: options.generic.enable_ipv6, + #[cfg(windows)] custom_dns: options .generic .custom_dns @@ -1174,6 +1180,8 @@ fn convert_tunnel_options(options: &TunnelOptions) -> types::TunnelOptions { .map(|addresses| types::CustomDns { addresses: addresses.iter().map(|addr| addr.to_string()).collect(), }), + #[cfg(not(windows))] + custom_dns: None, }), } } diff --git a/mullvad-daemon/src/settings.rs b/mullvad-daemon/src/settings.rs index c0a983fe51..1f6f6a447c 100644 --- a/mullvad-daemon/src/settings.rs +++ b/mullvad-daemon/src/settings.rs @@ -3,10 +3,11 @@ use mullvad_types::{ relay_constraints::{BridgeSettings, BridgeState, RelaySettingsUpdate}, settings::Settings, }; +#[cfg(windows)] +use std::net::IpAddr; use std::{ fs::{self, File}, io, - net::IpAddr, ops::Deref, path::{Path, PathBuf}, }; @@ -211,6 +212,7 @@ impl SettingsPersister { self.update(should_save) } + #[cfg(windows)] pub fn set_custom_dns(&mut self, servers: Option<Vec<IpAddr>>) -> Result<bool, Error> { let should_save = Self::update_field( &mut self.settings.tunnel_options.generic.custom_dns, diff --git a/mullvad-types/src/settings/mod.rs b/mullvad-types/src/settings/mod.rs index beb1b52256..2b8ce221b8 100644 --- a/mullvad-types/src/settings/mod.rs +++ b/mullvad-types/src/settings/mod.rs @@ -177,6 +177,7 @@ impl Default for TunnelOptions { generic: GenericTunnelOptions { // Enable IPv6 be default on Android enable_ipv6: cfg!(target_os = "android"), + #[cfg(windows)] custom_dns: None, }, } diff --git a/talpid-core/src/firewall/mod.rs b/talpid-core/src/firewall/mod.rs index 9c7cff22b1..b427e459d5 100644 --- a/talpid-core/src/firewall/mod.rs +++ b/talpid-core/src/firewall/mod.rs @@ -112,6 +112,7 @@ pub enum FirewallPolicy { /// Flag setting if communication with LAN networks should be possible. allow_lan: bool, /// Servers that are allowed to respond to DNS requests. + #[cfg(windows)] dns_servers: Vec<IpAddr>, /// A process that is allowed to send packets to the relay. #[cfg(windows)] diff --git a/talpid-core/src/tunnel_state_machine/connected_state.rs b/talpid-core/src/tunnel_state_machine/connected_state.rs index c4b7458960..a7fd495c50 100644 --- a/talpid-core/src/tunnel_state_machine/connected_state.rs +++ b/talpid-core/src/tunnel_state_machine/connected_state.rs @@ -76,7 +76,9 @@ impl ConnectedState { }) } + #[allow(unused_variables)] fn get_dns_servers(&self, shared_values: &SharedTunnelStateValues) -> Vec<IpAddr> { + #[cfg(windows)] if let Some(ref servers) = shared_values.custom_dns { servers.clone() } else { @@ -87,6 +89,15 @@ impl ConnectedState { }; dns_ips } + #[cfg(not(windows))] + { + let mut dns_ips = vec![]; + dns_ips.push(self.metadata.ipv4_gateway.into()); + if let Some(ipv6_gateway) = self.metadata.ipv6_gateway { + dns_ips.push(ipv6_gateway.into()); + }; + dns_ips + } } fn get_firewall_policy(&self, shared_values: &SharedTunnelStateValues) -> FirewallPolicy { @@ -94,6 +105,7 @@ impl ConnectedState { peer_endpoint: self.tunnel_parameters.get_next_hop_endpoint(), tunnel: self.metadata.clone(), allow_lan: shared_values.allow_lan, + #[cfg(windows)] dns_servers: self.get_dns_servers(shared_values), #[cfg(windows)] relay_client: TunnelMonitor::get_relay_client( @@ -106,12 +118,10 @@ impl ConnectedState { } fn set_dns(&self, shared_values: &mut SharedTunnelStateValues) -> Result<(), BoxedError> { + let dns_ips = self.get_dns_servers(shared_values); shared_values .dns_monitor - .set( - &self.metadata.interface, - &self.get_dns_servers(shared_values), - ) + .set(&self.metadata.interface, &dns_ips) .map_err(BoxedError::new)?; #[cfg(target_os = "linux")] @@ -172,6 +182,7 @@ impl ConnectedState { } } } + #[cfg(windows)] Some(TunnelCommand::CustomDns(servers)) => { if shared_values.custom_dns != servers { shared_values.custom_dns = servers; diff --git a/talpid-core/src/tunnel_state_machine/connecting_state.rs b/talpid-core/src/tunnel_state_machine/connecting_state.rs index 8fde71cc98..6f081697e5 100644 --- a/talpid-core/src/tunnel_state_machine/connecting_state.rs +++ b/talpid-core/src/tunnel_state_machine/connecting_state.rs @@ -227,6 +227,7 @@ impl ConnectingState { } } } + #[cfg(windows)] Some(TunnelCommand::CustomDns(servers)) => { shared_values.custom_dns = servers; SameState(self.into()) diff --git a/talpid-core/src/tunnel_state_machine/disconnected_state.rs b/talpid-core/src/tunnel_state_machine/disconnected_state.rs index 685925b922..4781f19091 100644 --- a/talpid-core/src/tunnel_state_machine/disconnected_state.rs +++ b/talpid-core/src/tunnel_state_machine/disconnected_state.rs @@ -82,6 +82,7 @@ impl TunnelState for DisconnectedState { } SameState(self.into()) } + #[cfg(windows)] Some(TunnelCommand::CustomDns(servers)) => { shared_values.custom_dns = servers; SameState(self.into()) diff --git a/talpid-core/src/tunnel_state_machine/disconnecting_state.rs b/talpid-core/src/tunnel_state_machine/disconnecting_state.rs index 9ecdd6dc88..356df9be53 100644 --- a/talpid-core/src/tunnel_state_machine/disconnecting_state.rs +++ b/talpid-core/src/tunnel_state_machine/disconnecting_state.rs @@ -32,6 +32,7 @@ impl DisconnectingState { let _ = shared_values.set_allow_lan(allow_lan); AfterDisconnect::Nothing } + #[cfg(windows)] Some(TunnelCommand::CustomDns(servers)) => { shared_values.custom_dns = servers; AfterDisconnect::Nothing @@ -53,6 +54,7 @@ impl DisconnectingState { let _ = shared_values.set_allow_lan(allow_lan); AfterDisconnect::Block(reason) } + #[cfg(windows)] Some(TunnelCommand::CustomDns(servers)) => { shared_values.custom_dns = servers; AfterDisconnect::Block(reason) @@ -79,6 +81,7 @@ impl DisconnectingState { let _ = shared_values.set_allow_lan(allow_lan); AfterDisconnect::Reconnect(retry_attempt) } + #[cfg(windows)] Some(TunnelCommand::CustomDns(servers)) => { shared_values.custom_dns = servers; AfterDisconnect::Reconnect(retry_attempt) diff --git a/talpid-core/src/tunnel_state_machine/error_state.rs b/talpid-core/src/tunnel_state_machine/error_state.rs index bf545258fe..aa53e0b0b5 100644 --- a/talpid-core/src/tunnel_state_machine/error_state.rs +++ b/talpid-core/src/tunnel_state_machine/error_state.rs @@ -102,6 +102,7 @@ impl TunnelState for ErrorState { SameState(self.into()) } } + #[cfg(windows)] Some(TunnelCommand::CustomDns(servers)) => { shared_values.custom_dns = servers; SameState(self.into()) diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs index 21119aa6ad..90bf9a5d29 100644 --- a/talpid-core/src/tunnel_state_machine/mod.rs +++ b/talpid-core/src/tunnel_state_machine/mod.rs @@ -24,10 +24,11 @@ use futures::{ channel::{mpsc, oneshot}, stream, StreamExt, }; +#[cfg(windows)] +use std::net::IpAddr; use std::{ collections::HashSet, io, - net::IpAddr, path::{Path, PathBuf}, sync::{mpsc as sync_mpsc, Arc}, }; @@ -75,7 +76,7 @@ pub enum Error { pub async fn spawn( allow_lan: bool, block_when_disconnected: bool, - custom_dns: Option<Vec<IpAddr>>, + #[cfg(windows)] custom_dns: Option<Vec<IpAddr>>, tunnel_parameters_generator: impl TunnelParametersGenerator, log_dir: Option<PathBuf>, resource_dir: PathBuf, @@ -111,6 +112,7 @@ pub async fn spawn( allow_lan, block_when_disconnected, is_offline, + #[cfg(windows)] custom_dns, tunnel_parameters_generator, tun_provider, @@ -151,6 +153,7 @@ pub enum TunnelCommand { /// Enable or disable LAN access in the firewall. AllowLan(bool), /// Set custom DNS servers to use. + #[cfg(windows)] CustomDns(Option<Vec<IpAddr>>), /// Enable or disable the block_when_disconnected feature. BlockWhenDisconnected(bool), @@ -189,7 +192,7 @@ impl TunnelStateMachine { allow_lan: bool, block_when_disconnected: bool, is_offline: bool, - custom_dns: Option<Vec<IpAddr>>, + #[cfg(windows)] custom_dns: Option<Vec<IpAddr>>, tunnel_parameters_generator: impl TunnelParametersGenerator, tun_provider: TunProvider, log_dir: Option<PathBuf>, @@ -214,6 +217,7 @@ impl TunnelStateMachine { allow_lan, block_when_disconnected, is_offline, + #[cfg(windows)] custom_dns, tunnel_parameters_generator: Box::new(tunnel_parameters_generator), tun_provider, @@ -285,6 +289,7 @@ struct SharedTunnelStateValues { /// True when the computer is known to be offline. is_offline: bool, /// Custom DNS servers to use. + #[cfg(windows)] custom_dns: Option<Vec<IpAddr>>, /// The generator of new `TunnelParameter`s tunnel_parameters_generator: Box<dyn TunnelParametersGenerator>, diff --git a/talpid-types/src/net/mod.rs b/talpid-types/src/net/mod.rs index 156462c3fc..36528e9744 100644 --- a/talpid-types/src/net/mod.rs +++ b/talpid-types/src/net/mod.rs @@ -204,6 +204,7 @@ pub struct GenericTunnelOptions { /// forwarded through the tunnel. pub enable_ipv6: bool, /// Custom DNS servers to use. + #[cfg(windows)] pub custom_dns: Option<Vec<IpAddr>>, } |
