]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: fix tcp answer counters 10007/head
authorKees Monshouwer <mind04@monshouwer.org>
Mon, 25 Jan 2021 20:56:09 +0000 (21:56 +0100)
committermind04 <mind04@monshouwer.org>
Mon, 25 Jan 2021 22:26:18 +0000 (23:26 +0100)
pdns/responsestats-auth.cc
pdns/responsestats.hh
pdns/tcpreceiver.cc
pdns/tcpreceiver.hh

index 7562f1de7013ba00a99d16883f1e43a2357ef129..4caae74f42407f15ba3e986443847e3ef1ebbd20 100644 (file)
@@ -7,7 +7,7 @@ extern StatBag S;
  *  Function that creates all the stats
  *  when udpOrTCP is true, it is udp
  */
-void ResponseStats::submitResponse(DNSPacket &p, bool udpOrTCP) {
+void ResponseStats::submitResponse(DNSPacket &p, bool udpOrTCP, bool last) {
   const string& buf=p.getString();
   static AtomicCounter &udpnumanswered=*S.getPointer("udp-answers");
   static AtomicCounter &udpnumanswered4=*S.getPointer("udp4-answers");
@@ -44,15 +44,20 @@ void ResponseStats::submitResponse(DNSPacket &p, bool udpOrTCP) {
       udpbytesanswered6+=buf.length();
     }
   } else { //tcp
-    tcpnumanswered++;
     tcpbytesanswered+=buf.length();
     if(p.d_remote.sin4.sin_family==AF_INET) {
-      tcpnumanswered4++;
       tcpbytesanswered4+=buf.length();
     } else {
-      tcpnumanswered6++;
       tcpbytesanswered6+=buf.length();
     }
+    if(last) {
+     tcpnumanswered++;
+     if(p.d_remote.sin4.sin_family==AF_INET) {
+      tcpnumanswered4++;
+     } else {
+      tcpnumanswered6++;
+     }
+    }
   }
 
   submitResponse(p.qtype.getCode(), buf.length(), p.d.rcode, udpOrTCP);
index ba966ffe3d7ff62759594eb9d3d3c059d0979e4d..d068a1c3d537f8d3ad1992dedb2af4b7afdd7807 100644 (file)
@@ -30,7 +30,7 @@ class ResponseStats
 public:
   ResponseStats();
 
-  void submitResponse(DNSPacket &p, bool udpOrTCP);
+  void submitResponse(DNSPacket &p, bool udpOrTCP, bool last=true);
   void submitResponse(uint16_t qtype, uint16_t respsize, bool udpOrTCP);
   void submitResponse(uint16_t qtype, uint16_t respsize, uint8_t rcode, bool udpOrTCP);
   map<uint16_t, uint64_t> getQTypeResponseCounts();
index f48de0d585c8fa6e34691e5d9a29c552e57e146a..ae78a60fded400a1e036a092cd19b8c84fc55b13 100644 (file)
@@ -168,9 +168,9 @@ static void writenWithTimeout(int fd, const void *buffer, unsigned int n, unsign
   }
 }
 
