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-1.9.10~7^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d17c730ef15fc59d931f9a344ea582cc2e59165f;p=thirdparty%2Fpdns.git dnsdist: Fix cache lookup for unavailable TCP-only backends (cherry picked from commit 5f6f1444efdf400ff66f5572f676d3fabf998b68) --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index b7c19b4a62..cb08775faf 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1447,6 +1447,9 @@ ProcessQueryResult processQueryAfterRules(DNSQuestion& dq, LocalHolders& holders if (selectedBackend && selectedBackend->isTCPOnly()) { willBeForwardedOverUDP = false; } + else if (!selectedBackend) { + willBeForwardedOverUDP = !serverPool->isTCPOnly(); + } uint32_t allowExpired = selectedBackend ? 0 : g_staleCacheEntriesTTL; diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 22eb4abeea..232e4d158c 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -1071,10 +1071,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 { diff --git a/pdns/dnsdistdist/dnsdist-backend.cc b/pdns/dnsdistdist/dnsdist-backend.cc index d59a5df0dc..ddad2abc1f 100644 --- a/pdns/dnsdistdist/dnsdist-backend.cc +++ b/pdns/dnsdistdist/dnsdist-backend.cc @@ -974,6 +974,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) @@ -984,6 +991,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 @@ -998,6 +1006,8 @@ void ServerPool::removeServer(shared_ptr& server) idx++; it++; } + tcpOnly = tcpOnly && it->second->isTCPOnly(); } + d_tcpOnly = tcpOnly; *servers = std::move(newServers); }