Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src-tauri/cli/src/bin/dg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ async fn connect(config: CliConfig, ifname: String, trigger: Arc<Notify>) -> Res
let mut wgapi =
WGApi::<Kernel>::new(ifname.to_string()).expect("Failed to setup WireGuard API");
#[cfg(target_os = "macos")]
let mut wgapi =
WGApi::<Userspace>::new(ifname.to_string()).expect("Failed to setup WireGuard API");
let mut wgapi = WGApi::<Userspace>::new(ifname.clone()).expect("Failed to setup WireGuard API");

// Create new interface.
debug!("Creating new interface {ifname}");
Expand Down Expand Up @@ -617,7 +616,7 @@ async fn main() {
let token = submatches
.get_one::<String>("token")
.expect("No enrollment token was provided or it's invalid")
.to_string();
.clone();
let url = submatches
.get_one::<Url>("url")
.expect("No enrollment URL was provided or it's invalid");
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
match self.mtu {
0 => None,
Expand Down
18 changes: 10 additions & 8 deletions src-tauri/src/apple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +43,7 @@ pub(crate) struct Stats {

/// Find `NETunnelProviderManager` in system preferences.
fn manager_for_name(name: &str) -> Option<Retained<NETunnelProviderManager>> {
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();

Expand Down Expand Up @@ -87,7 +87,7 @@ fn manager_for_name(name: &str) -> Option<Retained<NETunnelProviderManager>> {
},
);
unsafe {
NETunnelProviderManager::loadAllFromPreferencesWithCompletionHandler(&*handler);
NETunnelProviderManager::loadAllFromPreferencesWithCompletionHandler(&handler);
}

rx.recv().unwrap()
Expand Down Expand Up @@ -228,7 +228,7 @@ impl TunnelConfiguration {

let dns_search = NSMutableArray::<NSString>::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());

Expand All @@ -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);
Expand Down Expand Up @@ -319,6 +319,7 @@ impl Location<Id> {
preshared_key: Option<String>,
dns: Vec<IpAddr>,
dns_search: Vec<String>,
mtu: Option<u32>,
) -> Result<TunnelConfiguration, Error>
where
E: SqliteExecutor<'e>,
Expand Down Expand Up @@ -400,7 +401,7 @@ impl Location<Id> {
addresses,
listen_port: Some(0),
peers: vec![peer],
mtu: None,
mtu,
dns,
dns_search,
})
Expand All @@ -413,6 +414,7 @@ impl Tunnel<Id> {
executor: E,
dns: Vec<IpAddr>,
dns_search: Vec<String>,
mtu: Option<u32>,
) -> Result<TunnelConfiguration, Error>
where
E: SqliteExecutor<'e>,
Expand Down Expand Up @@ -489,7 +491,7 @@ impl Tunnel<Id> {
addresses,
listen_port: Some(0),
peers: vec![peer],
mtu: None,
mtu,
dns,
dns_search,
})
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/database/models/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ impl Location<Id> {
executor: E,
interface_name: String,
preshared_key: Option<String>,
mtu: Option<u32>,
) -> Result<InterfaceConfiguration, Error>
where
E: SqliteExecutor<'e>,
Expand Down Expand Up @@ -341,7 +342,7 @@ impl Location<Id> {
addresses,
port: 0,
peers: vec![peer],
mtu: None,
mtu,
};

Ok(interface_config)
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/enterprise/periodic/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ fn build_request(instance: &Instance<Id>) -> Result<InstanceInfoRequest, Error>
let token = instance.token.as_ref().ok_or_else(|| Error::NoToken)?;

Ok(InstanceInfoRequest {
token: (*token).to_string(),
token: (*token).clone(),
})
}

Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/enterprise/provisioning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl ProvisioningConfig {
}
}

#[must_use]
pub fn try_get_provisioning_config(app_data_dir: &Path) -> Option<ProvisioningConfig> {
debug!("Trying to find provisioning config in {app_data_dir:?}");

Expand Down
6 changes: 2 additions & 4 deletions src-tauri/src/enterprise/service_locations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,14 @@ impl Location<Id> {
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))
Expand Down
10 changes: 5 additions & 5 deletions src-tauri/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
Expand Down Expand Up @@ -124,15 +124,15 @@ pub(crate) async fn setup_interface(
location: &Location<Id>,
name: &str,
preshared_key: Option<String>,
_mtu: Option<u32>,
mtu: Option<u32>,
pool: &DbPool,
) -> Result<String, Error> {
debug!("Setting up interface for location: {location}");
let interface_name = get_interface_name(name);

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();
Expand All @@ -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`.
Expand Down Expand Up @@ -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,
Expand Down