diff options
| -rw-r--r-- | talpid-core/src/security/mod.rs | 3 | ||||
| -rw-r--r-- | talpid-core/src/security/windows/dns.rs | 18 | ||||
| -rw-r--r-- | talpid-core/src/security/windows/mod.rs | 19 |
3 files changed, 18 insertions, 22 deletions
diff --git a/talpid-core/src/security/mod.rs b/talpid-core/src/security/mod.rs index 82d331227a..4d3a26cd13 100644 --- a/talpid-core/src/security/mod.rs +++ b/talpid-core/src/security/mod.rs @@ -4,7 +4,8 @@ use ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network}; use lazy_static::lazy_static; use std::fmt; #[cfg(unix)] -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; +use std::net::{Ipv4Addr, Ipv6Addr}; +use std::net::IpAddr; use std::path::Path; use talpid_types::net::Endpoint; diff --git a/talpid-core/src/security/windows/dns.rs b/talpid-core/src/security/windows/dns.rs index f25dc076a6..36bf4eae4d 100644 --- a/talpid-core/src/security/windows/dns.rs +++ b/talpid-core/src/security/windows/dns.rs @@ -42,12 +42,14 @@ error_chain!{ } } -pub struct WinDns { +pub struct DnsMonitor { backup_writer: SystemStateWriter, } -impl WinDns { - pub fn new<P: AsRef<Path>>(cache_dir: P) -> Result<Self> { +impl super::super::DnsMonitorT for DnsMonitor { + type Error = Error; + + fn new(cache_dir: impl AsRef<Path>) -> Result<Self> { unsafe { WinDns_Initialize(Some(log_sink), ptr::null_mut()).into_result()? }; let backup_writer = SystemStateWriter::new( @@ -56,7 +58,7 @@ impl WinDns { .join(DNS_STATE_FILENAME) .into_boxed_path(), ); - let mut dns = WinDns { backup_writer }; + let mut dns = DnsMonitor { backup_writer }; if let Err(error) = dns .restore_system_backup() .chain_err(|| "Failed to restore DNS backup") @@ -66,7 +68,7 @@ impl WinDns { Ok(dns) } - pub fn set_dns(&mut self, servers: &[IpAddr]) -> Result<()> { + fn set(&mut self, _interface: &str, servers: &[IpAddr]) -> Result<()> { let ipv4 = servers .iter() .filter(|ip| ip.is_ipv4()) @@ -107,7 +109,7 @@ impl WinDns { } } - pub fn reset_dns(&mut self) -> Result<()> { + fn reset(&mut self) -> Result<()> { unsafe { WinDns_Reset().into_result()? }; if let Err(e) = self.backup_writer.remove_backup() { @@ -115,7 +117,9 @@ impl WinDns { } Ok(()) } +} +impl DnsMonitor { fn restore_dns_settings(&mut self, data: &[u8]) -> Result<()> { unsafe { WinDns_Recover(data.as_ptr(), data.len() as u32) }.into_result() } @@ -188,7 +192,7 @@ extern "system" fn log_sink( } } -impl Drop for WinDns { +impl Drop for DnsMonitor { fn drop(&mut self) { if unsafe { WinDns_Deinitialize().into_result().is_ok() } { trace!("Successfully deinitialized WinDns"); diff --git a/talpid-core/src/security/windows/mod.rs b/talpid-core/src/security/windows/mod.rs index 65590f6f19..b6b99f8351 100644 --- a/talpid-core/src/security/windows/mod.rs +++ b/talpid-core/src/security/windows/mod.rs @@ -6,7 +6,6 @@ use log::{debug, error, trace}; use talpid_types::net::Endpoint; use widestring::WideCString; -use self::dns::WinDns; use self::winfw::*; use super::{NetworkSecurityT, SecurityPolicy}; use winnet; @@ -15,6 +14,8 @@ use winnet; mod ffi; mod dns; +pub use self::dns::{DnsMonitor, Error as DnsError}; + mod system_state; error_chain! { @@ -54,24 +55,17 @@ error_chain! { description("Unable to set TAP adapter metric") } } - - links { - WinDns(dns::Error, dns::ErrorKind) #[doc = "WinDNS failure"]; - } } const WINFW_TIMEOUT_SECONDS: u32 = 2; /// The Windows implementation for the firewall and DNS. -pub struct NetworkSecurity { - dns: WinDns, -} +pub struct NetworkSecurity(()); impl NetworkSecurityT for NetworkSecurity { type Error = Error; - fn new(cache_dir: impl AsRef<Path>) -> Result<Self> { - let windns = WinDns::new(cache_dir)?; + fn new(_cache_dir: impl AsRef<Path>) -> Result<Self> { unsafe { WinFw_Initialize( WINFW_TIMEOUT_SECONDS, @@ -81,7 +75,7 @@ impl NetworkSecurityT for NetworkSecurity { .into_result()? }; trace!("Successfully initialized windows firewall module"); - Ok(NetworkSecurity { dns: windns }) + Ok(NetworkSecurity(())) } fn apply_policy(&mut self, policy: SecurityPolicy) -> Result<()> { @@ -109,7 +103,6 @@ impl NetworkSecurityT for NetworkSecurity { } fn reset_policy(&mut self) -> Result<()> { - self.dns.reset_dns()?; unsafe { WinFw_Reset().into_result() }?; Ok(()) } @@ -169,8 +162,6 @@ impl NetworkSecurity { protocol: WinFwProt::from(endpoint.protocol), }; - self.dns.set_dns(&vec![tunnel_metadata.gateway.into()])?; - let metrics_set = winnet::ensure_top_metric_for_interface(&tunnel_metadata.interface) .chain_err(|| ErrorKind::SetTapMetric)?; |
