Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple dns servers and search domains #306

Merged
merged 2 commits into from
Sep 18, 2024
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
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
Loading