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) {
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());
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);
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);
uint64_t records = 0;
try {
- records = cache->dump(fd);
+ records = cache->dump(fd, rawResponse? *rawResponse : false);
}
catch (const std::exception& e) {
close(fd);
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)