]> granicus.if.org Git - pdns/commitdiff
rec: Drop incoming queries with a qdcount of 0
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 6 Sep 2018 17:09:16 +0000 (19:09 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 6 Sep 2018 17:09:16 +0000 (19:09 +0200)
pdns/pdns_recursor.cc
pdns/rec-snmp.cc
pdns/rec_channel_rec.cc
pdns/recursordist/RECURSOR-MIB.txt
pdns/recursordist/docs/metrics.rst
pdns/syncres.hh

index 90cac60612f2246e448dd75fff52d52075eb309f..12a38591dbca595818f6c2aa5582b3cb7716aa01 100644 (file)
@@ -1733,7 +1733,9 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var)
   else if(conn->state==TCPConnection::GETQUESTION) {
     ssize_t bytes=recv(conn->getFD(), &conn->data[conn->bytesread], conn->qlen - conn->bytesread, 0);
     if(!bytes || bytes < 0 || bytes > std::numeric_limits<std::uint16_t>::max()) {
-      g_log<<Logger::Error<<"TCP client "<< conn->d_remote.toStringWithPort() <<" disconnected while reading question body"<<endl;
+      if(g_logCommonErrors) {
+        g_log<<Logger::Error<<"TCP client "<< conn->d_remote.toStringWithPort() <<" disconnected while reading question body"<<endl;
+      }
       t_fdm->removeReadFD(fd);
       return;
     }
@@ -1818,9 +1820,9 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var)
         dc->d_uuid = (*t_uuidGenerator)();
       }
 
+      const struct dnsheader* dh = reinterpret_cast<const struct dnsheader*>(&conn->data[0]);
       if(t_protobufServer) {
         try {
-          const struct dnsheader* dh = reinterpret_cast<const struct dnsheader*>(&conn->data[0]);
 
           if (logQuery && !(luaconfsLocal->protobufExportConfig.taggedOnly && dc->d_policyTags.empty())) {
             protobufLogQuery(t_protobufServer, luaconfsLocal->protobufMaskV4, luaconfsLocal->protobufMaskV6, dc->d_uuid, dc->d_source, dc->d_destination, dc->d_ednssubnet.source, true, dh->id, conn->qlen, qname, qtype, qclass, dc->d_policyTags, dc->d_requestorId, dc->d_deviceId);
@@ -1834,13 +1836,25 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var)
 #endif
       if(dc->d_mdp.d_header.qr) {
         g_stats.ignoredCount++;
-        g_log<<Logger::Error<<"Ignoring answer from TCP client "<< dc->getRemote() <<" on server socket!"<<endl;
+        if(g_logCommonErrors) {
+          g_log<<Logger::Error<<"Ignoring answer from TCP client "<< dc->getRemote() <<" on server socket!"<<endl;
+        }
         delete dc;
         return;
       }
       if(dc->d_mdp.d_header.opcode) {
         g_stats.ignoredCount++;
-        g_log<<Logger::Error<<"Ignoring non-query opcode from TCP client "<< dc->getRemote() <<" on server socket!"<<endl;
+        if(g_logCommonErrors) {
+          g_log<<Logger::Error<<"Ignoring non-query opcode from TCP client "<< dc->getRemote() <<" on server socket!"<<endl;
+        }
+        delete dc;
+        return;
+      }
+      else if (dh->qdcount == 0) {
+        g_stats.emptyQueriesCount++;
+        if(g_logCommonErrors) {
+          g_log<<Logger::Error<<"Ignoring empty (qdcount == 0) query from "<< dc->getRemote() <<" on server socket!"<<endl;
+        }
         delete dc;
         return;
       }
@@ -2202,6 +2216,12 @@ static void handleNewUDPQuestion(int fd, FDMultiplexer::funcparam_t& var)
             g_log<<Logger::Error<<"Ignoring non-query opcode "<<dh->opcode<<" from "<<fromaddr.toString()<<" on server socket!"<<endl;
           }
         }
