diff options
| author | Emīls <emils@mullvad.net> | 2020-11-17 13:41:52 +0000 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2020-11-19 11:53:23 +0000 |
| commit | 13325d6e976d2c5bdb9686fdcfb1d4814f439175 (patch) | |
| tree | e49e47d211a020ffef130321daca7f93da177260 | |
| parent | 2fd8b360822373be336dd8d896f921a752e458fb (diff) | |
| download | mullvadvpn-13325d6e976d2c5bdb9686fdcfb1d4814f439175.tar.xz mullvadvpn-13325d6e976d2c5bdb9686fdcfb1d4814f439175.zip | |
Refactor connectivity check disabling
| -rw-r--r-- | talpid-core/src/dns/linux/mod.rs | 7 | ||||
| -rw-r--r-- | talpid-core/src/dns/mod.rs | 9 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/mod.rs | 43 |
3 files changed, 10 insertions, 49 deletions
diff --git a/talpid-core/src/dns/linux/mod.rs b/talpid-core/src/dns/linux/mod.rs index 132627da06..48933269be 100644 --- a/talpid-core/src/dns/linux/mod.rs +++ b/talpid-core/src/dns/linux/mod.rs @@ -7,6 +7,7 @@ use self::{ network_manager::NetworkManager, resolvconf::Resolvconf, static_resolv_conf::StaticResolvConf, systemd_resolved::SystemdResolved, }; +use crate::linux::network_manager::NetworkManager as NMDBus; use std::{env, fmt, net::IpAddr, path::Path}; @@ -65,10 +66,10 @@ impl super::DnsMonitorT for DnsMonitor { Ok(()) } - fn dbus_connection(&self) -> Option<&dbus::ffidisp::Connection> { + fn dbus_connection(&self) -> Option<&NMDBus> { match &self.inner { - Some(DnsMonitorHolder::NetworkManager(nm)) => Some(&nm.dbus_connection), - Some(DnsMonitorHolder::SystemdResolved(sdr)) => Some(&sdr.dbus_connection), + Some(DnsMonitorHolder::NetworkManager(nm)) => Some(&nm.connection), + // Some(DnsMonitorHolder::SystemdResolved(sdr)) => Some(&sdr.dbus_connection), _ => None, } } diff --git a/talpid-core/src/dns/mod.rs b/talpid-core/src/dns/mod.rs index 7cea6f6c95..987f3f1092 100644 --- a/talpid-core/src/dns/mod.rs +++ b/talpid-core/src/dns/mod.rs @@ -53,12 +53,6 @@ impl DnsMonitor { log::info!("Resetting DNS"); self.inner.reset() } - - /// Expose an existing DBus connection if one already exists. - #[cfg(target_os = "linux")] - pub fn dbus_connection(&self) -> Option<&dbus::ffidisp::Connection> { - self.inner.dbus_connection() - } } trait DnsMonitorT: Sized { @@ -69,7 +63,4 @@ trait DnsMonitorT: Sized { fn set(&mut self, interface: &str, servers: &[IpAddr]) -> Result<(), Self::Error>; fn reset(&mut self) -> Result<(), Self::Error>; - - #[cfg(target_os = "linux")] - fn dbus_connection(&self) -> Option<&dbus::ffidisp::Connection>; } diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs index edffca927c..3e07bde0f4 100644 --- a/talpid-core/src/tunnel_state_machine/mod.rs +++ b/talpid-core/src/tunnel_state_machine/mod.rs @@ -19,8 +19,6 @@ use crate::{ routing::RouteManager, tunnel::{tun_provider::TunProvider, TunnelEvent}, }; -#[cfg(target_os = "linux")] -use dbus::ffidisp::{BusType, Connection}; use futures::{ channel::{mpsc, oneshot}, stream, StreamExt, @@ -343,24 +341,9 @@ impl SharedTunnelStateValues { return; }; - let own_connection; - let connection = if let Some(ready_connection) = self.dns_monitor.dbus_connection() { - ready_connection - } else { - match Connection::get_private(BusType::System) { - Ok(connection) => { - own_connection = connection; - &own_connection - } - Err(err) => { - log::error!("Failed to initialize DBus connection: {}", err); - return; - } - } - }; - - self.connectivity_check_was_enabled = - crate::linux::network_manager::nm_disable_connectivity_check(connection); + if let Ok(nm) = crate::linux::network_manager::NetworkManager::new() { + self.connectivity_check_was_enabled = nm.disable_connectivity_check(); + } } /// Reset NetworkManager's connectivity check if it was disabled. @@ -371,24 +354,10 @@ impl SharedTunnelStateValues { return; }; - let own_connection; - let connection = if let Some(ready_connection) = self.dns_monitor.dbus_connection() { - ready_connection - } else { - match Connection::get_private(BusType::System) { - Ok(connection) => { - own_connection = connection; - &own_connection - } - Err(err) => { - log::error!("Failed to initialize DBus connection: {}", err); - return; - } + if let Ok(nm) = crate::linux::network_manager::NetworkManager::new() { + if let Some(true) = self.connectivity_check_was_enabled.take() { + nm.enable_connectivity_check(); } - }; - - if let Some(true) = self.connectivity_check_was_enabled.take() { - crate::linux::network_manager::nm_enable_connectivity_check(connection); } } } |
