diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-09-18 19:34:42 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-09-18 19:34:42 +0200 |
commit | 9145b504b3179e723a66ede952f8983beebfddab (patch) | |
tree | 265d16b2e17a741efcfa98841de7314bdc0c7662 | |
parent | 3085cbd722547ad45cdd5f69d2a39e8aae04d785 (diff) |
introduce crate feature for localhost DNS resolution
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | src/main.rs | 24 |
3 files changed, 28 insertions, 6 deletions
@@ -15,3 +15,7 @@ linkaddrs = { version = "0.1.0", git = "https://github.com/HimbeerserverDE/linka serde = "1.0" serde_json = { version = "1.0", features = ["std"] } trust-dns-resolver = "0.23.0" + +[features] +default = ["localhost_dns"] +localhost_dns = [] @@ -15,6 +15,12 @@ dyndns [config] where config is the config path (defaults to /data/dyndns.conf). +# Crate features + +This crate provides the `localhost_dns` feature, which is enabled by default. +If enabled, `localhost_dns` causes `[::1]:53` to be used for resolution +of the API endpoint hostnames. Otherwise the system configuration is used. + # Configuration The configuration file is simply a JSON file. diff --git a/src/main.rs b/src/main.rs index db297d6..c7a9e50 100644 --- a/src/main.rs +++ b/src/main.rs @@ -405,8 +405,12 @@ fn push_addr4(config: ConfigIpv4, rx: &mpsc::Receiver<Ipv4Net>) -> Result<()> { #[cfg(debug_assertions)] let endpoint = Endpoint::Sandbox; - let addr = resolve_endpoint(&endpoint)?; - let clt = Client::login_addr(endpoint, addr, user, pass)?; + let clt = if cfg!(localhost_dns) { + let addr = resolve_endpoint(&endpoint)?; + Client::login_addr(endpoint, addr, user, pass) + } else { + Client::login(endpoint, user, pass) + }?; clt.call(RecordUpdate { ids: config.records.clone(), @@ -439,8 +443,12 @@ fn push_addr6(config: ConfigIpv6, rx: &mpsc::Receiver<Ipv6Net>) -> Result<()> { #[cfg(debug_assertions)] let endpoint = Endpoint::Sandbox; - let addr = resolve_endpoint(&endpoint)?; - let clt = Client::login_addr(endpoint, addr, user, pass)?; + let clt = if cfg!(localhost_dns) { + let addr = resolve_endpoint(&endpoint)?; + Client::login_addr(endpoint, addr, user, pass) + } else { + Client::login(endpoint, user, pass) + }?; clt.call(RecordUpdate { ids: config.records.clone(), @@ -473,8 +481,12 @@ fn push_net6(config: ConfigNet6, rx: &mpsc::Receiver<Ipv6Net>) -> Result<()> { #[cfg(debug_assertions)] let endpoint = Endpoint::Sandbox; - let addr = resolve_endpoint(&endpoint)?; - let clt = Client::login_addr(endpoint, addr, user, pass)?; + let clt = if cfg!(localhost_dns) { + let addr = resolve_endpoint(&endpoint)?; + Client::login_addr(endpoint, addr, user, pass) + } else { + Client::login(endpoint, user, pass) + }?; for id in &config.records { let info: RecordInfoResponse = clt.call(RecordInfoCall { |