From 7fafb0d3d7914540b5dff580244cde093f7a2e15 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:29:17 +0200 Subject: [PATCH] multiple dns and search domains --- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/src/service/mod.rs | 26 +++++++++++++++++++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index b89406e9..77dbc1d5 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1300,7 +1300,7 @@ dependencies = [ [[package]] name = "defguard_wireguard_rs" version = "0.4.9" -source = "git+https://github.com/DefGuard/wireguard-rs.git?rev=v0.4.9#4326eb4f1eeffa0788760b87aa193c135d7d1f86" +source = "git+https://github.com/DefGuard/wireguard-rs.git?rev=v0.4.10#bcdb7a50a08378cea95b10c7434a3ca77d72be14" dependencies = [ "base64 0.22.1", "libc", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 3ac9cb50..c1e69f97 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -22,7 +22,7 @@ base64 = "0.22" clap = { version = "4.5", features = ["derive", "env"] } chrono = { version = "0.4", features = ["serde"] } dark-light = "1.1" -defguard_wireguard_rs = { git = "https://github.com/DefGuard/wireguard-rs.git", rev = "v0.4.9" } +defguard_wireguard_rs = { git = "https://github.com/DefGuard/wireguard-rs.git", rev = "v0.4.10" } dirs = "5.0" lazy_static = "1.5" local-ip-address = "0.6" diff --git a/src-tauri/src/service/mod.rs b/src-tauri/src/service/mod.rs index fd0dce45..98e05760 100644 --- a/src-tauri/src/service/mod.rs +++ b/src-tauri/src/service/mod.rs @@ -110,11 +110,23 @@ impl DesktopDaemonService for DaemonService { })?; } - let dns: Vec = request - .dns - .into_iter() - .filter_map(|s| s.parse().ok()) - .collect(); + // The wireguard dns config value can be a list of IP addresses and domain names, which will be + // used as DNS servers and search domains respectively. + let dns_string = request.dns.unwrap_or_default(); + let dns_entries = dns_string + .split(',') + .map(|s| s.trim()) + .collect::>(); + // We assume that every entry that can't be parsed as an IP address is a domain name. + let mut dns = Vec::new(); + let mut search_domains = Vec::new(); + for entry in dns_entries { + if let Ok(ip) = entry.parse::() { + dns.push(ip); + } else { + search_domains.push(entry); + } + } // configure interface debug!("Configuring new interface {ifname} with configuration: {config:?}"); @@ -122,7 +134,7 @@ impl DesktopDaemonService for DaemonService { #[cfg(not(windows))] let configure_interface_result = wgapi.configure_interface(&config); #[cfg(windows)] - let configure_interface_result = wgapi.configure_interface(&config, &dns); + let configure_interface_result = wgapi.configure_interface(&config, &dns, &search_domains); configure_interface_result.map_err(|err| { let msg = format!("Failed to configure WireGuard interface {ifname}: {err}"); @@ -144,7 +156,7 @@ impl DesktopDaemonService for DaemonService { // Configure DNS if !dns.is_empty() { debug!("Configuring DNS for interface {ifname} with config: {dns:?}"); - wgapi.configure_dns(&dns).map_err(|err| { + wgapi.configure_dns(&dns, &search_domains).map_err(|err| { let msg = format!("Failed to configure DNS for WireGuard interface {ifname}: {err}"); error!("{msg}");