Skip to content

Commit

Permalink
multiple dns and search domains
Browse files Browse the repository at this point in the history
  • Loading branch information
t-aleksander committed Sep 18, 2024
1 parent 30aa60f commit 7fafb0d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

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

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 19 additions & 7 deletions src-tauri/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,31 @@ impl DesktopDaemonService for DaemonService {
})?;
}

let dns: Vec<IpAddr> = 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::<Vec<&str>>();
// 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::<IpAddr>() {
dns.push(ip);
} else {
search_domains.push(entry);
}
}

// configure interface
debug!("Configuring new interface {ifname} with configuration: {config:?}");

#[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}");
Expand All @@ -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}");
Expand Down

0 comments on commit 7fafb0d

Please sign in to comment.