From 8d11c508780f7d30aff5b00fd5985b7a1ea642ba Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Tue, 18 Jun 2019 14:55:22 +0200 Subject: [PATCH] doCNAMECacheCheck: Remove one level of indent Done by returning early when no records were found. --- pdns/syncres.cc | 196 ++++++++++++++++++++++++------------------------ 1 file changed, 99 insertions(+), 97 deletions(-) diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 676dd0dca..22df12e49 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -1098,123 +1098,125 @@ bool SyncRes::doCNAMECacheCheck(const DNSName &qname, const QType &qtype, vector } while(!labels.empty()); } - if(!foundName.empty()) { - for(auto j=cset.cbegin() ; j != cset.cend() ; ++j) { - if (j->d_class != QClass::IN) { - continue; - } + if (foundName.empty()) { + LOG(prefix<d_ttl>(unsigned int) d_now.tv_sec) { + for(auto j=cset.cbegin() ; j != cset.cend() ; ++j) { + if (j->d_class != QClass::IN) { + continue; + } - if (!wasAuthZone && shouldValidate() && (wasAuth || wasForwardRecurse) && state == Indeterminate && d_requireAuthData) { - /* This means we couldn't figure out the state when this entry was cached, - most likely because we hadn't computed the zone cuts yet. */ - /* make sure they are computed before validating */ - DNSName subdomain(foundName); - /* if we are retrieving a DS, we only care about the state of the parent zone */ - if(qtype == QType::DS) - subdomain.chopOff(); - - computeZoneCuts(subdomain, g_rootdnsname, depth); - - vState recordState = getValidationStatus(foundName, false); - if (recordState == Secure) { - LOG(prefix<d_ttl>(unsigned int) d_now.tv_sec) { - LOG(prefix<d_content->getZoneRepresentation()<<"', validation state is "<d_content->getZoneRepresentation()<<"', validation state is "<(*j); - if (dnameRR == nullptr) { - throw ImmediateServFailException("Unable to get record content for "+foundName.toLogString()+"|DNAME cache entry"); - } - const auto& dnameSuffix = dnameRR->getTarget(); - DNSName targetPrefix = qname.makeRelative(foundName); - try { - dr.d_type = QType::CNAME; - dr.d_name = targetPrefix + foundName; - newTarget = targetPrefix + dnameSuffix; - dr.d_content = std::make_shared(CNAMERecordContent(newTarget)); - ret.push_back(dr); - } catch (const std::exception &e) { - // We should probably catch an std::range_error here and set the rcode to YXDOMAIN (RFC 6672, section 2.2) - // But this is consistent with processRecords - throw ImmediateServFailException("Unable to perform DNAME substitution(DNAME owner: '" + foundName.toLogString() + - "', DNAME target: '" + dnameSuffix.toLogString() + "', substituted name: '" + - targetPrefix.toLogString() + "." + dnameSuffix.toLogString() + - "' : " + e.what()); - } + DNSRecord dr=*j; + dr.d_ttl -= d_now.tv_sec; + dr.d_ttl = std::min(dr.d_ttl, capTTL); + const uint32_t ttl = dr.d_ttl; + ret.reserve(ret.size() + 2 + signatures.size() + authorityRecs.size()); + ret.push_back(dr); - LOG(prefix<(*j); - if (cnameContent == nullptr) { - throw ImmediateServFailException("Unable to get record content for "+foundName.toLogString()+"|CNAME cache entry"); - } - newTarget = cnameContent->getTarget(); + // Synthesize a CNAME + auto dnameRR = getRR(*j); + if (dnameRR == nullptr) { + throw ImmediateServFailException("Unable to get record content for "+foundName.toLogString()+"|DNAME cache entry"); + } + const auto& dnameSuffix = dnameRR->getTarget(); + DNSName targetPrefix = qname.makeRelative(foundName); + try { + dr.d_type = QType::CNAME; + dr.d_name = targetPrefix + foundName; + newTarget = targetPrefix + dnameSuffix; + dr.d_content = std::make_shared(CNAMERecordContent(newTarget)); + ret.push_back(dr); + } catch (const std::exception &e) { + // We should probably catch an std::range_error here and set the rcode to YXDOMAIN (RFC 6672, section 2.2) + // But this is consistent with processRecords + throw ImmediateServFailException("Unable to perform DNAME substitution(DNAME owner: '" + foundName.toLogString() + + "', DNAME target: '" + dnameSuffix.toLogString() + "', substituted name: '" + + targetPrefix.toLogString() + "." + dnameSuffix.toLogString() + + "' : " + e.what()); } - setbeenthere; - vState cnameState = Indeterminate; - res = doResolve(newTarget, qtype, ret, depth+1, beenthere, cnameState); - LOG(prefix<(*j); + if (cnameContent == nullptr) { + throw ImmediateServFailException("Unable to get record content for "+foundName.toLogString()+"|CNAME cache entry"); + } + newTarget = cnameContent->getTarget(); + } + + setbeenthere; + vState cnameState = Indeterminate; + res = doResolve(newTarget, qtype, ret, depth+1, beenthere, cnameState); + LOG(prefix<