-void TCPNameserver::sendPacket(std::unique_ptr<DNSPacket>& p, int outsock)
+void TCPNameserver::sendPacket(std::unique_ptr<DNSPacket>& p, int outsock, bool last)
 {
-  g_rs.submitResponse(*p, false);
+  g_rs.submitResponse(*p, false, last);
 
   uint16_t len=htons(p->getString().length());
   string buffer((const char*)&len, 2);
@@ -188,15 +188,6 @@ catch(NetworkError& ae) {
   throw NetworkError("Error reading DNS data from TCP client "+remote.toString()+": "+ae.what());
 }
 
-static void incTCPAnswerCount(const ComboAddress& remote)
-{
-  S.inc("tcp-answers");
-  if(remote.sin4.sin_family == AF_INET6)
-    S.inc("tcp6-answers");
-  else
-    S.inc("tcp4-answers");
-}
-
 static bool maxConnectionDurationReached(unsigned int maxConnectionDuration, time_t start, unsigned int& remainingTime)
 {
   if (maxConnectionDuration) {
@@ -301,14 +292,12 @@ void TCPNameserver::doConnection(int fd)
         break;
       
       if(packet->qtype.getCode()==QType::AXFR) {
-        if(doAXFR(packet->qdomain, packet, fd))
-          incTCPAnswerCount(remote);
+        doAXFR(packet->qdomain, packet, fd);
         continue;
       }
 
       if(packet->qtype.getCode()==QType::IXFR) {
-        if(doIXFR(packet, fd))
-          incTCPAnswerCount(remote);
+        doIXFR(packet, fd);
         continue;
       }
 
@@ -597,7 +586,7 @@ int TCPNameserver::doAXFR(const DNSName &target, std::unique_ptr<DNSPacket>& q,
   if(haveTSIGDetails && !tsigkeyname.empty())
     outpacket->setTSIGDetails(trc, tsigkeyname, tsigsecret, trc.d_mac); // first answer is 'normal'
   
-  sendPacket(outpacket, outsock);
+  sendPacket(outpacket, outsock, false);
   
   trc.d_mac = outpacket->d_trc.d_mac;
   outpacket = getFreshAXFRPacket(q);
@@ -855,7 +844,7 @@ int TCPNameserver::doAXFR(const DNSName &target, std::unique_ptr<DNSPacket>& q,
         if(!outpacket->getRRS().empty()) {
           if(haveTSIGDetails && !tsigkeyname.empty())
             outpacket->setTSIGDetails(trc, tsigkeyname, tsigsecret, trc.d_mac, true);
-          sendPacket(outpacket, outsock);
+          sendPacket(outpacket, outsock, false);
           trc.d_mac=outpacket->d_trc.d_mac;
           outpacket=getFreshAXFRPacket(q);
         }
@@ -908,7 +897,7 @@ int TCPNameserver::doAXFR(const DNSName &target, std::unique_ptr<DNSPacket>& q,
               if(!outpacket->getRRS().empty()) {
                 if(haveTSIGDetails && !tsigkeyname.empty())
                   outpacket->setTSIGDetails(trc, tsigkeyname, tsigsecret, trc.d_mac, true);
-                sendPacket(outpacket, outsock);
+                sendPacket(outpacket, outsock, false);
                 trc.d_mac=outpacket->d_trc.d_mac;
                 outpacket=getFreshAXFRPacket(q);
               }
@@ -942,7 +931,7 @@ int TCPNameserver::doAXFR(const DNSName &target, std::unique_ptr<DNSPacket>& q,
           if(!outpacket->getRRS().empty()) {
             if(haveTSIGDetails && !tsigkeyname.empty())
               outpacket->setTSIGDetails(trc, tsigkeyname, tsigsecret, trc.d_mac, true); 
-            sendPacket(outpacket, outsock);
+            sendPacket(outpacket, outsock, false);
             trc.d_mac=outpacket->d_trc.d_mac;
             outpacket=getFreshAXFRPacket(q);
           }
@@ -963,7 +952,7 @@ int TCPNameserver::doAXFR(const DNSName &target, std::unique_ptr<DNSPacket>& q,
     if(!outpacket->getRRS().empty()) {
       if(haveTSIGDetails && !tsigkeyname.empty())
         outpacket->setTSIGDetails(trc, tsigkeyname, tsigsecret, trc.d_mac, true); // first answer is 'normal'
-      sendPacket(outpacket, outsock);
+      sendPacket(outpacket, outsock, false);
       trc.d_mac=outpacket->d_trc.d_mac;
       outpacket=getFreshAXFRPacket(q);
     }
index 8d538a72371a00b3ba047a636903c0b68a95782b..366921a91e560c9df4a318b497134800756c5285 100644 (file)
@@ -48,7 +48,7 @@ public:
   unsigned int numTCPConnections();
 private:
 
-  static void sendPacket(std::unique_ptr<DNSPacket>& p, int outsock);
+  static void sendPacket(std::unique_ptr<DNSPacket>& p, int outsock, bool last=true);
   static int readLength(int fd, ComboAddress *remote);
   static void getQuestion(int fd, char *mesg, int pktlen, const ComboAddress& remote, unsigned int totalTime);
   static int doAXFR(const DNSName &target, std::unique_ptr<DNSPacket>& q, int outsock);