From 7cf54c10833f2580200e91b4708c3032e125a5d3 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 3 Aug 2020 13:05:47 +0200 Subject: [PATCH] Lets do (non-recursive) cases with qname minimization. Have to shortcut forwarding in doResolveNoQNameMinimization() in that case, otherwise all are queries are just forwarded. --- pdns/syncres.cc | 16 ++++++++++------ pdns/syncres.hh | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pdns/syncres.cc b/pdns/syncres.cc index ca7f898dc8..800cd7bb06 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -406,10 +406,10 @@ bool SyncRes::doOOBResolve(const DNSName &qname, const QType &qtype, vectorsecond, qname, qtype, ret, res); } -bool SyncRes::isForwardOrAuth(const DNSName &qname) const { +bool SyncRes::isRecursiveForwardOrAuth(const DNSName &qname) const { DNSName authname(qname); domainmap_t::const_iterator iter = getBestAuthZone(&authname); - return iter != t_sstorage.domainmap->end(); + return iter != t_sstorage.domainmap->end() && (iter->second.isAuth() || iter->second.shouldRecurse()); } uint64_t SyncRes::doEDNSDump(int fd) @@ -641,7 +641,8 @@ int SyncRes::asyncresolveWrapper(const ComboAddress& ip, bool ednsMANDATORY, con int SyncRes::doResolve(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, set& beenthere, vState& state) { - if (!getQNameMinimization() || isForwardOrAuth(qname)) { + // In the auth or recursive forward case, it does nt make sense to do qname-minimization + if (!getQNameMinimization() || isRecursiveForwardOrAuth(qname)) { return doResolveNoQNameMinimization(qname, qtype, ret, depth, beenthere, state); } @@ -671,7 +672,10 @@ int SyncRes::doResolve(const DNSName &qname, const QType &qtype, vector retq; bool old = setCacheOnly(true); bool fromCache = false; - int res = doResolveNoQNameMinimization(qname, qtype, retq, depth, beenthere, state, &fromCache); + // For cache peeking, we tell doResolveNoQNameMinimization not to consider the (non-recursive) forward case. + // Otherwise all queries in a forward domain will be forwarded, while we want to consult the cache. + // The out-of-band cases for doResolveNoQNameMinimization() should be reconsidered and redone some day. + int res = doResolveNoQNameMinimization(qname, qtype, retq, depth, beenthere, state, &fromCache, nullptr, false); setCacheOnly(old); if (fromCache) { QLOG("Step0 Found in cache"); @@ -771,7 +775,7 @@ int SyncRes::doResolve(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, set& beenthere, vState& state, bool *fromCache, StopAtDelegation *stopAtDelegation) +int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, set& beenthere, vState& state, bool *fromCache, StopAtDelegation *stopAtDelegation, bool considerforwards) { string prefix; if(doLog()) { @@ -805,7 +809,7 @@ int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType &qty *fromCache = d_wasOutOfBand; return res; } - else { + else if (considerforwards) { const vector& servers = iter->second.d_servers; const ComboAddress remoteIP = servers.front(); LOG(prefix< ednsmask, bool sendRDQuery, NsSet &nameservers, std::vector& ret, const DNSFilterEngine& dfe, bool* gotNewServers, int* rcode, vState& state); int doResolve(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, set& beenthere, vState& state); - int doResolveNoQNameMinimization(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, set& beenthere, vState& state, bool* fromCache = NULL, StopAtDelegation* stopAtDelegation = NULL); + int doResolveNoQNameMinimization(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, set& beenthere, vState& state, bool* fromCache = NULL, StopAtDelegation* stopAtDelegation = NULL, bool considerforwards = true); bool doOOBResolve(const AuthDomain& domain, const DNSName &qname, const QType &qtype, vector&ret, int& res); bool doOOBResolve(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, int &res); - bool isForwardOrAuth(const DNSName &qname) const; + bool isRecursiveForwardOrAuth(const DNSName &qname) const; domainmap_t::const_iterator getBestAuthZone(DNSName* qname) const; bool doCNAMECacheCheck(const DNSName &qname, const QType &qtype, vector&ret, unsigned int depth, int &res, vState& state, bool wasAuthZone, bool wasForwardRecurse); bool doCacheCheck(const DNSName &qname, const DNSName& authname, bool wasForwardedOrAuthZone, bool wasAuthZone, bool wasForwardRecurse, const QType &qtype, vector&ret, unsigned int depth, int &res, vState& state); -- 2.47.2