summaryrefslogtreecommitdiffhomepage
path: root/talpid-core/src
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-10-19 12:12:40 +0200
committerDavid Lönnhager <david.l@mullvad.net>2020-10-22 09:33:59 +0200
commit83290680cc26ced9963f1798cd2290f309b01132 (patch)
tree5b819799d1713b433b2b5369d0b7d49b965783df /talpid-core/src
parenta4125e81f559bebf24e94934676537270e2dc917 (diff)
downloadmullvadvpn-83290680cc26ced9963f1798cd2290f309b01132.tar.xz
mullvadvpn-83290680cc26ced9963f1798cd2290f309b01132.zip
Use custom DNS setting on Windows only
Diffstat (limited to 'talpid-core/src')
-rw-r--r--talpid-core/src/firewall/mod.rs1
-rw-r--r--talpid-core/src/tunnel_state_machine/connected_state.rs19
-rw-r--r--talpid-core/src/tunnel_state_machine/connecting_state.rs1
-rw-r--r--talpid-core/src/tunnel_state_machine/disconnected_state.rs1
-rw-r--r--talpid-core/src/tunnel_state_machine/disconnecting_state.rs3
-rw-r--r--talpid-core/src/tunnel_state_machine/error_state.rs1
-rw-r--r--talpid-core/src/tunnel_state_machine/mod.rs11
7 files changed, 30 insertions, 7 deletions
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>,