]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix stats handling for TCP queries. 2984/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 2 Dec 2015 16:42:01 +0000 (17:42 +0100)
committerRemi Gacogne <rgacogne-github@coredump.fr>
Wed, 2 Dec 2015 21:50:04 +0000 (22:50 +0100)
The previous commit tried to fix the fact that TCP queries were
not correctly accounted, but did not properly handle the fact that
several queries can be sent over a single connection.
Responses were not properly handled either.

pdns/dnsdist-tcp.cc

index a7ecd212476b6d06360935b1dccae91c6ed61d7e..48710c710c71ebbd2b3663c8f65532c8fb5818de 100644 (file)
@@ -57,6 +57,7 @@ struct ConnectionInfo
 {
   int fd;
   ComboAddress remote;
+  ClientState* cs;
 };
 
 void* tcpClientThread(int pipefd);
@@ -170,6 +171,11 @@ void* tcpClientThread(int pipefd)
          g_rings.queryRing.push_back({now,ci.remote,qname,qtype});
        }
 
+       g_stats.queries++;
+       if (ci.cs) {
+         ci.cs->queries++;
+       }
+
        if(localDynBlockNMG->match(ci.remote)) {
          vinfolog("Query from %s dropped because of dynamic block", ci.remote.toStringWithPort());
          g_stats.dynBlocked++;
@@ -227,6 +233,8 @@ void* tcpClientThread(int pipefd)
        if(dh->qr) { // something turned it into a response
          if (putNonBlockingMsgLen(ci.fd, qlen, g_tcpSendTimeout))
            writen2WithTimeout(ci.fd, query, rlen, g_tcpSendTimeout);
+
+         g_stats.selfAnswered++;
          goto drop;
        }
 
@@ -305,6 +313,8 @@ void* tcpClientThread(int pipefd)
 
         if (putNonBlockingMsgLen(ci.fd, rlen, ds->tcpSendTimeout))
           writen2WithTimeout(ci.fd, answerbuffer, rlen, ds->tcpSendTimeout);
+
+        g_stats.responses++;
       }
     }
     catch(...){}
@@ -339,12 +349,10 @@ void* tcpAcceptorThread(void* p)
     try {
       ci=0;
       ci = new ConnectionInfo;
+      ci->cs = cs;
       ci->fd = -1;
       ci->fd = SAccept(cs->tcpFD, remote);
 
-      g_stats.queries++;
-      cs->queries++;
-      
       if(!acl->match(remote)) {
        g_stats.aclDrops++;
        close(ci->fd);