From: phonedph1 Date: Thu, 19 Sep 2024 02:12:08 +0000 (-0600) Subject: make the more dumping optional X-Git-Tag: rec-5.2.0-alpha1~24^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7178635c3788c5cfb0b964f2185b81c26576c779;p=thirdparty%2Fpdns.git make the more dumping optional --- diff --git a/pdns/dnsdistdist/dnsdist-cache.cc b/pdns/dnsdistdist/dnsdist-cache.cc index 5ce24c28d4..8baf99b410 100644 --- a/pdns/dnsdistdist/dnsdist-cache.cc +++ b/pdns/dnsdistdist/dnsdist-cache.cc @@ -482,7 +482,7 @@ uint64_t DNSDistPacketCache::getEntriesCount() return getSize(); } -uint64_t DNSDistPacketCache::dump(int fileDesc) +uint64_t DNSDistPacketCache::dump(int fileDesc, bool rawResponse) { auto filePtr = pdns::UniqueFilePtr(fdopen(dup(fileDesc), "w")); if (filePtr == nullptr) { @@ -508,8 +508,13 @@ uint64_t DNSDistPacketCache::dump(int fileDesc) rcode = dnsHeader.rcode; } - std::string rawResponse = Base64Encode(value.value); - fprintf(filePtr.get(), "%s %" PRId64 " %s %s ; ecs %s, rcode %" PRIu8 ", key %" PRIu32 ", length %" PRIu16 ", received over UDP %d, added %" PRId64 ", dnssecOK %d, raw query flags %" PRIu16 ", base64response %s\n", value.qname.toString().c_str(), static_cast(value.validity - now), QClass(value.qclass).toString().c_str(), QType(value.qtype).toString().c_str(), value.subnet ? value.subnet.get().toString().c_str() : "empty", rcode, entry.first, value.len, value.receivedOverUDP ? 1 : 0, static_cast(value.added), value.dnssecOK ? 1 : 0, value.queryFlags, rawResponse.c_str()); + fprintf(filePtr.get(), "%s %" PRId64 " %s %s ; ecs %s, rcode %" PRIu8 ", key %" PRIu32 ", length %" PRIu16 ", received over UDP %d, added %" PRId64 ", dnssecOK %d, raw query flags %" PRIu16, value.qname.toString().c_str(), static_cast(value.validity - now), QClass(value.qclass).toString().c_str(), QType(value.qtype).toString().c_str(), value.subnet ? value.subnet.get().toString().c_str() : "empty", rcode, entry.first, value.len, value.receivedOverUDP ? 1 : 0, static_cast(value.added), value.dnssecOK ? 1 : 0, value.queryFlags); + + if (rawResponse) { + std::string rawDataResponse = Base64Encode(value.value); + fprintf(filePtr.get(), ", base64response %s", rawDataResponse.c_str()); + } + fprintf(filePtr.get(), "\n"); } catch (...) { fprintf(filePtr.get(), "; error printing '%s'\n", value.qname.empty() ? "EMPTY" : value.qname.toString().c_str()); diff --git a/pdns/dnsdistdist/dnsdist-cache.hh b/pdns/dnsdistdist/dnsdist-cache.hh index b26fb5f666..241cf98f40 100644 --- a/pdns/dnsdistdist/dnsdist-cache.hh +++ b/pdns/dnsdistdist/dnsdist-cache.hh @@ -55,7 +55,7 @@ public: uint64_t getTTLTooShorts() const { return d_ttlTooShorts.load(); } uint64_t getCleanupCount() const { return d_cleanupCount.load(); } uint64_t getEntriesCount(); - uint64_t dump(int fileDesc); + uint64_t dump(int fileDesc, bool fullResponse = false); /* get the list of domains (qnames) that contains the given address in an A or AAAA record */ std::set getDomainsContainingRecords(const ComboAddress& addr); diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc index 65470b2b87..30a09d6c4c 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc @@ -202,7 +202,7 @@ void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client) return results; }); - luaCtx.registerFunction::*)(const std::string& fname)const>("dump", [](const std::shared_ptr& cache, const std::string& fname) { + luaCtx.registerFunction::*)(const std::string& fname, boost::optional rawResponse)const>("dump", [](const std::shared_ptr& cache, const std::string& fname, boost::optional rawResponse) { if (cache) { int fd = open(fname.c_str(), O_CREAT | O_EXCL | O_WRONLY, 0660); @@ -213,7 +213,7 @@ void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client) uint64_t records = 0; try { - records = cache->dump(fd); + records = cache->dump(fd, rawResponse? *rawResponse : false); } catch (const std::exception& e) { close(fd); diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 94d3de533d..f32e06405e 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -1004,11 +1004,15 @@ See :doc:`../guides/cache` for a how to. Represents a cache that can be part of :class:`ServerPool`. - .. method:: PacketCache:dump(fname) + .. method:: PacketCache:dump(fname [, rawResponse=false]) + + .. versionchanged:: 2.0.0 + ``rawResponse`` added Dump a summary of the cache entries to a file. :param str fname: The path to a file where the cache summary should be dumped. Note that if the target file already exists, it will not be overwritten. + :param bool rawResponse: Dump the raw packet response encoded with base64. .. method:: PacketCache:expunge(n)