]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Don't crash when calling cache functions with nil on the console 3539/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 10 Mar 2016 14:08:58 +0000 (15:08 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 10 Mar 2016 14:08:58 +0000 (15:08 +0100)
Fix some minor issues in the README.

pdns/README-dnsdist.md
pdns/dnsdist-lua2.cc

index 6a9d4a03dbb8aa231e27b31402a27077b330a383..206b6f5729196338cc9fe7008ac4dfddcb3bf9fb 100644 (file)
@@ -209,16 +209,16 @@ it to your configuration file.
 > showACL()
 192.0.2.0/24
 > delta()
-# Wed Dec 23 2015 15:15:35 CET
+-- Wed Dec 23 2015 15:15:35 CET
 setACL("192.0.2.0/24")
 > addACL("127.0.0.1/8")
 > showACL()
 192.0.2.0/24
 127.0.0.1/8
 > delta()
-# Wed Dec 23 2015 15:15:35 CET
+-- Wed Dec 23 2015 15:15:35 CET
 setACL("192.0.2.0/24")
-# Wed Dec 23 2015 15:15:44 CET
+-- Wed Dec 23 2015 15:15:44 CET
 addACL("127.0.0.1/8")
 >
 ```
@@ -495,6 +495,7 @@ This is still much in flux, but for now, try:
  * `grepq(Netmask|DNS Name|100ms [, n])`: shows the last n queries and responses matching the specified client address or range (Netmask), or the specified DNS Name, or slower than 100ms
  * `grepq({"::1", "powerdns.com", "100ms"} [, n])`: shows the last n queries and responses matching the specified client address AND range (Netmask) AND the specified DNS Name AND slower than 100ms
  * `topBandwidth(top)`: show top-`top` clients that consume the most bandwidth over length of ringbuffer
+ * `topClients(n)`: show top-`n` clients sending the most queries over length of ringbuffer
  * `topQueries(20)`: shows the top-20 queries
  * `topQueries(20,2)`: shows the top-20 two-level domain queries (so `topQueries(20,1)` only shows TLDs)
  * `topResponses(20, 2)`: top-20 servfail responses (use ,3 for NXDOMAIN)
@@ -782,7 +783,7 @@ First, a few words about `dnsdist` architecture:
  if any, and is responsible for cleaning the cache
  * A health check thread checks the backends availability
  * A control thread handles console connections
- * A carbon thread exports statistics to a carbon server if needed
+ * A carbon thread exports statistics to carbon servers if needed
  * One or more webserver threads handle queries to the internal webserver
 
 The maximum number of threads in the TCP pool is controlled by the
@@ -953,6 +954,7 @@ Here are all functions:
     * `topResponses(n, kind[, labels])`: show top 'n' responses with RCODE=kind (0=NO Error, 2=ServFail, 3=ServFail), as grouped when optionally cut down to 'labels' labels
     * `topSlow([top][, limit][, labels])`: show `top` queries slower than `limit` milliseconds, grouped by last `labels` labels   
     * `topBandwidth(top)`: show top-`top` clients that consume the most bandwidth over length of ringbuffer
+    * `topClients(n)`: show top-`n` clients sending the most queries over length of ringbuffer
     * `showResponseLatency()`: show a plot of the response time latency distribution
  * Logging related
     * `infolog(string)`: log at level info
index 6bd10be2c4e89d5d7c22e9186353ab80215834ca..f5f30d3d7bb032b39aa1de7ad94601723e690a64 100644 (file)
@@ -527,11 +527,15 @@ void moreLua(bool client)
     });
 
     g_lua.registerFunction<void(std::shared_ptr<ServerPool>::*)(std::shared_ptr<DNSDistPacketCache>)>("setCache", [](std::shared_ptr<ServerPool> pool, std::shared_ptr<DNSDistPacketCache> cache) {
-        pool->packetCache = cache;
+        if (pool) {
+          pool->packetCache = cache;
+        }
     });
     g_lua.registerFunction("getCache", &ServerPool::getCache);
     g_lua.registerFunction<void(std::shared_ptr<ServerPool>::*)()>("unsetCache", [](std::shared_ptr<ServerPool> pool) {
-        pool->packetCache = nullptr;
+        if (pool) {
+          pool->packetCache = nullptr;
+        }
     });
 
     g_lua.writeFunction("newPacketCache", [client](size_t maxEntries, boost::optional<uint32_t> maxTTL, boost::optional<uint32_t> minTTL, boost::optional<uint32_t> servFailTTL, boost::optional<uint32_t> staleTTL) {
@@ -542,15 +546,19 @@ void moreLua(bool client)
     g_lua.registerFunction("purgeExpired", &DNSDistPacketCache::purgeExpired);
     g_lua.registerFunction("expunge", &DNSDistPacketCache::expunge);
     g_lua.registerFunction<void(std::shared_ptr<DNSDistPacketCache>::*)(const DNSName& dname, boost::optional<uint16_t> qtype)>("expungeByName", [](std::shared_ptr<DNSDistPacketCache> cache, const DNSName& dname, boost::optional<uint16_t> qtype) {
-        cache->expungeByName(dname, qtype ? *qtype : QType::ANY);
+        if (cache) {
+          cache->expungeByName(dname, qtype ? *qtype : QType::ANY);
+        }
       });
     g_lua.registerFunction<void(std::shared_ptr<DNSDistPacketCache>::*)()>("printStats", [](const std::shared_ptr<DNSDistPacketCache> cache) {
-        g_outputBuffer="Hits: " + std::to_string(cache->getHits()) + "\n";
-        g_outputBuffer+="Misses: " + std::to_string(cache->getMisses()) + "\n";
-        g_outputBuffer+="Deferred inserts: " + std::to_string(cache->getDeferredInserts()) + "\n";
-        g_outputBuffer+="Deferred lookups: " + std::to_string(cache->getDeferredLookups()) + "\n";
-        g_outputBuffer+="Lookup Collisions: " + std::to_string(cache->getLookupCollisions()) + "\n";
-        g_outputBuffer+="Insert Collisions: " + std::to_string(cache->getInsertCollisions()) + "\n";
+        if (cache) {
+          g_outputBuffer="Hits: " + std::to_string(cache->getHits()) + "\n";
+          g_outputBuffer+="Misses: " + std::to_string(cache->getMisses()) + "\n";
+          g_outputBuffer+="Deferred inserts: " + std::to_string(cache->getDeferredInserts()) + "\n";
+          g_outputBuffer+="Deferred lookups: " + std::to_string(cache->getDeferredLookups()) + "\n";
+          g_outputBuffer+="Lookup Collisions: " + std::to_string(cache->getLookupCollisions()) + "\n";
+          g_outputBuffer+="Insert Collisions: " + std::to_string(cache->getInsertCollisions()) + "\n";
+        }
       });
 
     g_lua.writeFunction("getPool", [client](const string& poolName) {