diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2018-10-26 12:53:57 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2018-10-29 13:09:40 +0000 |
| commit | 55329a4fcd8d16cb2a94997c592c9518efced211 (patch) | |
| tree | c55cef9ad34304b093ce011cb54e00bf2ba6d98f | |
| parent | c7e120975687f3590969e8c571286cd2d2a9fc92 (diff) | |
| download | mullvadvpn-55329a4fcd8d16cb2a94997c592c9518efced211.tar.xz mullvadvpn-55329a4fcd8d16cb2a94997c592c9518efced211.zip | |
Reset DNS before setting DNS servers on Linux
| -rw-r--r-- | talpid-core/src/security/linux/dns/mod.rs | 7 | ||||
| -rw-r--r-- | talpid-core/src/security/linux/dns/network_manager.rs | 18 |
2 files changed, 13 insertions, 12 deletions
diff --git a/talpid-core/src/security/linux/dns/mod.rs b/talpid-core/src/security/linux/dns/mod.rs index 8645302803..4013ec1cab 100644 --- a/talpid-core/src/security/linux/dns/mod.rs +++ b/talpid-core/src/security/linux/dns/mod.rs @@ -74,6 +74,10 @@ impl DnsSettings { pub fn set_dns(&mut self, interface: &str, servers: Vec<IpAddr>) -> Result<()> { use self::DnsSettings::*; + self.reset()?; + // Resetting the DNS managemer in case the previously selected one isn't valid + *self = DnsSettings::new()?; + match self { Resolvconf(ref mut resolvconf) => resolvconf.set_dns(interface, servers)?, @@ -97,9 +101,6 @@ impl DnsSettings { NetworkManager(ref mut network_manager) => network_manager.reset()?, } - // Resetting the DNS managemer in case the previously selected one isn't valid - *self = DnsSettings::new()?; - Ok(()) } } diff --git a/talpid-core/src/security/linux/dns/network_manager.rs b/talpid-core/src/security/linux/dns/network_manager.rs index 62eb4d6cd0..775ac283b3 100644 --- a/talpid-core/src/security/linux/dns/network_manager.rs +++ b/talpid-core/src/security/linux/dns/network_manager.rs @@ -18,10 +18,10 @@ error_chain! { NoNetworkManager { description("NetworkManager not detected") } - NMTooOld { + NmTooOld { description("NetworkManager is too old") } - NMNotManagingDns{ + NmNotManagingDns{ description("NetworkManager is not managing DNS") } } @@ -68,7 +68,7 @@ impl NetworkManager { .dbus_connection .with_path(NM_BUS, NM_DNS_MANAGER_PATH, RPC_TIMEOUT_MS) .get(NM_DNS_MANAGER, RC_MANAGEMENT_MODE_KEY) - .chain_err(|| ErrorKind::NMTooOld); + .chain_err(|| ErrorKind::NmTooOld); match management_mode { Err(e) => { @@ -77,16 +77,16 @@ impl NetworkManager { } Ok(management_mode) => { if management_mode == "unmanaged" { - return Err(Error::from(ErrorKind::NMNotManagingDns)); + return Err(Error::from(ErrorKind::NmNotManagingDns)); } } } let expected_resolv_conf = "/var/run/NetworkManager/resolv.conf"; let actual_resolv_conf = "/etc/resolv.conf"; - if !compare_files(&expected_resolv_conf, &actual_resolv_conf) { + if !eq_file_content(&expected_resolv_conf, &actual_resolv_conf) { debug!("/etc/resolv.conf differs from reference resolv.conf, therefore NM is not manaing DNS"); - return Err(Error::from(ErrorKind::NMNotManagingDns)); + bail!(ErrorKind::NmNotManagingDns); } Ok(()) @@ -155,15 +155,15 @@ fn as_variant<T: RefArg + 'static>(t: T) -> Variant<Box<RefArg>> { Variant(Box::new(t) as Box<RefArg>) } -fn compare_files<P: AsRef<Path>>(a: &P, b: &P) -> bool { - let file_a = match File::open(&a).map(BufReader::new) { +fn eq_file_content<P: AsRef<Path>>(a: &P, b: &P) -> bool { + let file_a = match File::open(a).map(BufReader::new) { Ok(file) => file, Err(e) => { debug!("Failed top open file {}: {}", a.as_ref().display(), e); return false; } }; - let file_b = match File::open(&b).map(BufReader::new) { + let file_b = match File::open(b).map(BufReader::new) { Ok(file) => file, Err(e) => { debug!("Failed top open file {}: {}", b.as_ref().display(), e); |
