diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index daef3420..3b7af78b 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -970,9 +970,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.51" +version = "4.5.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c26d721170e0295f191a69bd9a1f93efcdb0aff38684b61ab5750468972e5f5" +checksum = "aa8120877db0e5c011242f96806ce3c94e0737ab8108532a76a3300a01db2ab8" dependencies = [ "clap_builder", "clap_derive", @@ -980,9 +980,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.51" +version = "4.5.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75835f0c7bf681bfd05abe44e965760fea999a5286c6eb2d59883634fd02011a" +checksum = "02576b399397b659c26064fbc92a75fede9d18ffd5f80ca1cd74ddab167016e1" dependencies = [ "anstream", "anstyle", diff --git a/src-tauri/cli/src/bin/dg.rs b/src-tauri/cli/src/bin/dg.rs index f988257a..6e026c94 100644 --- a/src-tauri/cli/src/bin/dg.rs +++ b/src-tauri/cli/src/bin/dg.rs @@ -159,8 +159,7 @@ async fn connect(config: CliConfig, ifname: String, trigger: Arc) -> Res let mut wgapi = WGApi::::new(ifname.to_string()).expect("Failed to setup WireGuard API"); #[cfg(target_os = "macos")] - let mut wgapi = - WGApi::::new(ifname.to_string()).expect("Failed to setup WireGuard API"); + let mut wgapi = WGApi::::new(ifname.clone()).expect("Failed to setup WireGuard API"); // Create new interface. debug!("Creating new interface {ifname}"); @@ -617,7 +616,7 @@ async fn main() { let token = submatches .get_one::("token") .expect("No enrollment token was provided or it's invalid") - .to_string(); + .clone(); let url = submatches .get_one::("url") .expect("No enrollment URL was provided or it's invalid"); diff --git a/src-tauri/src/app_config.rs b/src-tauri/src/app_config.rs index 0fd9fb23..84a93d9f 100644 --- a/src-tauri/src/app_config.rs +++ b/src-tauri/src/app_config.rs @@ -137,6 +137,7 @@ impl AppConfig { /// Wraps MTU in an Option. We don't store Option directly in AppConfig to avoid struct-patch /// ambiguity when applying updates coming from the frontend. An incoming MTU value of 0 is /// interpreted as a request to fall back to the default. + #[must_use] pub fn get_mtu(&self) -> Option { match self.mtu { 0 => None, diff --git a/src-tauri/src/apple.rs b/src-tauri/src/apple.rs index 1a8cf498..27c375a4 100644 --- a/src-tauri/src/apple.rs +++ b/src-tauri/src/apple.rs @@ -15,8 +15,8 @@ use block2::RcBlock; use defguard_wireguard_rs::{host::Peer, key::Key, net::IpAddrMask}; use objc2::{rc::Retained, runtime::AnyObject}; use objc2_foundation::{ - ns_string, NSArray, NSDictionary, NSError, NSMutableArray, NSMutableDictionary, NSNull, - NSNumber, NSString, + ns_string, NSArray, NSDictionary, NSError, NSMutableArray, NSMutableDictionary, NSNumber, + NSString, }; use objc2_network_extension::{NETunnelProviderManager, NETunnelProviderProtocol}; use serde::Serialize; @@ -43,7 +43,7 @@ pub(crate) struct Stats { /// Find `NETunnelProviderManager` in system preferences. fn manager_for_name(name: &str) -> Option> { - let name_string = NSString::from_str(&name); + let name_string = NSString::from_str(name); let plugin_bundle_id = NSString::from_str(PLUGIN_BUNDLE_ID); let (tx, rx) = channel(); @@ -87,7 +87,7 @@ fn manager_for_name(name: &str) -> Option> { }, ); unsafe { - NETunnelProviderManager::loadAllFromPreferencesWithCompletionHandler(&*handler); + NETunnelProviderManager::loadAllFromPreferencesWithCompletionHandler(&handler); } rx.recv().unwrap() @@ -228,7 +228,7 @@ impl TunnelConfiguration { let dns_search = NSMutableArray::::new(); for entry in &self.dns_search { - dns_search.addObject(NSString::from_str(&entry).as_ref()); + dns_search.addObject(NSString::from_str(entry).as_ref()); } dict.insert(ns_string!("dnsSearch"), dns_search.as_ref()); @@ -244,7 +244,7 @@ impl TunnelConfiguration { let tunnel_protocol = NETunnelProviderProtocol::new(); let plugin_bundle_id = NSString::from_str(PLUGIN_BUNDLE_ID); tunnel_protocol.setProviderBundleIdentifier(Some(&plugin_bundle_id)); - let server_address = self.peers.get(0).map_or(String::new(), |peer| { + let server_address = self.peers.first().map_or(String::new(), |peer| { peer.endpoint.map_or(String::new(), |sa| sa.to_string()) }); let server_address = NSString::from_str(&server_address); @@ -319,6 +319,7 @@ impl Location { preshared_key: Option, dns: Vec, dns_search: Vec, + mtu: Option, ) -> Result where E: SqliteExecutor<'e>, @@ -400,7 +401,7 @@ impl Location { addresses, listen_port: Some(0), peers: vec![peer], - mtu: None, + mtu, dns, dns_search, }) @@ -413,6 +414,7 @@ impl Tunnel { executor: E, dns: Vec, dns_search: Vec, + mtu: Option, ) -> Result where E: SqliteExecutor<'e>, @@ -489,7 +491,7 @@ impl Tunnel { addresses, listen_port: Some(0), peers: vec![peer], - mtu: None, + mtu, dns, dns_search, }) diff --git a/src-tauri/src/database/models/location.rs b/src-tauri/src/database/models/location.rs index bfaa553d..ebd74f9f 100644 --- a/src-tauri/src/database/models/location.rs +++ b/src-tauri/src/database/models/location.rs @@ -262,6 +262,7 @@ impl Location { executor: E, interface_name: String, preshared_key: Option, + mtu: Option, ) -> Result where E: SqliteExecutor<'e>, @@ -341,7 +342,7 @@ impl Location { addresses, port: 0, peers: vec![peer], - mtu: None, + mtu, }; Ok(interface_config) diff --git a/src-tauri/src/enterprise/periodic/config.rs b/src-tauri/src/enterprise/periodic/config.rs index 894c3211..935953c9 100644 --- a/src-tauri/src/enterprise/periodic/config.rs +++ b/src-tauri/src/enterprise/periodic/config.rs @@ -269,7 +269,7 @@ fn build_request(instance: &Instance) -> Result let token = instance.token.as_ref().ok_or_else(|| Error::NoToken)?; Ok(InstanceInfoRequest { - token: (*token).to_string(), + token: (*token).clone(), }) } diff --git a/src-tauri/src/enterprise/provisioning/mod.rs b/src-tauri/src/enterprise/provisioning/mod.rs index a6ae327d..5e5cf31d 100644 --- a/src-tauri/src/enterprise/provisioning/mod.rs +++ b/src-tauri/src/enterprise/provisioning/mod.rs @@ -58,6 +58,7 @@ impl ProvisioningConfig { } } +#[must_use] pub fn try_get_provisioning_config(app_data_dir: &Path) -> Option { debug!("Trying to find provisioning config in {app_data_dir:?}"); diff --git a/src-tauri/src/enterprise/service_locations/mod.rs b/src-tauri/src/enterprise/service_locations/mod.rs index 3a2b1098..b8dffa4c 100644 --- a/src-tauri/src/enterprise/service_locations/mod.rs +++ b/src-tauri/src/enterprise/service_locations/mod.rs @@ -88,16 +88,14 @@ impl Location { if !self.is_service_location() { warn!("Location {self} is not a service location, so it can't be converted to one."); return Err(crate::error::Error::ConversionError(format!( - "Failed to convert location {} to a service location as it's either not marked as one or has MFA enabled.", - self + "Failed to convert location {self} to a service location as it's either not marked as one or has MFA enabled." ))); } let mode = match self.service_location_mode { ServiceLocationMode::Disabled => { warn!( - "Location {} has an invalid service location mode, so it can't be converted to one.", - self + "Location {self} has an invalid service location mode, so it can't be converted to one." ); return Err( crate::error::Error::ConversionError(format!("Location {} has an invalid service location mode ({:?}), so it can't be converted to one.", self, self.service_location_mode)) diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index 2f2ef9f1..800b586b 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -80,7 +80,7 @@ pub(crate) async fn setup_interface( debug!("Found free port: {port} for interface {interface_name}."); let mut interface_config = location - .interface_configuration(pool, interface_name.clone(), preshared_key) + .interface_configuration(pool, interface_name.clone(), preshared_key, mtu) .await?; interface_config.mtu = mtu; debug!("Creating interface for location {location} with configuration {interface_config:?}"); @@ -124,7 +124,7 @@ pub(crate) async fn setup_interface( location: &Location, name: &str, preshared_key: Option, - _mtu: Option, + mtu: Option, pool: &DbPool, ) -> Result { debug!("Setting up interface for location: {location}"); @@ -132,7 +132,7 @@ pub(crate) async fn setup_interface( let (dns, dns_search) = location.dns(); let tunnel_config = location - .tunnel_configurarion(pool, preshared_key, dns, dns_search) + .tunnel_configurarion(pool, preshared_key, dns, dns_search, mtu) .await?; tunnel_config.save(); @@ -156,7 +156,7 @@ pub(crate) async fn stats_handler( interval.tick().await; let all_stats = all_tunnel_stats(); - if all_stats.len() == 0 { + if all_stats.is_empty() { continue; } // Let `all_stats` be `Send`. @@ -565,7 +565,7 @@ pub async fn get_tunnel_interface_details( address: tunnel.address, dns: tunnel.dns, listen_port, - peer_pubkey: peer_pubkey.to_string(), + peer_pubkey: peer_pubkey.clone(), peer_endpoint: tunnel.endpoint, allowed_ips: tunnel.allowed_ips.unwrap_or_default(), persistent_keepalive_interval,