From 8b003e6be2f920c86cbe98b582179775379c63d8 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 16 Apr 2024 05:41:55 -0700 Subject: [PATCH] add DNS configuration for TCP fallback. Signed-off-by: Jason Volk --- conduwuit-example.toml | 3 +++ src/config/mod.rs | 3 +++ src/service/globals/resolver.rs | 1 + 3 files changed, 7 insertions(+) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 2b92eac0..f077ebdf 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -491,6 +491,9 @@ allow_profile_lookup_federation_requests = true # Number of retries after a timeout. #dns_attempts = 5 +# Fallback to TCP on DNS errors. Set this to false if unsupported by nameserver. +#dns_tcp_fallback = true + # Enable to query all nameservers until the domain is found. Referred to as "trust_negative_responses" in hickory_resolver. # This can avoid useless DNS queries if the first nameserver responds with NXDOMAIN or an empty NOERROR response. # diff --git a/src/config/mod.rs b/src/config/mod.rs index df4a9335..8fe0823d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -98,6 +98,8 @@ pub struct Config { pub dns_attempts: u16, #[serde(default = "default_dns_timeout")] pub dns_timeout: u64, + #[serde(default = "true_fn")] + pub dns_tcp_fallback: bool, #[serde(default)] pub query_all_nameservers: bool, #[serde(default = "default_max_request_size")] @@ -494,6 +496,7 @@ impl fmt::Display for Config { ("DNS minimum nxdomain ttl", &self.dns_min_ttl_nxdomain.to_string()), ("DNS attempts", &self.dns_attempts.to_string()), ("DNS timeout", &self.dns_timeout.to_string()), + ("DNS fallback to TCP", &self.dns_tcp_fallback.to_string()), ("Query all nameservers", &self.query_all_nameservers.to_string()), ("Maximum request size (bytes)", &self.max_request_size.to_string()), ("Maximum concurrent requests", &self.max_concurrent_requests.to_string()), diff --git a/src/service/globals/resolver.rs b/src/service/globals/resolver.rs index 475edd52..d958309d 100644 --- a/src/service/globals/resolver.rs +++ b/src/service/globals/resolver.rs @@ -64,6 +64,7 @@ impl Resolver { opts.positive_max_ttl = Some(Duration::from_secs(60 * 60 * 24 * 7)); opts.timeout = Duration::from_secs(config.dns_timeout); opts.attempts = config.dns_attempts as usize; + opts.try_tcp_on_error = config.dns_tcp_fallback; opts.num_concurrent_reqs = 1; opts.shuffle_dns_servers = true; opts.rotate = true;