From: Otto Moerbeek Date: Fri, 30 Aug 2024 11:18:19 +0000 (+0200) Subject: rec: Only log MOADNSExceptions if logging.log_common_errors is true. X-Git-Tag: rec-5.2.0-alpha1~47^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F14611%2Fhead;p=thirdparty%2Fpdns.git rec: Only log MOADNSExceptions if logging.log_common_errors is true. But do not ratelimit them --- diff --git a/pdns/recursordist/pdns_recursor.cc b/pdns/recursordist/pdns_recursor.cc index e636cf57a8..4831294d40 100644 --- a/pdns/recursordist/pdns_recursor.cc +++ b/pdns/recursordist/pdns_recursor.cc @@ -100,8 +100,6 @@ GlobalStateHolder g_dontThrottleNetmasks; GlobalStateHolder g_DoTToAuthNames; uint64_t g_latencyStatSize; -static pdns::RateLimitedLog s_rateLimitedLogger; - LWResult::Result UDPClientSocks::getSocket(const ComboAddress& toaddr, int* fileDesc) { *fileDesc = makeClientSocket(toaddr.sin4.sin_family); @@ -2285,13 +2283,18 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr eventTrace.add(RecEventTrace::LuaGetTag, ctag, false); } } + catch (const MOADNSException& moadnsexception) { + if (g_logCommonErrors) { + g_slogudpin->error(moadnsexception.what(), "Error parsing a query packet for tag determination", "qname", Logging::Loggable(qname), "excepion", Logging::Loggable("MOADNSException")); + } + } catch (const std::exception& stdException) { - s_rateLimitedLogger.log(g_slogudpin, "Error parsing a query packet for tag determination", stdException, "qname", Logging::Loggable(qname), "remote", Logging::Loggable(fromaddr)); + g_rateLimitedLogger.log(g_slogudpin, "Error parsing a query packet for tag determination", stdException, "qname", Logging::Loggable(qname), "remote", Logging::Loggable(fromaddr)); } } } catch (const std::exception& stdException) { - s_rateLimitedLogger.log(g_slogudpin, "Error parsing a query packet for tag determination, setting tag=0", stdException); + g_rateLimitedLogger.log(g_slogudpin, "Error parsing a query packet for tag determination, setting tag=0", stdException); } } diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 89543ee567..4a5a3b852c 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -145,7 +145,7 @@ unsigned int RecThreadInfo::s_numUDPWorkerThreads; unsigned int RecThreadInfo::s_numTCPWorkerThreads; thread_local unsigned int RecThreadInfo::t_id; -static pdns::RateLimitedLog s_rateLimitedLogger; +pdns::RateLimitedLog g_rateLimitedLogger; static std::map> parseCPUMap(Logr::log_t log) { @@ -2389,13 +2389,18 @@ static void handlePipeRequest(int fileDesc, FDMultiplexer::funcparam_t& /* var * resp = tmsg->func(); } catch (const PDNSException& pdnsException) { - s_rateLimitedLogger.log(g_slog->withName("runtime"), "PIPE function", pdnsException); + g_rateLimitedLogger.log(g_slog->withName("runtime"), "PIPE function", pdnsException); + } + catch (const MOADNSException& moadnsexception) { + if (g_logCommonErrors) { + g_slog->withName("runtime")->error(moadnsexception.what(), "PIPE function created an exception", "excepion", Logging::Loggable("MOADNSException")); + } } catch (const std::exception& stdException) { - s_rateLimitedLogger.log(g_slog->withName("runtime"), "PIPE function", stdException); + g_rateLimitedLogger.log(g_slog->withName("runtime"), "PIPE function", stdException); } catch (...) { - s_rateLimitedLogger.log(g_slog->withName("runtime"), "PIPE function"); + g_rateLimitedLogger.log(g_slog->withName("runtime"), "PIPE function"); } if (tmsg->wantAnswer) { if (write(RecThreadInfo::self().getPipes().writeFromThread, &resp, sizeof(resp)) != sizeof(resp)) { @@ -2810,13 +2815,13 @@ static void recLoop() runTCPMaintenance(threadInfo, listenOnTCP, maxTcpClients); } catch (const PDNSException& pdnsException) { - s_rateLimitedLogger.log(g_slog->withName("runtime"), "recLoop", pdnsException); + g_rateLimitedLogger.log(g_slog->withName("runtime"), "recLoop", pdnsException); } catch (const std::exception& stdException) { - s_rateLimitedLogger.log(g_slog->withName("runtime"), "recLoop", stdException); + g_rateLimitedLogger.log(g_slog->withName("runtime"), "recLoop", stdException); } catch (...) { - s_rateLimitedLogger.log(g_slog->withName("runtime"), "recLoop"); + g_rateLimitedLogger.log(g_slog->withName("runtime"), "recLoop"); } } } diff --git a/pdns/recursordist/rec-main.hh b/pdns/recursordist/rec-main.hh index e30224e4c7..91499bf690 100644 --- a/pdns/recursordist/rec-main.hh +++ b/pdns/recursordist/rec-main.hh @@ -38,6 +38,7 @@ #include "rec_channel.hh" #include "threadname.hh" #include "recpacketcache.hh" +#include "ratelimitedlog.hh" #ifdef NOD_ENABLED #include "nod.hh" @@ -240,6 +241,7 @@ extern RecursorControlChannel g_rcc; // only active in the handler thread extern thread_local std::unique_ptr t_proxyMapping; using ProxyMappingStats_t = std::unordered_map; +extern pdns::RateLimitedLog g_rateLimitedLogger; #ifdef NOD_ENABLED extern bool g_nodEnabled; diff --git a/pdns/recursordist/rec-tcp.cc b/pdns/recursordist/rec-tcp.cc index a1af4a1088..b5bba12961 100644 --- a/pdns/recursordist/rec-tcp.cc +++ b/pdns/recursordist/rec-tcp.cc @@ -345,19 +345,18 @@ static void doProcessTCPQuestion(std::unique_ptr& comboWriter, s // constructing the PB message. comboWriter->d_policyTags = comboWriter->d_gettagPolicyTags; } - catch (const std::exception& e) { + catch (const MOADNSException& moadnsexception) { if (g_logCommonErrors) { - SLOG(g_log << Logger::Warning << "Error parsing a query packet qname='" << qname << "' for tag determination, setting tag=0: " << e.what() << endl, - g_slogtcpin->info(Logr::Warning, "Error parsing a query packet for tag determination, setting tag=0", "remote", Logging::Loggable(conn->d_remote), "qname", Logging::Loggable(qname))); + g_slogtcpin->error(moadnsexception.what(), "Error parsing a query packet for tag determination", "qname", Logging::Loggable(qname), "excepion", Logging::Loggable("MOADNSException")); } } + catch (const std::exception& stdException) { + g_rateLimitedLogger.log(g_slogtcpin, "Error parsing a query packet for tag determination", stdException, "qname", Logging::Loggable(qname), "remote", Logging::Loggable(conn->d_remote)); + } } } - catch (const std::exception& e) { - if (g_logCommonErrors) { - SLOG(g_log << Logger::Warning << "Error parsing a query packet for tag determination, setting tag=0: " << e.what() << endl, - g_slogtcpin->error(Logr::Warning, e.what(), "Error parsing a query packet for tag determination, setting tag=0", "exception", Logging::Loggable("std::exception"), "remote", Logging::Loggable(conn->d_remote))); - } + catch (const std::exception& stdException) { + g_rateLimitedLogger.log(g_slogudpin, "Error parsing a query packet for tag determination, setting tag=0", stdException, "remote", Logging::Loggable(conn->d_remote)); } }