]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
make the more dumping optional
authorphonedph1 <ph1@slurpee3>
Thu, 19 Sep 2024 02:12:08 +0000 (20:12 -0600)
committerphonedph1 <ph1@slurpee3>
Thu, 19 Sep 2024 02:12:08 +0000 (20:12 -0600)
pdns/dnsdistdist/dnsdist-cache.cc
pdns/dnsdistdist/dnsdist-cache.hh
pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc
pdns/dnsdistdist/docs/reference/config.rst

index 5ce24c28d4ec68d095e7d4ef0c076c8039705300..8baf99b410993a247629ae8c7afe9e30bb715d83 100644 (file)
@@ -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<int64_t>(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<int64_t>(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<int64_t>(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<int64_t>(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());
index b26fb5f666f3f55118626e2458fbd15c12411c63..241cf98f402f2805788b6e9a1bfd97f3bb7a612b 100644 (file)
@@ -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<DNSName> getDomainsContainingRecords(const ComboAddress& addr);
index 65470b2b870df40924927609a35972fdbd962522..30a09d6c4c24d6387425066ad32f6863dda99217 100644 (file)
@@ -202,7 +202,7 @@ void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client)
       return results;
     });
 
-  luaCtx.registerFunction<void(std::shared_ptr<DNSDistPacketCache>::*)(const std::string& fname)const>("dump", [](const std::shared_ptr<DNSDistPacketCache>& cache, const std::string& fname) {
+  luaCtx.registerFunction<void(std::shared_ptr<DNSDistPacketCache>::*)(const std::string& fname, boost::optional<bool> rawResponse)const>("dump", [](const std::shared_ptr<DNSDistPacketCache>& cache, const std::string& fname, boost::optional<bool> 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);
index 94d3de533da613b39110796539f9ad89bf8be295..f32e06405e5395daedf6a0f889234fae9b07d5c9 100644 (file)
@@ -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)