From: phonedph1 Date: Tue, 16 Oct 2018 02:07:50 +0000 (+0000) Subject: Do the edns dumping harder. X-Git-Tag: dnsdist-1.3.3~38^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F7068%2Fhead;p=thirdparty%2Fpdns.git Do the edns dumping harder. --- diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 9aeb935194..bf8edd8220 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -189,6 +189,11 @@ static uint64_t* pleaseDump(int fd) return new uint64_t(t_RC->doDump(fd) + dumpNegCache(SyncRes::t_sstorage.negcache, fd) + t_packetCache->doDump(fd)); } +static uint64_t* pleaseDumpEDNSMap(int fd) +{ + return new uint64_t(SyncRes::doEDNSDump(fd)); +} + static uint64_t* pleaseDumpNSSpeeds(int fd) { return new uint64_t(SyncRes::doDumpNSSpeeds(fd)); @@ -264,10 +269,14 @@ string doDumpEDNSStatus(T begin, T end) int fd=open(fname.c_str(), O_CREAT | O_EXCL | O_WRONLY, 0660); if(fd < 0) return "Error opening dump file for writing: "+string(strerror(errno))+"\n"; + uint64_t total = 0; + try { + total = broadcastAccFunction(boost::bind(pleaseDumpEDNSMap, fd)); + } + catch(...){} - SyncRes::doEDNSDumpAndClose(fd); - - return "done\n"; + close(fd); + return "dumped "+std::to_string(total)+" records\n"; } template diff --git a/pdns/syncres.cc b/pdns/syncres.cc index ec3cf531bc..b37a02480f 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -350,18 +350,21 @@ bool SyncRes::doOOBResolve(const DNSName &qname, const QType &qtype, vectorsecond, qname, qtype, ret, res); } -void SyncRes::doEDNSDumpAndClose(int fd) +uint64_t SyncRes::doEDNSDump(int fd) { - FILE* fp=fdopen(fd, "w"); + FILE* fp=fdopen(dup(fd), "w"); if (!fp) { - return; + return 0; } - fprintf(fp,"IP Address\tMode\tMode last updated at\n"); + uint64_t count = 0; + + fprintf(fp,"; edns from thread follows\n;\n"); for(const auto& eds : t_sstorage.ednsstatus) { + count++; fprintf(fp, "%s\t%d\t%s", eds.first.toString().c_str(), (int)eds.second.mode, ctime(&eds.second.modeSetAt)); } - fclose(fp); + return count; } uint64_t SyncRes::doDumpNSSpeeds(int fd) diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 0037fd2b97..6bc8bb752d 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -399,7 +399,7 @@ public: { s_lm = lm; } - static void doEDNSDumpAndClose(int fd); + static uint64_t doEDNSDump(int fd); static uint64_t doDumpNSSpeeds(int fd); static uint64_t doDumpThrottleMap(int fd); static int getRootNS(struct timeval now, asyncresolve_t asyncCallback);