Skip to content

Commit 36f6762

Browse files
authored
Merge pull request PowerDNS#17358 from miodvallat/verboseview
auth: some views traces
2 parents 0a9334b + eb65d6b commit 36f6762

9 files changed

Lines changed: 54 additions & 15 deletions

File tree

modules/remotebackend/test-remotebackend.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "test-remotebackend-keys.hh"
4646

4747
bool g_slogStructured{false};
48+
bool g_logDNSQueries{false};
4849

4950
extern std::unique_ptr<DNSBackend> backendUnderTest;
5051

pdns/auth-main.cc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ const char* funnytext = "*******************************************************
105105

106106
bool g_anyToTcp;
107107
bool g_8bitDNS;
108+
bool g_logDNSQueries;
108109
#ifdef HAVE_LUA_RECORDS
109110
bool g_doLuaRecord;
110111
int g_luaRecordExecLimit;
@@ -568,6 +569,7 @@ static void sendout(std::unique_ptr<DNSPacket>& a, Logr::log_t slog, int start)
568569
}
569570

570571
//! The qthread receives questions over the internet via the Nameserver class, and hands them to the Distributor for further processing
572+
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
571573
static void qthread(unsigned int num)
572574
{
573575
std::shared_ptr<Logr::Logger> slog;
@@ -594,7 +596,6 @@ static void qthread(unsigned int num)
594596

595597
int diff{};
596598
int start{};
597-
bool logDNSQueries = ::arg().mustDo("log-dns-queries");
598599
shared_ptr<UDPNameserver> NS; // NOLINT(readability-identifier-length)
599600
std::string buffer;
600601
ComboAddress accountremote;
@@ -652,7 +653,7 @@ static void qthread(unsigned int num)
652653

653654
S.ringAccount("queries", question.qdomain, question.qtype);
654655
S.ringAccount("remotes", question.getInnerRemote());
655-
if (logDNSQueries) {
656+
if (g_logDNSQueries) {
656657
if (g_slogStructured) {
657658
if (question.d_ednsRawPacketSizeLimit > 0 && question.getMaxReplyLen() != (unsigned int)question.d_ednsRawPacketSizeLimit) {
658659
slog->info(Logr::Notice, "Query received", "remote", Logging::Loggable(question.getRemoteString()), "query", Logging::Loggable(question.qdomain), "type", Logging::Loggable(question.qtype), "dnssec", Logging::Loggable(question.d_dnssecOk), "max reply length", Logging::Loggable(question.getMaxReplyLen()), "raw packet size limit", Logging::Loggable(question.d_ednsRawPacketSizeLimit));
@@ -669,17 +670,22 @@ static void qthread(unsigned int num)
669670
}
670671
}
671672

673+
bool logAtNewline{false};
672674
if (PC.enabled() && (question.d.opcode != Opcode::Notify && question.d.opcode != Opcode::Update) && question.couldBeCached()) {
673675
start = diff;
674676
std::string view{};
675677
if (g_views) {
678+
if (!g_slogStructured) {
679+
g_log << endl;
680+
logAtNewline = true; // because of getViewFromNetwork below
681+
}
676682
Netmask netmask(accountremote);
677683
view = g_zoneCache.getViewFromNetwork(&netmask);
678684
}
679685
bool haveSomething = PC.get(question, cached, view); // does the PacketCache recognize this question?
680686
if (haveSomething) {
681-
if (logDNSQueries) {
682-
SLOG(g_log << ": packetcache HIT" << endl,
687+
if (g_logDNSQueries) {
688+
SLOG(g_log << (logAtNewline ? "" : ": ") << "packetcache HIT" << endl,
683689
slog->info(Logr::Notice, "packetcache HIT"));
684690
}
685691
cached.setRemote(&question.d_remote); // inlined
@@ -706,17 +712,17 @@ static void qthread(unsigned int num)
706712
}
707713

708714
if (distributor->isOverloaded()) {
709-
if (logDNSQueries) {
710-
SLOG(g_log << ": Dropped query, backends are overloaded" << endl,
715+
if (g_logDNSQueries) {
716+
SLOG(g_log << (logAtNewline ? "" : ": ") << "Dropped query, backends are overloaded" << endl,
711717
slog->info(Logr::Notice, "Dropped query, backends are overloaded"));
712718
}
713719
overloadDrops++;
714720
continue;
715721
}
716722

717-
if (logDNSQueries) {
723+
if (g_logDNSQueries) {
718724
if (PC.enabled()) {
719-
SLOG(g_log << ": packetcache MISS" << endl,
725+
SLOG(g_log << (logAtNewline ? "" : ": ") << "packetcache MISS" << endl,
720726
slog->info(Logr::Notice, "packetcache MISS"));
721727
}
722728
else {
@@ -772,6 +778,7 @@ static void mainthread()
772778

773779
g_anyToTcp = ::arg().mustDo("any-to-tcp");
774780
g_8bitDNS = ::arg().mustDo("8bit-dns");
781+
g_logDNSQueries = ::arg().mustDo("log-dns-queries");
775782
#ifdef HAVE_LUA_RECORDS
776783
g_doLuaRecord = ::arg().mustDo("enable-lua-records");
777784
g_LuaRecordSharedState = (::arg()["enable-lua-records"] == "shared");
@@ -968,6 +975,7 @@ static void mainthread()
968975
UeberBackend::go();
969976

970977
// Setup the zone cache
978+
g_zoneCache.setSLog(slog);
971979
g_zoneCache.setRefreshInterval(::arg().asNum("zone-cache-refresh-interval"));
972980
try {
973981
UeberBackend B;

pdns/auth-main.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern CommunicatorClass Communicator;
4646
void carbonDumpThread(Logr::log_t slog); // Implemented in auth-carbon.cc. Avoids having an auth-carbon.hh declaring exactly one function.
4747
extern bool g_anyToTcp;
4848
extern bool g_8bitDNS;
49+
extern bool g_logDNSQueries;
4950
extern NetmaskGroup g_proxyProtocolACL;
5051
extern size_t g_proxyProtocolMaximumSize;
5152
#ifdef HAVE_LUA_RECORDS

pdns/auth-zonecache.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "statbag.hh"
3030
#include "arguments.hh"
3131
#include "cachecleaner.hh"
32+
#include "auth-main.hh"
33+
3234
extern StatBag S;
3335

3436
AuthZoneCache::AuthZoneCache(size_t mapsCount) :
@@ -71,6 +73,10 @@ std::string AuthZoneCache::getViewFromNetwork(Netmask* net)
7173
string view{};
7274

7375
if (net == nullptr || net->empty()) {
76+
if (g_logDNSQueries) {
77+
SLOG(g_log << Logger::Notice << "missing or empty netmask, unable to pick a view" << endl,
78+
d_log->info(Logr::Notice, "Missing or empty netmask, unable to pick a view"));
79+
}
7480
return view;
7581
}
7682

@@ -82,12 +88,21 @@ std::string AuthZoneCache::getViewFromNetwork(Netmask* net)
8288
*net = netview->first;
8389
// ...and which view it covers.
8490
view = netview->second;
91+
if (g_logDNSQueries) {
92+
SLOG(g_log << Logger::Notice << "netmask " << net->toString() << " matches view '" << view << "'" << endl,
93+
d_log->info(Logr::Notice, "matching view", "netmask", Logging::Loggable(net), "view", Logging::Loggable(view)));
94+
}
95+
return view;
8596
}
8697
}
8798
catch (...) {
8899
// this handles the "empty" case, but might hide other errors
89100
}
90101

102+
if (g_logDNSQueries) {
103+
SLOG(g_log << Logger::Notice << "no view found matching netmask " << net->toString() << endl,
104+
d_log->info(Logr::Notice, "no view found", "netmask", Logging::Loggable(net)));
105+
}
91106
return view;
92107
}
93108

pdns/auth-zonecache.hh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public:
7878

7979
void clear();
8080

81+
void setSLog(Logr::log_t log)
82+
{
83+
d_log = log;
84+
}
85+
8186
private:
8287
SharedLockGuarded<NetmaskTree<string>> d_nets;
8388
SharedLockGuarded<ViewsMap> d_views;
@@ -121,6 +126,8 @@ private:
121126
bool d_replacePending{false};
122127
};
123128
LockGuarded<PendingData> d_pending;
129+
130+
std::shared_ptr<Logr::Logger> d_log;
124131
};
125132

126133
extern AuthZoneCache g_zoneCache;

pdns/ixfrdist.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ AuthPacketCache PC;
7070
// NOLINTNEXTLINE(readability-identifier-length)
7171
AuthQueryCache QC;
7272
AuthZoneCache g_zoneCache;
73+
bool g_logDNSQueries{false};
7374

7475
ArgvMap &arg()
7576
{

pdns/pdnsutil.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ namespace po = boost::program_options;
6363
po::variables_map g_vm;
6464

6565
bool g_slogStructured{false};
66+
bool g_logDNSQueries{false};
6667
static Logger::Urgency s_logUrgency;
6768

6869
string g_programname="pdns";

pdns/tcpreceiver.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ void TCPNameserver::doConnection(int fd, Logr::log_t slog)
264264

265265
DLOG(SLOG(g_log<<"TCP Connection accepted on fd "<<fd<<endl,
266266
slog->info(Logr::Debug, "TCP Connection accepted", "fd", Logging::Loggable(fd))));
267-
bool logDNSQueries= ::arg().mustDo("log-dns-queries");
268267
if (g_proxyProtocolACL.match(remote)) {
269268
unsigned int remainingTime = 0;
270269
PacketBuffer proxyData;
@@ -398,7 +397,7 @@ void TCPNameserver::doConnection(int fd, Logr::log_t slog)
398397
std::unique_ptr<DNSPacket> reply;
399398
auto cached = make_unique<DNSPacket>(slog, false);
400399
std::shared_ptr<Logr::Logger> slogger;
401-
if(logDNSQueries) {
400+
if(g_logDNSQueries) {
402401
if (g_slogStructured) {
403402
slogger = slog->withValues("remote", Logging::Loggable(packet->getRemoteString()), "query", Logging::Loggable(packet->qdomain), "type", Logging::Loggable(packet->qtype), "dnssecok", Logging::Loggable(packet->d_dnssecOk), "bufsize", Logging::Loggable(packet->getMaxReplyLen()));
404403
}
@@ -408,16 +407,21 @@ void TCPNameserver::doConnection(int fd, Logr::log_t slog)
408407
}
409408
}
410409

410+
bool logAtNewline{false};
411411
if (PC.enabled()) {
412412
if (packet->couldBeCached()) {
413413
std::string view{};
414414
if (g_views) {
415+
if (!g_slogStructured) {
416+
g_log << endl;
417+
logAtNewline = true; // because of getViewFromNetwork below
418+
}
415419
Netmask netmask(packet->getInnerRemote());
416420
view = g_zoneCache.getViewFromNetwork(&netmask);
417421
}
418422
if (PC.get(*packet, *cached, view)) { // short circuit - does the PacketCache recognize this question?
419-
if(logDNSQueries) {
420-
SLOG(g_log<<": packetcache HIT"<<endl,
423+
if(g_logDNSQueries) {
424+
SLOG(g_log << (logAtNewline ? "" : ": ") << "packetcache HIT"<<endl,
421425
slogger->info(Logr::Notice, "Received TCP query", "packetcache", Logging::Loggable("hit")));
422426
}
423427
cached->setRemote(&packet->d_remote);
@@ -430,12 +434,12 @@ void TCPNameserver::doConnection(int fd, Logr::log_t slog)
430434
continue;
431435
}
432436
}
433-
if(logDNSQueries) {
434-
SLOG(g_log<<": packetcache MISS"<<endl,
437+
if(g_logDNSQueries) {
438+
SLOG(g_log<< (logAtNewline ? "" : ": ") << "packetcache MISS"<<endl,
435439
slogger->info(Logr::Notice, "Received TCP query", "packetcache", Logging::Loggable("miss")));
436440
}
437441
} else {
438-
if (logDNSQueries) {
442+
if (g_logDNSQueries) {
439443
SLOG(g_log<<endl,
440444
slogger->info(Logr::Notice, "Received TCP query"));
441445
}

pdns/testrunner.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ AuthQueryCache QC;
1919
AuthZoneCache g_zoneCache;
2020
uint16_t g_maxNSEC3Iterations{0};
2121
bool g_slogStructured{false};
22+
bool g_logDNSQueries{false};
2223

2324
ArgvMap& arg()
2425
{

0 commit comments

Comments
 (0)