diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2023-04-21 13:47:45 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2023-04-21 13:47:45 +0200 |
| commit | 7ef94355f9069ca4ccd6f60e45d11b0ba0da5a98 (patch) | |
| tree | dfe495f906211dd19b436b2f36b620cb6e59efcb | |
| parent | 6e394574d948b61691ddf716ffb38dd9df716e3f (diff) | |
| parent | 3a29e794787d95120622a4cacd8442ddf47d151d (diff) | |
| download | mullvadvpn-7ef94355f9069ca4ccd6f60e45d11b0ba0da5a98.tar.xz mullvadvpn-7ef94355f9069ca4ccd6f60e45d11b0ba0da5a98.zip | |
Merge branch 'clippy-fix-windows-2'
| -rw-r--r-- | mullvad-daemon/src/migrations/v6.rs | 1 | ||||
| -rw-r--r-- | mullvad-paths/src/windows.rs | 4 | ||||
| -rw-r--r-- | talpid-core/src/dns/windows/auto.rs | 12 | ||||
| -rw-r--r-- | talpid-core/src/dns/windows/iphlpapi.rs | 12 | ||||
| -rw-r--r-- | talpid-core/src/dns/windows/netsh.rs | 12 | ||||
| -rw-r--r-- | talpid-core/src/dns/windows/tcpip.rs | 18 | ||||
| -rw-r--r-- | talpid-core/src/firewall/windows.rs | 3 | ||||
| -rw-r--r-- | talpid-core/src/split_tunnel/windows/path_monitor.rs | 10 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/connecting_state.rs | 5 | ||||
| -rw-r--r-- | talpid-openvpn/src/wintun.rs | 2 | ||||
| -rw-r--r-- | talpid-routing/src/windows/route_manager.rs | 15 | ||||
| -rw-r--r-- | talpid-tunnel/src/tun_provider/stub.rs | 6 | ||||
| -rw-r--r-- | talpid-windows-net/src/net.rs | 9 | ||||
| -rw-r--r-- | talpid-wireguard/src/wireguard_nt.rs | 45 |
14 files changed, 73 insertions, 81 deletions
diff --git a/mullvad-daemon/src/migrations/v6.rs b/mullvad-daemon/src/migrations/v6.rs index b5ba7fdf5b..66e6f90343 100644 --- a/mullvad-daemon/src/migrations/v6.rs +++ b/mullvad-daemon/src/migrations/v6.rs @@ -91,7 +91,6 @@ fn version_matches(settings: &mut serde_json::Value) -> bool { #[cfg(test)] mod test { use super::{migrate, migrate_pq_setting, version_matches}; - use serde_json; pub const V6_SETTINGS: &str = r#" { diff --git a/mullvad-paths/src/windows.rs b/mullvad-paths/src/windows.rs index 8237a983b9..900f4b67e6 100644 --- a/mullvad-paths/src/windows.rs +++ b/mullvad-paths/src/windows.rs @@ -153,7 +153,7 @@ fn adjust_token_privilege( return Err(std::io::Error::last_os_error()); } - let mut privileges = TOKEN_PRIVILEGES { + let privileges = TOKEN_PRIVILEGES { PrivilegeCount: 1, Privileges: [LUID_AND_ATTRIBUTES { Luid: privilege_luid, @@ -164,7 +164,7 @@ fn adjust_token_privilege( AdjustTokenPrivileges( token_handle, 0, - &mut privileges, + &privileges, 0, ptr::null_mut(), ptr::null_mut(), diff --git a/talpid-core/src/dns/windows/auto.rs b/talpid-core/src/dns/windows/auto.rs index a09804b700..d4cd5d838e 100644 --- a/talpid-core/src/dns/windows/auto.rs +++ b/talpid-core/src/dns/windows/auto.rs @@ -44,13 +44,11 @@ impl DnsMonitorT for DnsMonitor { type Error = super::Error; fn new() -> Result<Self, Self::Error> { - let current_monitor; - - if iphlpapi::DnsMonitor::is_supported() { - current_monitor = InnerMonitor::Iphlpapi(iphlpapi::DnsMonitor::new()?); + let current_monitor = if iphlpapi::DnsMonitor::is_supported() { + InnerMonitor::Iphlpapi(iphlpapi::DnsMonitor::new()?) } else { - current_monitor = InnerMonitor::Netsh(netsh::DnsMonitor::new()?); - } + InnerMonitor::Netsh(netsh::DnsMonitor::new()?) + }; Ok(Self { current_monitor }) } @@ -86,7 +84,7 @@ impl DnsMonitor { Err(super::Error::Iphlpapi(iphlpapi::Error::SetInterfaceDnsSettings(error))) => { *error == RPC_S_SERVER_UNAVAILABLE } - Err(super::Error::Netsh(netsh::Error::NetshError(Some(1)))) => true, + Err(super::Error::Netsh(netsh::Error::Netsh(Some(1)))) => true, _ => false, }; if is_dnscache_error { diff --git a/talpid-core/src/dns/windows/iphlpapi.rs b/talpid-core/src/dns/windows/iphlpapi.rs index 98f5034060..8cd8859224 100644 --- a/talpid-core/src/dns/windows/iphlpapi.rs +++ b/talpid-core/src/dns/windows/iphlpapi.rs @@ -29,11 +29,11 @@ use windows_sys::{ pub enum Error { /// Failure to obtain an interface LUID given an alias. #[error(display = "Failed to obtain LUID for the interface alias")] - InterfaceLuidError(#[error(source)] io::Error), + ObtainInterfaceLuid(#[error(source)] io::Error), /// Failure to obtain an interface GUID. #[error(display = "Failed to obtain GUID for the interface")] - InterfaceGuidError(#[error(source)] io::Error), + ObtainInterfaceGuid(#[error(source)] io::Error), /// Failed to set DNS settings on interface. #[error(display = "Failed to set DNS settings on interface: {}", _0)] @@ -41,7 +41,7 @@ pub enum Error { /// Failure to flush DNS cache. #[error(display = "Failed to flush DNS resolver cache")] - FlushResolverCacheError(#[error(source)] super::dnsapi::Error), + FlushResolverCache(#[error(source)] super::dnsapi::Error), /// Failed to load iphlpapi.dll. #[error(display = "Failed to load iphlpapi.dll")] @@ -117,8 +117,8 @@ impl DnsMonitorT for DnsMonitor { } fn set(&mut self, interface: &str, servers: &[IpAddr]) -> Result<(), Error> { - let guid = guid_from_luid(&luid_from_alias(interface).map_err(Error::InterfaceLuidError)?) - .map_err(Error::InterfaceGuidError)?; + let guid = guid_from_luid(&luid_from_alias(interface).map_err(Error::ObtainInterfaceLuid)?) + .map_err(Error::ObtainInterfaceGuid)?; let mut v4_servers = vec![]; let mut v6_servers = vec![]; @@ -208,5 +208,5 @@ fn set_interface_dns_servers<T: ToString>( } fn flush_dns_cache() -> Result<(), Error> { - super::dnsapi::flush_resolver_cache().map_err(Error::FlushResolverCacheError) + super::dnsapi::flush_resolver_cache().map_err(Error::FlushResolverCache) } diff --git a/talpid-core/src/dns/windows/netsh.rs b/talpid-core/src/dns/windows/netsh.rs index 7c0450f855..406b3710c4 100644 --- a/talpid-core/src/dns/windows/netsh.rs +++ b/talpid-core/src/dns/windows/netsh.rs @@ -26,11 +26,11 @@ const NETSH_TIMEOUT: Duration = Duration::from_secs(10); pub enum Error { /// Failure to obtain an interface LUID given an alias. #[error(display = "Failed to obtain LUID for the interface alias")] - InterfaceLuidError(#[error(source)] io::Error), + ObtainInterfaceLuid(#[error(source)] io::Error), /// Failure to obtain an interface index. #[error(display = "Failed to obtain index of the interface")] - InterfaceIndexError(#[error(source)] io::Error), + ObtainInterfaceIndex(#[error(source)] io::Error), /// Failure to spawn netsh subprocess. #[error(display = "Failed to spawn 'netsh'")] @@ -50,7 +50,7 @@ pub enum Error { /// netsh returned a non-zero status. #[error(display = "'netsh' returned an error: {:?}", _0)] - NetshError(Option<i32>), + Netsh(Option<i32>), /// netsh did not return in a timely manner. #[error(display = "'netsh' took too long to complete")] @@ -71,9 +71,9 @@ impl DnsMonitorT for DnsMonitor { } fn set(&mut self, interface: &str, servers: &[IpAddr]) -> Result<(), Error> { - let interface_luid = luid_from_alias(interface).map_err(Error::InterfaceLuidError)?; + let interface_luid = luid_from_alias(interface).map_err(Error::ObtainInterfaceLuid)?; let interface_index = - index_from_luid(&interface_luid).map_err(Error::InterfaceIndexError)?; + index_from_luid(&interface_luid).map_err(Error::ObtainInterfaceIndex)?; self.current_index = Some(interface_index); @@ -154,7 +154,7 @@ fn run_netsh_with_timeout(netsh_input: String, timeout: Duration) -> Result<(), match wait_for_child(&mut subproc, timeout) { Ok(Some(status)) => { if !status.success() { - return Err(Error::NetshError(status.code())); + return Err(Error::Netsh(status.code())); } Ok(()) } diff --git a/talpid-core/src/dns/windows/tcpip.rs b/talpid-core/src/dns/windows/tcpip.rs index 2fdb7e3c28..c1d577f5fe 100644 --- a/talpid-core/src/dns/windows/tcpip.rs +++ b/talpid-core/src/dns/windows/tcpip.rs @@ -15,19 +15,19 @@ use winreg::{ pub enum Error { /// Failure to obtain an interface LUID given an alias. #[error(display = "Failed to obtain LUID for the interface alias")] - InterfaceLuidError(#[error(source)] io::Error), + ObtainInterfaceLuid(#[error(source)] io::Error), /// Failure to obtain an interface GUID. #[error(display = "Failed to obtain GUID for the interface")] - InterfaceGuidError(#[error(source)] io::Error), + ObtainInterfaceGuid(#[error(source)] io::Error), /// Failure to flush DNS cache. #[error(display = "Failed to flush DNS resolver cache")] - FlushResolverCacheError(#[error(source)] super::dnsapi::Error), + FlushResolverCache(#[error(source)] super::dnsapi::Error), /// Failed to update DNS servers for interface. #[error(display = "Failed to update interface DNS servers")] - SetResolversError(#[error(source)] io::Error), + SetResolvers(#[error(source)] io::Error), } pub struct DnsMonitor { @@ -46,8 +46,8 @@ impl DnsMonitorT for DnsMonitor { } fn set(&mut self, interface: &str, servers: &[IpAddr]) -> Result<(), Error> { - let guid = guid_from_luid(&luid_from_alias(interface).map_err(Error::InterfaceLuidError)?) - .map_err(Error::InterfaceGuidError)?; + let guid = guid_from_luid(&luid_from_alias(interface).map_err(Error::ObtainInterfaceLuid)?) + .map_err(Error::ObtainInterfaceGuid)?; set_dns(&guid, servers)?; self.current_guid = Some(guid); if self.should_flush { @@ -75,12 +75,12 @@ impl DnsMonitor { } fn set_dns(interface: &GUID, servers: &[IpAddr]) -> Result<(), Error> { - let transaction = Transaction::new().map_err(Error::SetResolversError)?; + let transaction = Transaction::new().map_err(Error::SetResolvers)?; let result = match set_dns_inner(&transaction, interface, servers) { Ok(()) => transaction.commit(), Err(error) => transaction.rollback().and(Err(error)), }; - result.map_err(Error::SetResolversError) + result.map_err(Error::SetResolvers) } fn set_dns_inner( @@ -157,7 +157,7 @@ fn config_interface<'a>( } fn flush_dns_cache() -> Result<(), Error> { - super::dnsapi::flush_resolver_cache().map_err(Error::FlushResolverCacheError) + super::dnsapi::flush_resolver_cache().map_err(Error::FlushResolverCache) } /// Obtain a string representation for a GUID object. diff --git a/talpid-core/src/firewall/windows.rs b/talpid-core/src/firewall/windows.rs index 6f727f543b..6ec3fcc102 100644 --- a/talpid-core/src/firewall/windows.rs +++ b/talpid-core/src/firewall/windows.rs @@ -338,7 +338,6 @@ pub extern "system" fn log_sink( if msg.is_null() { log::error!("Log message from FFI boundary is NULL"); } else { - let rust_log_level = log::Level::from(level); let target = if context.is_null() { "UNKNOWN".into() } else { @@ -355,7 +354,7 @@ pub extern "system" fn log_sink( log::logger().log( &log::Record::builder() - .level(rust_log_level) + .level(level) .target(&target) .args(format_args!("{}", managed_msg)) .build(), diff --git a/talpid-core/src/split_tunnel/windows/path_monitor.rs b/talpid-core/src/split_tunnel/windows/path_monitor.rs index c40fec6dea..db673f16e9 100644 --- a/talpid-core/src/split_tunnel/windows/path_monitor.rs +++ b/talpid-core/src/split_tunnel/windows/path_monitor.rs @@ -667,11 +667,11 @@ impl PathMonitor { /// Find the index of the `DirContext` that owns the `OVERLAPPED` object, or None. fn find_context(&self, overlapped: *const OVERLAPPED) -> Option<usize> { - if overlapped == ptr::null_mut() { + if overlapped.is_null() { return None; } - for i in 0..self.dir_contexts.len() { - if ((&*self.dir_contexts[i].overlapped) as *const _) == overlapped { + for (i, dir_context) in self.dir_contexts.iter().enumerate() { + if (&*dir_context.overlapped as *const _) == overlapped { return Some(i); } } @@ -680,7 +680,7 @@ impl PathMonitor { /// Remove the element in `discarded_contexts` that owns the `OVERLAPPED` object, if it exists. fn free_discarded_context(&mut self, overlapped: *const OVERLAPPED) -> bool { - if overlapped == ptr::null_mut() { + if overlapped.is_null() { return false; } let mut was_discarded = false; @@ -773,7 +773,7 @@ impl PathMonitor { Err((error, result)) => { if error.raw_os_error() != Some(ERROR_OPERATION_ABORTED as i32) { log::error!("GetQueuedCompletionStatus failed: {:?}", error); - if result.used_overlapped == ptr::null_mut() { + if result.used_overlapped.is_null() { continue; } } diff --git a/talpid-core/src/tunnel_state_machine/connecting_state.rs b/talpid-core/src/tunnel_state_machine/connecting_state.rs index 821e076db6..8f1dafe2bf 100644 --- a/talpid-core/src/tunnel_state_machine/connecting_state.rs +++ b/talpid-core/src/tunnel_state_machine/connecting_state.rs @@ -528,10 +528,7 @@ fn should_retry(error: &tunnel::Error, retry_attempt: u32) -> bool { #[cfg(windows)] fn is_recoverable_routing_error(error: &talpid_routing::Error) -> bool { - match error { - talpid_routing::Error::AddRoutesFailed(_) => true, - _ => false, - } + matches!(error, talpid_routing::Error::AddRoutesFailed(_)) } impl TunnelState for ConnectingState { diff --git a/talpid-openvpn/src/wintun.rs b/talpid-openvpn/src/wintun.rs index 06fb443928..8b21ce9fd7 100644 --- a/talpid-openvpn/src/wintun.rs +++ b/talpid-openvpn/src/wintun.rs @@ -260,7 +260,7 @@ impl WintunDll { None => ptr::null_mut(), }; let handle = unsafe { (self.func_create)(name.as_ptr(), tunnel_type.as_ptr(), guid_ptr) }; - if handle == ptr::null_mut() { + if handle.is_null() { return Err(io::Error::last_os_error()); } Ok(handle) diff --git a/talpid-routing/src/windows/route_manager.rs b/talpid-routing/src/windows/route_manager.rs index 4a3713f7e3..14fbbf3f52 100644 --- a/talpid-routing/src/windows/route_manager.rs +++ b/talpid-routing/src/windows/route_manager.rs @@ -173,7 +173,7 @@ impl RouteManagerInternal { }); let existing_record_idx = - Self::find_route_record(&mut route_manager_routes, &new_record.registered_route); + Self::find_route_record(&route_manager_routes, &new_record.registered_route); match existing_record_idx { None => route_manager_routes.push(new_record), @@ -311,13 +311,13 @@ impl RouteManagerInternal { } } - fn find_route_record(records: &mut Vec<RouteRecord>, route: &RegisteredRoute) -> Option<usize> { + fn find_route_record(records: &[RouteRecord], route: &RegisteredRoute) -> Option<usize> { records .iter() .position(|record| route == &record.registered_route) } - fn undo_events(event_log: &Vec<EventEntry>, records: &mut Vec<RouteRecord>) -> Result<()> { + fn undo_events(event_log: &[EventEntry], records: &mut Vec<RouteRecord>) -> Result<()> { // Rewind state by processing events in the reverse order. // @@ -446,7 +446,7 @@ impl RouteManagerInternal { // for record in (*routes).iter() { - if let Err(_) = Self::delete_from_routing_table(&record.registered_route) { + if Self::delete_from_routing_table(&record.registered_route).is_err() { log::error!( "Failed to delete route while clearing applied routes, {}", record.registered_route @@ -481,8 +481,7 @@ impl RouteManagerInternal { { let (_, callbacks) = &mut *callbacks.lock().unwrap(); for callback in callbacks.values() { - let family = - AddressFamily::try_from_af_family(u16::try_from(family).unwrap()).unwrap(); + let family = AddressFamily::try_from_af_family(family).unwrap(); callback(event_type, family); } } @@ -714,8 +713,8 @@ impl Adapters { /// Create a new linked list of adapters from the windows API fn new(family: ADDRESS_FAMILY, flags: GET_ADAPTERS_ADDRESSES_FLAGS) -> Result<Self> { const MSDN_RECOMMENDED_STARTING_BUFFER_SIZE: usize = 1024 * 15; - let mut buffer: Vec<u8> = Vec::with_capacity(MSDN_RECOMMENDED_STARTING_BUFFER_SIZE); - buffer.resize(MSDN_RECOMMENDED_STARTING_BUFFER_SIZE, 0); + + let mut buffer: Vec<u8> = vec![0; MSDN_RECOMMENDED_STARTING_BUFFER_SIZE]; let mut buffer_size = u32::try_from(buffer.len()).unwrap(); let mut buffer_pointer = buffer.as_mut_ptr(); diff --git a/talpid-tunnel/src/tun_provider/stub.rs b/talpid-tunnel/src/tun_provider/stub.rs index ff659210cf..4227c2f8fb 100644 --- a/talpid-tunnel/src/tun_provider/stub.rs +++ b/talpid-tunnel/src/tun_provider/stub.rs @@ -15,3 +15,9 @@ impl StubTunProvider { unimplemented!(); } } + +impl Default for StubTunProvider { + fn default() -> Self { + Self::new() + } +} diff --git a/talpid-windows-net/src/net.rs b/talpid-windows-net/src/net.rs index 2cf5c7af7f..984b792e42 100644 --- a/talpid-windows-net/src/net.rs +++ b/talpid-windows-net/src/net.rs @@ -129,9 +129,8 @@ impl AddressFamily { /// Convert an [`AddressFamily`] to one of the `AF_*` constants. pub fn to_af_family(&self) -> u16 { match self { - // These values are both small enough to fit in a u16 - Self::Ipv4 => u16::try_from(AF_INET).unwrap(), - Self::Ipv6 => u16::try_from(AF_INET6).unwrap(), + Self::Ipv4 => AF_INET, + Self::Ipv6 => AF_INET6, } } } @@ -230,8 +229,8 @@ fn ip_interface_entry_exists(family: AddressFamily, luid: &NET_LUID_LH) -> io::R pub async fn wait_for_interfaces(luid: NET_LUID_LH, ipv4: bool, ipv6: bool) -> io::Result<()> { let (tx, rx) = futures::channel::oneshot::channel(); - let mut found_ipv4 = if ipv4 { false } else { true }; - let mut found_ipv6 = if ipv6 { false } else { true }; + let mut found_ipv4 = !ipv4; + let mut found_ipv6 = !ipv6; let mut tx = Some(tx); diff --git a/talpid-wireguard/src/wireguard_nt.rs b/talpid-wireguard/src/wireguard_nt.rs index bdb51c74a7..4ae7901a02 100644 --- a/talpid-wireguard/src/wireguard_nt.rs +++ b/talpid-wireguard/src/wireguard_nt.rs @@ -113,35 +113,35 @@ pub type Result<T> = std::result::Result<T, Error>; pub enum Error { /// Failed to load WireGuardNT #[error(display = "Failed to load mullvad-wireguard.dll")] - DllError(#[error(source)] io::Error), + LoadDll(#[error(source)] io::Error), /// Failed to create tunnel interface #[error(display = "Failed to create WireGuard device")] - CreateTunnelDeviceError(#[error(source)] io::Error), + CreateTunnelDevice(#[error(source)] io::Error), /// Failed to obtain tunnel interface alias #[error(display = "Failed to obtain interface name")] - ObtainAliasError(#[error(source)] io::Error), + ObtainAlias(#[error(source)] io::Error), /// Failed to get WireGuard tunnel config for device #[error(display = "Failed to get tunnel WireGuard config")] - GetWireGuardConfigError(#[error(source)] io::Error), + GetWireGuardConfig(#[error(source)] io::Error), /// Failed to set WireGuard tunnel config on device #[error(display = "Failed to set tunnel WireGuard config")] - SetWireGuardConfigError(#[error(source)] io::Error), + SetWireGuardConfig(#[error(source)] io::Error), /// Error listening to tunnel IP interfaces #[error(display = "Failed to wait on tunnel IP interfaces")] - IpInterfacesError(#[error(source)] io::Error), + IpInterfaces(#[error(source)] io::Error), /// Failed to set MTU and metric on tunnel device #[error(display = "Failed to set tunnel interface MTU")] - SetTunnelMtuError(#[error(source)] io::Error), + SetTunnelMtu(#[error(source)] io::Error), /// Failed to set the tunnel state to up #[error(display = "Failed to enable the tunnel adapter")] - EnableTunnelError(#[error(source)] io::Error), + EnableTunnel(#[error(source)] io::Error), /// Unknown address family #[error(display = "Unknown address family: {}", _0)] @@ -149,7 +149,7 @@ pub enum Error { /// Failure to set up logging #[error(display = "Failed to set up logging")] - InitLoggingError(#[error(source)] logging::Error), + InitLogging(#[error(source)] logging::Error), /// Invalid allowed IP #[error(display = "Invalid CIDR prefix")] @@ -419,9 +419,7 @@ impl WgNtTunnel { ); match error { - Error::CreateTunnelDeviceError(_) => { - super::TunnelError::RecoverableStartWireguardError - } + Error::CreateTunnelDevice(_) => super::TunnelError::RecoverableStartWireguardError, _ => super::TunnelError::FatalStartWireguardError, } }) @@ -436,12 +434,9 @@ impl WgNtTunnel { let dll = load_wg_nt_dll(resource_dir)?; let logger_handle = LoggerHandle::new(dll.clone(), log_path)?; let device = WgNtAdapter::create(dll, &ADAPTER_ALIAS, &ADAPTER_TYPE, Some(ADAPTER_GUID)) - .map_err(Error::CreateTunnelDeviceError)?; + .map_err(Error::CreateTunnelDevice)?; - let interface_name = device - .name() - .map_err(Error::ObtainAliasError)? - .to_string_lossy(); + let interface_name = device.name().map_err(Error::ObtainAlias)?.to_string_lossy(); if let Err(error) = device.set_logging(WireGuardAdapterLogState::On) { log::error!( @@ -490,16 +485,16 @@ async fn setup_ip_listener( log::debug!("Waiting for tunnel IP interfaces to arrive"); net::wait_for_interfaces(luid, true, has_ipv6) .await - .map_err(Error::IpInterfacesError)?; + .map_err(Error::IpInterfaces)?; log::debug!("Waiting for tunnel IP interfaces: Done"); talpid_tunnel::network_interface::initialize_interfaces(luid, Some(mtu)) - .map_err(Error::SetTunnelMtuError)?; + .map_err(Error::SetTunnelMtu)?; if let Some(device) = &*device.lock().unwrap() { device .set_state(WgAdapterState::Up) - .map_err(Error::EnableTunnelError) + .map_err(Error::EnableTunnel) } else { Ok(()) } @@ -522,7 +517,7 @@ struct LoggerHandle { impl LoggerHandle { fn new(dll: Arc<WgNtDll>, log_path: Option<&Path>) -> Result<Self> { - let context = logging::initialize_logging(log_path).map_err(Error::InitLoggingError)?; + let context = logging::initialize_logging(log_path).map_err(Error::InitLogging)?; { *(LOG_CONTEXT.lock().unwrap()) = Some(context); } @@ -598,7 +593,7 @@ impl WgNtAdapter { unsafe { self.dll_handle .set_config(self.handle, config_buffer.as_ptr(), config_buffer.len()) - .map_err(Error::SetWireGuardConfigError) + .map_err(Error::SetWireGuardConfig) } } @@ -608,7 +603,7 @@ impl WgNtAdapter { &self .dll_handle .get_config(self.handle) - .map_err(Error::GetWireGuardConfigError)?, + .map_err(Error::GetWireGuardConfig)?, ) } } @@ -735,7 +730,7 @@ impl WgNtDll { None => ptr::null_mut(), }; let handle = unsafe { (self.func_create)(name.as_ptr(), tunnel_type.as_ptr(), guid_ptr) }; - if handle == ptr::null_mut() { + if handle.is_null() { return Err(io::Error::last_os_error()); } Ok(handle) @@ -822,7 +817,7 @@ fn load_wg_nt_dll(resource_dir: &Path) -> Result<Arc<WgNtDll>> { match &*dll { Some(dll) => Ok(dll.clone()), None => { - let new_dll = Arc::new(WgNtDll::new(resource_dir).map_err(Error::DllError)?); + let new_dll = Arc::new(WgNtDll::new(resource_dir).map_err(Error::LoadDll)?); *dll = Some(new_dll.clone()); Ok(new_dll) } |
