From: Remi Gacogne Date: Thu, 10 Mar 2016 14:08:58 +0000 (+0100) Subject: dnsdist: Don't crash when calling cache functions with nil on the console X-Git-Tag: dnsdist-1.0.0-beta1~130^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F3539%2Fhead;p=thirdparty%2Fpdns.git dnsdist: Don't crash when calling cache functions with nil on the console Fix some minor issues in the README. --- diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index 6a9d4a03db..206b6f5729 100644 --- a/pdns/README-dnsdist.md +++ b/pdns/README-dnsdist.md @@ -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 diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index 6bd10be2c4..f5f30d3d7b 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -527,11 +527,15 @@ void moreLua(bool client) }); g_lua.registerFunction::*)(std::shared_ptr)>("setCache", [](std::shared_ptr pool, std::shared_ptr cache) { - pool->packetCache = cache; + if (pool) { + pool->packetCache = cache; + } }); g_lua.registerFunction("getCache", &ServerPool::getCache); g_lua.registerFunction::*)()>("unsetCache", [](std::shared_ptr pool) { - pool->packetCache = nullptr; + if (pool) { + pool->packetCache = nullptr; + } }); g_lua.writeFunction("newPacketCache", [client](size_t maxEntries, boost::optional maxTTL, boost::optional minTTL, boost::optional servFailTTL, boost::optional staleTTL) { @@ -542,15 +546,19 @@ void moreLua(bool client) g_lua.registerFunction("purgeExpired", &DNSDistPacketCache::purgeExpired); g_lua.registerFunction("expunge", &DNSDistPacketCache::expunge); g_lua.registerFunction::*)(const DNSName& dname, boost::optional qtype)>("expungeByName", [](std::shared_ptr cache, const DNSName& dname, boost::optional qtype) { - cache->expungeByName(dname, qtype ? *qtype : QType::ANY); + if (cache) { + cache->expungeByName(dname, qtype ? *qtype : QType::ANY); + } }); g_lua.registerFunction::*)()>("printStats", [](const std::shared_ptr 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) {