From 1b3fbc88567fb65f1733c930171bd13f75b00874 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 6 Jun 2024 09:42:19 +0200 Subject: [PATCH] Reduce nesting in UDR check --- pdns/recursordist/pdns_recursor.cc | 37 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/pdns/recursordist/pdns_recursor.cc b/pdns/recursordist/pdns_recursor.cc index 511f46ca71..de564d26ad 100644 --- a/pdns/recursordist/pdns_recursor.cc +++ b/pdns/recursordist/pdns_recursor.cc @@ -666,24 +666,25 @@ static bool udrCheckUniqueDNSRecord(Logr::log_t nodlogger, const DNSName& dname, { bool ret = false; // First check the (sub)domain isn't ignored for UDR purposes - if (!g_udrDomainWL.check(dname)) { - if (record.d_place == DNSResourceRecord::ANSWER || record.d_place == DNSResourceRecord::ADDITIONAL) { - // Create a string that represent a triplet of (qname, qtype and RR[type, name, content]) - std::stringstream strStream; - strStream << dname.toDNSStringLC() << ":" << qtype << ":" << qtype << ":" << record.d_type << ":" << record.d_name.toDNSStringLC() << ":" << record.getContent()->getZoneRepresentation(); - if (g_udrDBp && g_udrDBp->isUniqueResponse(strStream.str())) { - if (g_udrLog) { - // This should also probably log to a dedicated file. - SLOG(g_log << Logger::Notice << "Unique response observed: qname=" << dname << " qtype=" << QType(qtype) << " rrtype=" << QType(record.d_type) << " rrname=" << record.d_name << " rrcontent=" << record.getContent()->getZoneRepresentation() << endl, - nodlogger->info(Logr::Notice, "New response observed", - "qtype", Logging::Loggable(QType(qtype)), - "rrtype", Logging::Loggable(QType(record.d_type)), - "rrname", Logging::Loggable(record.d_name), - "rrcontent", Logging::Loggable(record.getContent()->getZoneRepresentation()));); - } - t_Counters.at(rec::Counter::udrCount)++; - ret = true; - } + if (g_udrDomainWL.check(dname)) { + return ret; + } + if (record.d_place == DNSResourceRecord::ANSWER || record.d_place == DNSResourceRecord::ADDITIONAL) { + // Create a string that represent a triplet of (qname, qtype and RR[type, name, content]) + std::stringstream strStream; + strStream << dname.toDNSStringLC() << ":" << qtype << ":" << qtype << ":" << record.d_type << ":" << record.d_name.toDNSStringLC() << ":" << record.getContent()->getZoneRepresentation(); + if (g_udrDBp && g_udrDBp->isUniqueResponse(strStream.str())) { + if (g_udrLog) { + // This should also probably log to a dedicated file. + SLOG(g_log << Logger::Notice << "Unique response observed: qname=" << dname << " qtype=" << QType(qtype) << " rrtype=" << QType(record.d_type) << " rrname=" << record.d_name << " rrcontent=" << record.getContent()->getZoneRepresentation() << endl, + nodlogger->info(Logr::Notice, "New response observed", + "qtype", Logging::Loggable(QType(qtype)), + "rrtype", Logging::Loggable(QType(record.d_type)), + "rrname", Logging::Loggable(record.d_name), + "rrcontent", Logging::Loggable(record.getContent()->getZoneRepresentation()));); + } + t_Counters.at(rec::Counter::udrCount)++; + ret = true; } } return ret; -- 2.47.2