]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Only log MOADNSExceptions if logging.log_common_errors is true. 14611/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 30 Aug 2024 11:18:19 +0000 (13:18 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 30 Aug 2024 12:51:07 +0000 (14:51 +0200)
But do not ratelimit them

pdns/recursordist/pdns_recursor.cc
pdns/recursordist/rec-main.cc
pdns/recursordist/rec-main.hh
pdns/recursordist/rec-tcp.cc

index e636cf57a86f1deae8b5bf01fe85bd38d6a9a82c..4831294d409ddf1c07e0cf88a5400e4db7534389 100644 (file)
@@ -100,8 +100,6 @@ GlobalStateHolder<NetmaskGroup> g_dontThrottleNetmasks;
 GlobalStateHolder<SuffixMatchNode> 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);
       }
     }
 
index 89543ee5671b475ea6d73e4cb7863363faf30f8f..4a5a3b852ce8d6dcc744859864d6bf6508f2cb77 100644 (file)
@@ -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<unsigned int, std::set<int>> 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");
     }
   }
 }
index e30224e4c736d68079d7a30d290dad1ff3603594..91499bf69091d9be26341267a044abbf75d379d7 100644 (file)
@@ -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<ProxyMapping> t_proxyMapping;
 using ProxyMappingStats_t = std::unordered_map<Netmask, ProxyMappingCounts>;
+extern pdns::RateLimitedLog g_rateLimitedLogger;
 
 #ifdef NOD_ENABLED
 extern bool g_nodEnabled;
index a1af4a10889e9084a3c381c42e15a32cdbf70961..b5bba129615f0bf7ec3888d2fceaf8e392e7884b 100644 (file)
@@ -345,19 +345,18 @@ static void doProcessTCPQuestion(std::unique_ptr<DNSComboWriter>& 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));
     }
   }