From: Remi Gacogne Date: Thu, 10 Apr 2025 13:49:51 +0000 (+0200) Subject: dnsdist: Fix cache lookup for unavailable TCP-only backends X-Git-Tag: dnsdist-2.0.0-alpha2~82^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5f6f1444efdf400ff66f5572f676d3fabf998b68;p=thirdparty%2Fpdns.git dnsdist: Fix cache lookup for unavailable TCP-only backends --- diff --git a/pdns/dnsdistdist/dnsdist-backend.cc b/pdns/dnsdistdist/dnsdist-backend.cc index 33bcc7b6f5..2f3cccb915 100644 --- a/pdns/dnsdistdist/dnsdist-backend.cc +++ b/pdns/dnsdistdist/dnsdist-backend.cc @@ -1052,6 +1052,13 @@ void ServerPool::addServer(shared_ptr& server) serv.first = idx++; } *servers = std::make_shared(std::move(newServers)); + + if ((*servers)->size() == 1) { + d_tcpOnly = server->isTCPOnly(); + } + else if (d_tcpOnly && !server->isTCPOnly()) { + d_tcpOnly = false; + } } void ServerPool::removeServer(shared_ptr& server) @@ -1062,6 +1069,7 @@ void ServerPool::removeServer(shared_ptr& server) auto newServers = std::make_shared(*(*servers)); size_t idx = 1; bool found = false; + bool tcpOnly = true; for (auto it = newServers->begin(); it != newServers->end();) { if (found) { /* we need to renumber the servers placed @@ -1076,7 +1084,9 @@ void ServerPool::removeServer(shared_ptr& server) idx++; it++; } + tcpOnly = tcpOnly && it->second->isTCPOnly(); } + d_tcpOnly = tcpOnly; *servers = std::move(newServers); } diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 3ca83043d2..bd2e71eeab 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -1421,6 +1421,9 @@ ProcessQueryResult processQueryAfterRules(DNSQuestion& dnsQuestion, std::shared_ if (selectedBackend && selectedBackend->isTCPOnly()) { willBeForwardedOverUDP = false; } + else if (!selectedBackend) { + willBeForwardedOverUDP = !serverPool->isTCPOnly(); + } uint32_t allowExpired = selectedBackend ? 0 : dnsdist::configuration::getCurrentRuntimeConfiguration().d_staleCacheEntriesTTL; diff --git a/pdns/dnsdistdist/dnsdist.hh b/pdns/dnsdistdist/dnsdist.hh index 0cf39e4481..8c3e35b544 100644 --- a/pdns/dnsdistdist/dnsdist.hh +++ b/pdns/dnsdistdist/dnsdist.hh @@ -927,10 +927,15 @@ struct ServerPool const std::shared_ptr getServers(); void addServer(shared_ptr& server); void removeServer(shared_ptr& server); + bool isTCPOnly() const + { + return d_tcpOnly; + } private: SharedLockGuarded> d_servers; bool d_useECS{false}; + bool d_tcpOnly{false}; }; enum ednsHeaderFlags