From: Otto Moerbeek Date: Wed, 29 Jun 2022 09:46:51 +0000 (+0200) Subject: Make serveStale a field instead of a parameter passed around X-Git-Tag: rec-4.8.0-alpha1~24^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6af46497ef52055f47ebd19c9effd49621e0197a;p=thirdparty%2Fpdns.git Make serveStale a field instead of a parameter passed around --- diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 406a898c5a..b06851ceed 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -1807,7 +1807,7 @@ int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType qtyp for (int loop = 0; loop < iterations; loop++) { // First try a regular resolve - const bool serveStale = loop == 1; + d_serveStale = loop == 1; // When we're not on the last iteration, a timeout is not fatal const bool exceptionOnTimeout = loop == iterations - 1; @@ -1877,7 +1877,7 @@ int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType qtyp /* When we are looking for a DS, we want to the non-CNAME cache check first because we can actually have a DS (from the parent zone) AND a CNAME (from the child zone), and what we really want is the DS */ - if (qtype != QType::DS && doCNAMECacheCheck(qname, qtype, ret, depth, res, state, wasAuthZone, wasForwardRecurse, serveStale)) { // will reroute us if needed + if (qtype != QType::DS && doCNAMECacheCheck(qname, qtype, ret, depth, res, state, wasAuthZone, wasForwardRecurse)) { // will reroute us if needed d_wasOutOfBand = wasAuthZone; // Here we have an issue. If we were prevented from going out to the network (cache-only was set, possibly because we // are in QM Step0) we might have a CNAME but not the corresponding target. @@ -1906,7 +1906,7 @@ int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType qtyp return res; } - if (doCacheCheck(qname, authname, wasForwardedOrAuthZone, wasAuthZone, wasForwardRecurse, qtype, ret, depth, res, state, serveStale)) { + if (doCacheCheck(qname, authname, wasForwardedOrAuthZone, wasAuthZone, wasForwardRecurse, qtype, ret, depth, res, state)) { // we done d_wasOutOfBand = wasAuthZone; if (fromCache) { @@ -1926,7 +1926,7 @@ int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType qtyp } /* if we have not found a cached DS (or denial of), now is the time to look for a CNAME */ - if (qtype == QType::DS && doCNAMECacheCheck(qname, qtype, ret, depth, res, state, wasAuthZone, wasForwardRecurse, serveStale)) { // will reroute us if needed + if (qtype == QType::DS && doCNAMECacheCheck(qname, qtype, ret, depth, res, state, wasAuthZone, wasForwardRecurse)) { // will reroute us if needed d_wasOutOfBand = wasAuthZone; // Here we have an issue. If we were prevented from going out to the network (cache-only was set, possibly because we // are in QM Step0) we might have a CNAME but not the corresponding target. @@ -1975,7 +1975,7 @@ int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType qtyp subdomain=getBestNSNamesFromCache(subdomain, qtype, nsset, &flawedNSSet, depth, beenthere); // pass beenthere to both occasions } - res = doResolveAt(nsset, subdomain, flawedNSSet, qname, qtype, ret, depth, beenthere, state, stopAtDelegation, nullptr, serveStale); + res = doResolveAt(nsset, subdomain, flawedNSSet, qname, qtype, ret, depth, beenthere, state, stopAtDelegation, nullptr); if (res == -1 && s_save_parent_ns_set) { // It did not work out, lets check if we have a saved parent NS set @@ -1995,7 +1995,7 @@ int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType qtyp } if (fallBack.size() > 0) { LOG(prefix<inc(subdomain); @@ -2047,7 +2047,7 @@ struct speedOrderCA /** This function explicitly goes out for A or AAAA addresses */ -vector SyncRes::getAddrs(const DNSName &qname, unsigned int depth, set& beenthere, bool cacheOnly, unsigned int& addressQueriesForNS, bool serveStale) +vector SyncRes::getAddrs(const DNSName &qname, unsigned int depth, set& beenthere, bool cacheOnly, unsigned int& addressQueriesForNS) { typedef vector res_t; typedef vector ret_t; @@ -2064,7 +2064,7 @@ vector SyncRes::getAddrs(const DNSName &qname, unsigned int depth, d_followCNAME = true; MemRecursorCache::Flags flags = MemRecursorCache::None; - if (serveStale) { + if (d_serveStale) { flags |= MemRecursorCache::ServeStale; } try { @@ -2210,6 +2210,10 @@ void SyncRes::getBestNSFromCache(const DNSName &qname, const QType qtype, vector } bestns.clear(); bool brokeloop; + MemRecursorCache::Flags flags = MemRecursorCache::None; + if (d_serveStale) { + flags |= MemRecursorCache::ServeStale; + } do { if (cutOffDomain && (subdomain == *cutOffDomain || !subdomain.isPartOf(*cutOffDomain))) { break; @@ -2219,7 +2223,7 @@ void SyncRes::getBestNSFromCache(const DNSName &qname, const QType qtype, vector vector ns; *flawedNSSet = false; - if(g_recCache->get(d_now.tv_sec, subdomain, QType::NS, MemRecursorCache::None, &ns, d_cacheRemote, d_routingTag) > 0) { + if (g_recCache->get(d_now.tv_sec, subdomain, QType::NS, flags, &ns, d_cacheRemote, d_routingTag) > 0) { if (s_maxnsperresolve > 0 && ns.size() > s_maxnsperresolve) { vector selected; selected.reserve(s_maxnsperresolve); @@ -2419,7 +2423,7 @@ static bool scanForCNAMELoop(const DNSName& name, const vector& recor return false; } -bool SyncRes::doCNAMECacheCheck(const DNSName &qname, const QType qtype, vector& ret, unsigned int depth, int &res, vState& state, bool wasAuthZone, bool wasForwardRecurse, bool serveStale) +bool SyncRes::doCNAMECacheCheck(const DNSName &qname, const QType qtype, vector& ret, unsigned int depth, int &res, vState& state, bool wasAuthZone, bool wasForwardRecurse) { string prefix; if(doLog()) { @@ -2450,7 +2454,7 @@ bool SyncRes::doCNAMECacheCheck(const DNSName &qname, const QType qtype, vector< if (d_refresh) { flags |= MemRecursorCache::Refresh; } - if (serveStale) { + if (d_serveStale) { flags |= MemRecursorCache::ServeStale; } if (g_recCache->get(d_now.tv_sec, qname, QType::CNAME, flags, &cset, d_cacheRemote, d_routingTag, d_doDNSSEC ? &signatures : nullptr, d_doDNSSEC ? &authorityRecs : nullptr, &d_wasVariable, &state, &wasAuth, &authZone, &d_fromAuthIP) > 0) { @@ -2743,7 +2747,7 @@ void SyncRes::computeNegCacheValidationStatus(const NegCache::NegCacheEntry& ne, } } -bool SyncRes::doCacheCheck(const DNSName &qname, const DNSName& authname, bool wasForwardedOrAuthZone, bool wasAuthZone, bool wasForwardRecurse, QType qtype, vector&ret, unsigned int depth, int &res, vState& state, bool serveStale) +bool SyncRes::doCacheCheck(const DNSName &qname, const DNSName& authname, bool wasForwardedOrAuthZone, bool wasAuthZone, bool wasForwardRecurse, QType qtype, vector&ret, unsigned int depth, int &res, vState& state) { bool giveNegative=false; @@ -2861,7 +2865,7 @@ bool SyncRes::doCacheCheck(const DNSName &qname, const DNSName& authname, bool w if (d_refresh) { flags |= MemRecursorCache::Refresh; } - if (serveStale) { + if (d_serveStale) { flags |= MemRecursorCache::ServeStale; } if(g_recCache->get(d_now.tv_sec, sqname, sqt, flags, &cset, d_cacheRemote, d_routingTag, d_doDNSSEC ? &signatures : nullptr, d_doDNSSEC ? &authorityRecs : nullptr, &d_wasVariable, &cachedState, &wasCachedAuth, nullptr, &d_fromAuthIP) > 0) { @@ -3328,7 +3332,7 @@ bool SyncRes::nameserverIPBlockedByRPZ(const DNSFilterEngine& dfe, const ComboAd return false; } -vector SyncRes::retrieveAddressesForNS(const std::string& prefix, const DNSName& qname, std::vector>::const_iterator& tns, const unsigned int depth, set& beenthere, const vector>& rnameservers, NsSet& nameservers, bool& sendRDQuery, bool& pierceDontQuery, bool& flawedNSSet, bool cacheOnly, unsigned int &nretrieveAddressesForNS, bool serveStale) +vector SyncRes::retrieveAddressesForNS(const std::string& prefix, const DNSName& qname, std::vector>::const_iterator& tns, const unsigned int depth, set& beenthere, const vector>& rnameservers, NsSet& nameservers, bool& sendRDQuery, bool& pierceDontQuery, bool& flawedNSSet, bool cacheOnly, unsigned int &nretrieveAddressesForNS) { vector result; @@ -3345,7 +3349,7 @@ vector SyncRes::retrieveAddressesForNS(const std::string& prefix, LOG(prefix<first<< "' ("<<1+tns-rnameservers.begin()<<"/"<<(unsigned int)rnameservers.size()<<")"<first, depth, beenthere, cacheOnly, nretrieveAddressesForNS, serveStale); + result = getAddrs(tns->first, depth, beenthere, cacheOnly, nretrieveAddressesForNS); } // Other exceptions should likely not throttle... catch (const ImmediateServFailException& ex) { @@ -4250,7 +4254,7 @@ void SyncRes::rememberParentSetIfNeeded(const DNSName& domain, const vectorgetNS(); set beenthereIgnored; unsigned int nretrieveAddressesForNSIgnored; - auto addresses = getAddrs(name, depth, beenthereIgnored, true, nretrieveAddressesForNSIgnored, false); + auto addresses = getAddrs(name, depth, beenthereIgnored, true, nretrieveAddressesForNSIgnored); entries.emplace(name, addresses); } s_savedParentNSSet.lock()->emplace(domain, std::move(entries), d_now.tv_sec + ttl); @@ -5492,7 +5496,7 @@ bool SyncRes::doDoTtoAuth(const DNSName& ns) const int SyncRes::doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, const DNSName &qname, const QType qtype, vector&ret, unsigned int depth, set&beenthere, vState& state, StopAtDelegation* stopAtDelegation, - map>* fallBack, bool serveStale) + map>* fallBack) { auto luaconfsLocal = g_luaconfs.getLocal(); string prefix; @@ -5595,7 +5599,7 @@ int SyncRes::doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, con } } if (remoteIPs.size() == 0) { - remoteIPs = retrieveAddressesForNS(prefix, qname, tns, depth, beenthere, rnameservers, nameservers, sendRDQuery, pierceDontQuery, flawedNSSet, cacheOnly, addressQueriesForNS, serveStale); + remoteIPs = retrieveAddressesForNS(prefix, qname, tns, depth, beenthere, rnameservers, nameservers, sendRDQuery, pierceDontQuery, flawedNSSet, cacheOnly, addressQueriesForNS); } if(remoteIPs.empty()) { diff --git a/pdns/syncres.hh b/pdns/syncres.hh index e4486989c1..7f6a71c21b 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -551,7 +551,7 @@ private: bool doDoTtoAuth(const DNSName& ns) const; int doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, const DNSName &qname, QType qtype, vector&ret, unsigned int depth, set&beenthere, vState& state, StopAtDelegation* stopAtDelegation, - std::map>* fallback, bool serveStale); + std::map>* fallback); bool doResolveAtThisIP(const std::string& prefix, const DNSName& qname, const QType qtype, LWResult& lwr, boost::optional& ednsmask, const DNSName& auth, bool const sendRDQuery, const bool wasForwarded, const DNSName& nsName, const ComboAddress& remoteIP, bool doTCP, bool doDoT, bool& truncated, bool& spoofed, bool dontThrottle = false); bool processAnswer(unsigned int depth, LWResult& lwr, const DNSName& qname, const QType qtype, DNSName& auth, bool wasForwarded, const boost::optional ednsmask, bool sendRDQuery, NsSet &nameservers, std::vector& ret, const DNSFilterEngine& dfe, bool* gotNewServers, int* rcode, vState& state, const ComboAddress& remoteIP); @@ -562,22 +562,22 @@ private: bool isRecursiveForwardOrAuth(const DNSName &qname) const; bool isForwardOrAuth(const DNSName &qname) const; domainmap_t::const_iterator getBestAuthZone(DNSName* qname) const; - bool doCNAMECacheCheck(const DNSName &qname, QType qtype, vector&ret, unsigned int depth, int &res, vState& state, bool wasAuthZone, bool wasForwardRecurse, bool serveStale); - bool doCacheCheck(const DNSName &qname, const DNSName& authname, bool wasForwardedOrAuthZone, bool wasAuthZone, bool wasForwardRecurse, QType qtype, vector&ret, unsigned int depth, int &res, vState& state, bool serveStale); + bool doCNAMECacheCheck(const DNSName &qname, 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, QType qtype, vector&ret, unsigned int depth, int &res, vState& state); void getBestNSFromCache(const DNSName &qname, QType qtype, vector&bestns, bool* flawedNSSet, unsigned int depth, set& beenthere, const boost::optional& cutOffDomain = boost::none); DNSName getBestNSNamesFromCache(const DNSName &qname, QType qtype, NsSet& nsset, bool* flawedNSSet, unsigned int depth, set&beenthere); inline vector> shuffleInSpeedOrder(NsSet &nameservers, const string &prefix); inline vector shuffleForwardSpeed(const vector &rnameservers, const string &prefix, const bool wasRd); bool moreSpecificThan(const DNSName& a, const DNSName &b) const; - vector getAddrs(const DNSName &qname, unsigned int depth, set& beenthere, bool cacheOnly, unsigned int& addressQueriesForNS, bool serveStale); + vector getAddrs(const DNSName &qname, unsigned int depth, set& beenthere, bool cacheOnly, unsigned int& addressQueriesForNS); bool nameserversBlockedByRPZ(const DNSFilterEngine& dfe, const NsSet& nameservers); bool nameserverIPBlockedByRPZ(const DNSFilterEngine& dfe, const ComboAddress&); void checkMaxQperQ(const DNSName& qname) const; bool throttledOrBlocked(const std::string& prefix, const ComboAddress& remoteIP, const DNSName& qname, QType qtype, bool pierceDontQuery); - vector retrieveAddressesForNS(const std::string& prefix, const DNSName& qname, vector>::const_iterator& tns, const unsigned int depth, set& beenthere, const vector>& rnameservers, NsSet& nameservers, bool& sendRDQuery, bool& pierceDontQuery, bool& flawedNSSet, bool cacheOnly, unsigned int& addressQueriesForNS, bool serveStale); + vector retrieveAddressesForNS(const std::string& prefix, const DNSName& qname, vector>::const_iterator& tns, const unsigned int depth, set& beenthere, const vector>& rnameservers, NsSet& nameservers, bool& sendRDQuery, bool& pierceDontQuery, bool& flawedNSSet, bool cacheOnly, unsigned int& addressQueriesForNS); void sanitizeRecords(const std::string& prefix, LWResult& lwr, const DNSName& qname, const QType qtype, const DNSName& auth, bool wasForwarded, bool rdQuery); /* This function will check whether the answer should have the AA bit set, and will set if it should be set and isn't. @@ -647,7 +647,8 @@ private: bool d_queryReceivedOverTCP{false}; bool d_followCNAME{true}; bool d_refresh{false}; - + bool d_serveStale{false}; + LogMode d_lm; };