From: Remi Gacogne Date: Thu, 22 Apr 2021 10:17:04 +0000 (+0200) Subject: dnsdist: Also lookup the cache for UDP answers for DoH X-Git-Tag: dnsdist-1.7.0-alpha1~45^2~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9774bc83137b653ff169ff320859fa6b61649c98;p=thirdparty%2Fpdns.git dnsdist: Also lookup the cache for UDP answers for DoH --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index e64620ed87..16bde52b51 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1198,7 +1198,7 @@ ProcessQueryResult processQuery(DNSQuestion& dq, ClientState& cs, LocalHolders& // we need ECS parsing (parseECS) to be true so we can be sure that the initial incoming query did not have an existing // ECS option, which would make it unsuitable for the zero-scope feature. if (dq.packetCache && !dq.skipCache && (!selectedBackend || !selectedBackend->disableZeroScope) && dq.packetCache->isECSParsingEnabled()) { - if (dq.packetCache->get(dq, dq.getHeader()->id, &dq.cacheKeyNoECS, dq.subnet, dq.dnssecOK, !dq.overTCP() || dq.getProtocol() == dnsdist::Protocol::DoH, allowExpired)) { + if (dq.packetCache->get(dq, dq.getHeader()->id, &dq.cacheKeyNoECS, dq.subnet, dq.dnssecOK, !dq.overTCP(), allowExpired)) { if (!prepareOutgoingResponse(holders, cs, dq, true)) { return ProcessQueryResult::Drop; @@ -1220,7 +1220,7 @@ ProcessQueryResult processQuery(DNSQuestion& dq, ClientState& cs, LocalHolders& } if (dq.packetCache && !dq.skipCache) { - if (dq.packetCache->get(dq, dq.getHeader()->id, &dq.cacheKey, dq.subnet, dq.dnssecOK, !dq.overTCP() || dq.getProtocol() == dnsdist::Protocol::DoH, allowExpired)) { + if (dq.packetCache->get(dq, dq.getHeader()->id, &dq.cacheKey, dq.subnet, dq.dnssecOK, !dq.overTCP(), allowExpired)) { restoreFlags(dq.getHeader(), dq.origFlags); @@ -1230,6 +1230,23 @@ ProcessQueryResult processQuery(DNSQuestion& dq, ClientState& cs, LocalHolders& return ProcessQueryResult::SendAnswer; } + else if (dq.protocol == dnsdist::Protocol::DoH) { + /* do a second-lookup for UDP responses */ + uint32_t udpCacheKey = 0; + /* we need to do a copy to be able to restore the query on a TC=1 cached answer */ + PacketBuffer initialQuery(dq.getData()); + if (dq.packetCache->get(dq, dq.getHeader()->id, &udpCacheKey, dq.subnet, dq.dnssecOK, true, allowExpired)) { + if (dq.getHeader()->tc == 0) { + if (!prepareOutgoingResponse(holders, cs, dq, true)) { + return ProcessQueryResult::Drop; + } + + return ProcessQueryResult::SendAnswer; + } + dq.getMutableData() = std::move(initialQuery); + } + } + ++g_stats.cacheMisses; }