From: Otto Moerbeek Date: Fri, 23 Feb 2024 12:24:25 +0000 (+0100) Subject: rec: log if a dnssec related limit was hit (if log_bogus is set) X-Git-Tag: rec-5.0.3^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=26bb66635b87c33a065bd2bbe8c3d060cadcff92;p=thirdparty%2Fpdns.git rec: log if a dnssec related limit was hit (if log_bogus is set) (cherry picked from commit 9d4a01ffa2b724907e07db423da048f68f15eca2) --- diff --git a/pdns/recursordist/pdns_recursor.cc b/pdns/recursordist/pdns_recursor.cc index f5978c7fed..200635c1c0 100644 --- a/pdns/recursordist/pdns_recursor.cc +++ b/pdns/recursordist/pdns_recursor.cc @@ -569,10 +569,10 @@ static PolicyResult handlePolicyHit(const DNSFilterEngine::Policy& appliedPolicy break; } catch (const pdns::validation::TooManySEC3IterationsException& e) { - if (g_logCommonErrors) { + if (g_logCommonErrors || (g_dnssecLogBogus && resolver.getDNSSECLimitHit())) { SLOG(g_log << Logger::Notice << "Sending SERVFAIL to " << comboWriter->getRemote() << " during resolve of the custom filter policy '" << appliedPolicy.getName() << "' while resolving '" << comboWriter->d_mdp.d_qname << "' because: " << e.what() << endl, resolver.d_slog->error(Logr::Notice, e.what(), "Sending SERVFAIL during resolve of the custom filter policy", - "policyName", Logging::Loggable(appliedPolicy.getName()), "exception", Logging::Loggable("TooManySEC3IterationsException"))); + "policyName", Logging::Loggable(appliedPolicy.getName()), "exception", Logging::Loggable("TooManySEC3IterationsException"), "dnsseclimithit", Logging::Loggable(resolver.getDNSSECLimitHit()))); } res = RCode::ServFail; break; @@ -1282,7 +1282,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi catch (const pdns::validation::TooManySEC3IterationsException& e) { if (g_logCommonErrors) { SLOG(g_log << Logger::Notice << "Sending SERVFAIL to " << comboWriter->getRemote() << " during resolve of '" << comboWriter->d_mdp.d_qname << "' because: " << e.what() << endl, - resolver.d_slog->error(Logr::Notice, e.what(), "Sending SERVFAIL during resolve")); + resolver.d_slog->error(Logr::Notice, e.what(), "Sending SERVFAIL during resolve", "dnsseclimithit", Logging::Loggable(true))); } res = RCode::ServFail; } @@ -1403,6 +1403,9 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi if (resolver.doLog() || vStateIsBogus(state)) { // Only create logging object if needed below, beware if you change the logging logic! log = resolver.d_slog->withValues("vstate", Logging::Loggable(state)); + if (resolver.getDNSSECLimitHit()) { + log = log->withValues("dnsseclimithit", Logging::Loggable(true)); + } auto xdnssec = g_xdnssec.getLocal(); if (xdnssec->check(comboWriter->d_mdp.d_qname)) { log = log->withValues("in-x-dnssec-names", Logging::Loggable(1)); @@ -1466,9 +1469,9 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi goto sendit; // NOLINT(cppcoreguidelines-avoid-goto) } catch (const pdns::validation::TooManySEC3IterationsException& e) { - if (g_logCommonErrors) { + if (g_logCommonErrors || (g_dnssecLogBogus && resolver.getDNSSECLimitHit())) { SLOG(g_log << Logger::Notice << "Sending SERVFAIL to " << comboWriter->getRemote() << " during validation of '" << comboWriter->d_mdp.d_qname << "|" << QType(comboWriter->d_mdp.d_qtype) << "' because: " << e.what() << endl, - resolver.d_slog->error(Logr::Notice, e.what(), "Sending SERVFAIL during validation", "exception", Logging::Loggable("TooManySEC3IterationsException"))); + resolver.d_slog->error(Logr::Notice, e.what(), "Sending SERVFAIL during validation", "exception", Logging::Loggable("TooManySEC3IterationsException"), "dnsseclimithit", Logging::Loggable(resolver.getDNSSECLimitHit()))); } goto sendit; // NOLINT(cppcoreguidelines-avoid-goto) } diff --git a/pdns/recursordist/syncres.hh b/pdns/recursordist/syncres.hh index b77fc24c3e..4298b8b3bd 100644 --- a/pdns/recursordist/syncres.hh +++ b/pdns/recursordist/syncres.hh @@ -465,6 +465,11 @@ public: return d_queryValidationState; } + [[nodiscard]] bool getDNSSECLimitHit() const + { + return d_validationContext.d_limitHit; + } + void setQueryReceivedOverTCP(bool tcp) { d_queryReceivedOverTCP = tcp; diff --git a/pdns/validate.cc b/pdns/validate.cc index 16d144e643..6833ab9baa 100644 --- a/pdns/validate.cc +++ b/pdns/validate.cc @@ -176,6 +176,7 @@ bool denialProvesNoDelegation(const DNSName& zone, const std::vector& } if (g_maxNSEC3sPerRecordToConsider > 0 && nsec3sConsidered >= g_maxNSEC3sPerRecordToConsider) { + context.d_limitHit = true; return false; } nsec3sConsidered++; @@ -704,6 +705,7 @@ dState getDenial(const cspmap_t &validrrsets, const DNSName& qname, const uint16 if (g_maxNSEC3sPerRecordToConsider > 0 && nsec3sConsidered >= g_maxNSEC3sPerRecordToConsider) { VLOG(log, qname << ": Too many NSEC3s for this record"< 0 && nsec3sConsidered >= g_maxNSEC3sPerRecordToConsider) { VLOG(log, qname << ": Too many NSEC3s for this record"< 0 && nsec3sConsidered >= g_maxNSEC3sPerRecordToConsider) { VLOG(log, qname << ": Too many NSEC3s for this record"< 0 && signaturesConsidered >= g_maxRRSIGsPerRecordToConsider) { VLOG(log, name<<": We have already considered "< 0 && dnskeysConsidered >= g_maxDNSKEYsToConsider) { VLOG(log, name << ": We have already considered "<d_tag)<<" and algorithm "<d_algorithm)<<", not considering the remaining ones for this signature"< 0 && signaturesConsidered >= g_maxRRSIGsPerRecordToConsider) { VLOG(log, zone << ": We have already considered "< 0 && dnskeysConsidered >= g_maxDNSKEYsToConsider) { VLOG(log, zone << ": We have already considered "<d_tag)<<" and algorithm "<d_algorithm)<<", not considering the remaining ones for this signature"< 0 && signaturesConsidered >= g_maxRRSIGsPerRecordToConsider) { VLOG(log, zone << ": We have already considered "<