summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-12-03 20:29:40 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-12-04 13:18:17 +0000
commitb66a0f208ffcaac0a5603a4fa590d9445f6325eb (patch)
treef3ea773b7b9fd73b4ffe31773ca5b8fd6ff09276
parent376e15e48aa7d23f4c30262628e5e053f8292349 (diff)
downloadmullvadvpn-b66a0f208ffcaac0a5603a4fa590d9445f6325eb.tar.xz
mullvadvpn-b66a0f208ffcaac0a5603a4fa590d9445f6325eb.zip
Notify tun provider when custom DNS servers change
-rw-r--r--talpid-core/src/tunnel_state_machine/connected_state.rs43
-rw-r--r--talpid-core/src/tunnel_state_machine/connecting_state.rs7
-rw-r--r--talpid-core/src/tunnel_state_machine/disconnected_state.rs6
-rw-r--r--talpid-core/src/tunnel_state_machine/disconnecting_state.rs6
-rw-r--r--talpid-core/src/tunnel_state_machine/error_state.rs7
-rw-r--r--talpid-core/src/tunnel_state_machine/mod.rs25
6 files changed, 65 insertions, 29 deletions
diff --git a/talpid-core/src/tunnel_state_machine/connected_state.rs b/talpid-core/src/tunnel_state_machine/connected_state.rs
index f3139715c8..b150d32481 100644
--- a/talpid-core/src/tunnel_state_machine/connected_state.rs
+++ b/talpid-core/src/tunnel_state_machine/connected_state.rs
@@ -193,26 +193,35 @@ impl ConnectedState {
}
}
Some(TunnelCommand::CustomDns(servers)) => {
- if shared_values.set_custom_dns(servers) {
- if let Err(error) = self.set_firewall_policy(shared_values) {
- return self.disconnect(
- shared_values,
- AfterDisconnect::Block(ErrorStateCause::SetFirewallPolicyError(error)),
- );
- }
-
- match self.set_dns(shared_values) {
- Ok(()) => SameState(self.into()),
- Err(error) => {
- log::error!("{}", error.display_chain_with_msg("Failed to set DNS"));
- self.disconnect(
+ match shared_values.set_custom_dns(servers) {
+ Ok(true) => {
+ if let Err(error) = self.set_firewall_policy(shared_values) {
+ return self.disconnect(
shared_values,
- AfterDisconnect::Block(ErrorStateCause::SetDnsError),
- )
+ AfterDisconnect::Block(ErrorStateCause::SetFirewallPolicyError(
+ error,
+ )),
+ );
+ }
+
+ match self.set_dns(shared_values) {
+ Ok(()) => SameState(self.into()),
+ Err(error) => {
+ log::error!(
+ "{}",
+ error.display_chain_with_msg("Failed to set DNS")
+ );
+ self.disconnect(
+ shared_values,
+ AfterDisconnect::Block(ErrorStateCause::SetDnsError),
+ )
+ }
}
}
- } else {
- SameState(self.into())
+ Ok(false) => SameState(self.into()),
+ Err(error_cause) => {
+ self.disconnect(shared_values, AfterDisconnect::Block(error_cause))
+ }
}
}
Some(TunnelCommand::BlockWhenDisconnected(block_when_disconnected)) => {
diff --git a/talpid-core/src/tunnel_state_machine/connecting_state.rs b/talpid-core/src/tunnel_state_machine/connecting_state.rs
index 5bf6d98766..4077f6ad5e 100644
--- a/talpid-core/src/tunnel_state_machine/connecting_state.rs
+++ b/talpid-core/src/tunnel_state_machine/connecting_state.rs
@@ -236,8 +236,11 @@ impl ConnectingState {
}
}
Some(TunnelCommand::CustomDns(servers)) => {
- shared_values.set_custom_dns(servers);
- SameState(self.into())
+ if let Err(error_cause) = shared_values.set_custom_dns(servers) {
+ self.disconnect(shared_values, AfterDisconnect::Block(error_cause))
+ } else {
+ SameState(self.into())
+ }
}
Some(TunnelCommand::BlockWhenDisconnected(block_when_disconnected)) => {
shared_values.block_when_disconnected = block_when_disconnected;
diff --git a/talpid-core/src/tunnel_state_machine/disconnected_state.rs b/talpid-core/src/tunnel_state_machine/disconnected_state.rs
index 9368a832ef..dcc4660e9f 100644
--- a/talpid-core/src/tunnel_state_machine/disconnected_state.rs
+++ b/talpid-core/src/tunnel_state_machine/disconnected_state.rs
@@ -78,7 +78,11 @@ impl TunnelState for DisconnectedState {
SameState(self.into())
}
Some(TunnelCommand::CustomDns(servers)) => {
- shared_values.set_custom_dns(servers);
+ // Same situation as allow LAN above.
+ shared_values
+ .set_custom_dns(servers)
+ .expect("Failed to reconnect after changing custom DNS servers");
+
SameState(self.into())
}
Some(TunnelCommand::BlockWhenDisconnected(block_when_disconnected)) => {
diff --git a/talpid-core/src/tunnel_state_machine/disconnecting_state.rs b/talpid-core/src/tunnel_state_machine/disconnecting_state.rs
index 48d8d66c05..0928834d1c 100644
--- a/talpid-core/src/tunnel_state_machine/disconnecting_state.rs
+++ b/talpid-core/src/tunnel_state_machine/disconnecting_state.rs
@@ -33,7 +33,7 @@ impl DisconnectingState {
AfterDisconnect::Nothing
}
Some(TunnelCommand::CustomDns(servers)) => {
- shared_values.set_custom_dns(servers);
+ let _ = shared_values.set_custom_dns(servers);
AfterDisconnect::Nothing
}
Some(TunnelCommand::BlockWhenDisconnected(block_when_disconnected)) => {
@@ -54,7 +54,7 @@ impl DisconnectingState {
AfterDisconnect::Block(reason)
}
Some(TunnelCommand::CustomDns(servers)) => {
- shared_values.set_custom_dns(servers);
+ let _ = shared_values.set_custom_dns(servers);
AfterDisconnect::Block(reason)
}
Some(TunnelCommand::BlockWhenDisconnected(block_when_disconnected)) => {
@@ -80,7 +80,7 @@ impl DisconnectingState {
AfterDisconnect::Reconnect(retry_attempt)
}
Some(TunnelCommand::CustomDns(servers)) => {
- shared_values.set_custom_dns(servers);
+ let _ = shared_values.set_custom_dns(servers);
AfterDisconnect::Reconnect(retry_attempt)
}
Some(TunnelCommand::BlockWhenDisconnected(block_when_disconnected)) => {
diff --git a/talpid-core/src/tunnel_state_machine/error_state.rs b/talpid-core/src/tunnel_state_machine/error_state.rs
index 11236e3f62..a87dccd5b4 100644
--- a/talpid-core/src/tunnel_state_machine/error_state.rs
+++ b/talpid-core/src/tunnel_state_machine/error_state.rs
@@ -106,8 +106,11 @@ impl TunnelState for ErrorState {
}
}
Some(TunnelCommand::CustomDns(servers)) => {
- shared_values.set_custom_dns(servers);
- SameState(self.into())
+ if let Err(error_state_cause) = shared_values.set_custom_dns(servers) {
+ NewState(Self::enter(shared_values, error_state_cause))
+ } else {
+ SameState(self.into())
+ }
}
Some(TunnelCommand::BlockWhenDisconnected(block_when_disconnected)) => {
shared_values.block_when_disconnected = block_when_disconnected;
diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs
index fb00dfab55..adafe9f16e 100644
--- a/talpid-core/src/tunnel_state_machine/mod.rs
+++ b/talpid-core/src/tunnel_state_machine/mod.rs
@@ -328,12 +328,29 @@ impl SharedTunnelStateValues {
Ok(())
}
- pub fn set_custom_dns(&mut self, custom_dns: Option<Vec<IpAddr>>) -> bool {
+ pub fn set_custom_dns(
+ &mut self,
+ custom_dns: Option<Vec<IpAddr>>,
+ ) -> Result<bool, ErrorStateCause> {
if self.custom_dns != custom_dns {
- self.custom_dns = custom_dns;
- true
+ self.custom_dns = custom_dns.clone();
+
+ #[cfg(target_os = "android")]
+ {
+ if let Err(error) = self.tun_provider.set_custom_dns_servers(custom_dns) {
+ log::error!(
+ "{}",
+ error.display_chain_with_msg(
+ "Failed to restart tunnel after changing custom DNS servers",
+ )
+ );
+ return Err(ErrorStateCause::StartTunnelError);
+ }
+ }
+
+ Ok(true)
} else {
- false
+ Ok(false)
}
}