+        else if (dh->qdcount == 0) {
+          g_stats.emptyQueriesCount++;
+          if(g_logCommonErrors) {
+            g_log<<Logger::Error<<"Ignoring empty (qdcount == 0) query from "<<fromaddr.toString()<<" on server socket!"<<endl;
+          }
+        }
         else {
           struct timeval tv={0,0};
           HarvestTimestamp(&msgh, &tv);
index b5884a8110b3d19c739a5ddf457a082e3f7e1d2d..ce7dd34bd090cce584c062da1ae9d09d3919e61d 100644 (file)
@@ -109,6 +109,7 @@ static const oid policyResultTruncateOID[] = { RECURSOR_STATS_OID, 90 };
 static const oid policyResultCustomOID[] = { RECURSOR_STATS_OID, 91 };
 static const oid queryPipeFullDropsOID[] = { RECURSOR_STATS_OID, 92 };
 static const oid truncatedDropsOID[] = { RECURSOR_STATS_OID, 93 };
+static const oid emptyQueriesOID[] = { RECURSOR_STATS_OID, 94 };
 
 static std::unordered_map<oid, std::string> s_statsMap;
 
@@ -222,6 +223,7 @@ RecursorSNMPAgent::RecursorSNMPAgent(const std::string& name, const std::string&
   registerCounter64Stat("too-old-drops", tooOldDropsOID, OID_LENGTH(tooOldDropsOID));
   registerCounter64Stat("query-pipe-full-drops", queryPipeFullDropsOID, OID_LENGTH(queryPipeFullDropsOID));
   registerCounter64Stat("truncated-drops", truncatedDropsOID, OID_LENGTH(truncatedDropsOID));
+  registerCounter64Stat("empty-queries", emptyQueriesOID, OID_LENGTH(emptyQueriesOID));
   registerCounter64Stat("answers0-1", answers01OID, OID_LENGTH(answers01OID));
   registerCounter64Stat("answers1-10", answers110OID, OID_LENGTH(answers110OID));
   registerCounter64Stat("answers10-100", answers10100OID, OID_LENGTH(answers10100OID));
index 6ff2a84e015e98016e0e1f9e7dbdd1c6952f23a7..d4b44f5b357ba97e6912305b66245f716b9cdc58 100644 (file)
@@ -941,6 +941,7 @@ void registerAllStats()
   addGetStat("no-packet-error", &g_stats.noPacketError);
   addGetStat("dlg-only-drops", &SyncRes::s_nodelegated);
   addGetStat("ignored-packets", &g_stats.ignoredCount);
+  addGetStat("empty-queries", &g_stats.emptyQueriesCount);
   addGetStat("max-mthread-stack", &g_stats.maxMThreadStackUsage);
   
   addGetStat("negcache-entries", boost::bind(getNegCacheSize));
index 35d933ea29e9b711201aec2113331dc478273e10..143d10d31e1389f35d8743d462e515b332996e63 100644 (file)
@@ -774,6 +774,14 @@ truncatedDrops OBJECT-TYPE
         "Number of queries dropped because they were larger than 512 bytes"
     ::= { stats 93 }
 
+emptyQueries OBJECT-TYPE
+    SYNTAX Counter64
+    MAX-ACCESS read-only
+    STATUS current
+    DESCRIPTION
+        "Number of queries dropped because they had a QD count of 0"
+    ::= { stats 94 }
+
 ---
 --- Traps / Notifications
 ---
index 4ee63b45c7fe71731d91dd71544246155db6fd7c..6bd2e45ab942d770a676206cfb4c1cc3e8c37634 100644 (file)
@@ -432,6 +432,12 @@ truncated-drops
 
 questions dropped because they were larger than 512 bytes
 
+empty-queries
+^^^^^^^^^^^^^
+.. versionadded:: 4.2
+
+questions dropped because they had a QD count of 0
+
 unauthorized-tcp
 ^^^^^^^^^^^^^^^^
 number of TCP questions denied because of   allow-from restrictions
index 6310c5bea1e67d6174bfa68d2763908fb68b49af..053142f5b19de25e26373cd1eaf286434e8b9305 100644 (file)
@@ -930,6 +930,7 @@ struct RecursorStats
   std::atomic<uint64_t> packetCacheHits;
   std::atomic<uint64_t> noPacketError;
   std::atomic<uint64_t> ignoredCount;
+  std::atomic<uint64_t> emptyQueriesCount;
   time_t startupTime;
   std::atomic<uint64_t> dnssecQueries;
   unsigned int maxMThreadStackUsage;