]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
unify various rings, make generic query infra NOTE - WE STILL DON'T LOCK THE RINGS...
authorbert hubert <bert.hubert@netherlabs.nl>
Sun, 29 Nov 2015 19:45:42 +0000 (20:45 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Sun, 29 Nov 2015 19:45:42 +0000 (20:45 +0100)
pdns/dnsdist-lua.cc
pdns/dnsdist-lua2.cc
pdns/dnsdist.cc
pdns/dnsdist.hh

index 247728550feb58af0fe7a50038c7e283da86450b..cfbb251d3a7c8327e29f67ca07118e72596105a8 100644 (file)
@@ -652,8 +652,8 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
   g_lua.writeFunction("topClients", [](unsigned int top) {
       map<ComboAddress, int,ComboAddress::addressOnlyLessThan > counts;
       unsigned int total=0;
-      for(const auto& c : g_rings.clientRing) {
-       counts[c]++;
+      for(const auto& c : g_rings.queryRing) {
+       counts[c.requestor]++;
        total++;
       }
       vector<pair<int, ComboAddress>> rcounts;
@@ -680,15 +680,15 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
       unsigned int total=0;
       if(!labels) {
        for(const auto& a : g_rings.queryRing) {
-         counts[a]++;
+         counts[a.name]++;
          total++;
        }
       }
       else {
        unsigned int lab = *labels;
        for(auto a : g_rings.queryRing) {
-         a.trimToLabels(lab);
-         counts[a]++;
+         a.name.trimToLabels(lab);
+         counts[a.name]++;
          total++;
        }
 
index 602dc51403d0d3c9aeba1e31143da2a5b2ecdfe7..78ca29085482bd45429ec6928b032213694de064 100644 (file)
@@ -61,6 +61,26 @@ map<ComboAddress,int> exceedRespGen(int rate, int seconds, std::function<void(co
   return filterScore(counts, mintime, maxtime, rate);
 }
 
+map<ComboAddress,int> exceedQueryGen(int rate, int seconds, std::function<void(counts_t&, const Rings::Query&)> T) 
+{
+  counts_t counts;
+  struct timespec mintime, maxtime, cutoff;
+  clock_gettime(CLOCK_MONOTONIC, &maxtime);
+  mintime=cutoff=maxtime;
+  cutoff.tv_sec -= seconds;
+  
+  for(const auto& c : g_rings.queryRing) {
+    if(seconds && c.when < cutoff)
+      continue;
+
+    T(counts, c);
+    if(c.when < mintime)
+      mintime = c.when;
+  }
+  
+  return filterScore(counts, mintime, maxtime, rate);
+}
+
 
 map<ComboAddress,int> exceedRCode(int rate, int seconds, int rcode) 
 {
@@ -97,7 +117,6 @@ void moreLua()
   g_lua.registerFunction<bool(NetmaskGroup::*)(const ComboAddress&)>("match", 
                                                                     [](NetmaskGroup& s, const ComboAddress& ca) { return s.match(ca); });
 
-
   g_lua.writeFunction("exceedServfails", [](unsigned int rate, int seconds) {
       return exceedRCode(rate, seconds, RCode::ServFail);
     });
@@ -105,9 +124,20 @@ void moreLua()
       return exceedRCode(rate, seconds, RCode::NXDomain);
     });
 
+
+
   g_lua.writeFunction("exceedRespByterate", [](unsigned int rate, int seconds) {
       return exceedRespByterate(rate, seconds);
     });
 
+  g_lua.writeFunction("exceedQTypeRate", [](uint16_t type, unsigned int rate, int seconds) {
+      return exceedQueryGen(rate, seconds, [type](counts_t& counts, const Rings::Query& q) {
+         if(q.qtype==type)
+           counts[q.requestor]++;
+       });
+
+
+    });
+
 
 }
index 07783e7af363be909b5cebd1d2f060badb480628..9c5e03cf7f1ae71e2c1979170541bfba0b95678a 100644 (file)
@@ -429,7 +429,7 @@ try
   for(;;) {
     try {
       len = recvmsg(cs->udpFD, &msgh, 0);
-      g_rings.clientRing.push_back(remote);
+
       if(len < (int)sizeof(struct dnsheader)) {
        g_stats.nonCompliantQueries++;
        continue;
@@ -457,7 +457,9 @@ try
       const uint16_t * flags = getFlagsFromDNSHeader(dh);
       const uint16_t origFlags = *flags;
       DNSName qname(packet, len, 12, false, &qtype);
-      g_rings.queryRing.push_back(qname);
+      struct timespec now;
+      clock_gettime(CLOCK_MONOTONIC, &now);
+      g_rings.queryRing.push_back({now,remote,qname,qtype}); // XXX LOCK?!
             
       if(blockFilter) {
        std::lock_guard<std::mutex> lock(g_luamutex);
index 3634ae4cfef5cb395f1973390e7d15a14b60e361..6e824d6efe371e506d6a02e938579edd229547ff 100644 (file)
@@ -179,12 +179,17 @@ struct IDState
 struct Rings {
   Rings()
   {
-    clientRing.set_capacity(10000);
     queryRing.set_capacity(10000);
     respRing.set_capacity(10000);
   }
-  boost::circular_buffer<ComboAddress> clientRing;
-  boost::circular_buffer<DNSName> queryRing;
+  struct Query
+  {
+    struct timespec when;
+    ComboAddress requestor;
+    DNSName name;
+    uint16_t qtype;
+  };
+  boost::circular_buffer<Query> queryRing;
   struct Response
   {
     struct timespec when;