From f3c9f421e88eb458e2a95c37ef50db9970473ef6 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 4 Jul 2019 13:41:01 +0200 Subject: [PATCH] dnsdist: Display non-zero opcodes in grepq() --- pdns/dns.cc | 10 ++++++++++ pdns/dns.hh | 1 + pdns/dnsdist-lua-inspection.cc | 8 ++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pdns/dns.cc b/pdns/dns.cc index 5d4073564..420db9247 100644 --- a/pdns/dns.cc +++ b/pdns/dns.cc @@ -69,6 +69,16 @@ std::string ERCode::to_s(uint8_t rcode) { return RCode::rcodes_s[rcode]; } +std::string Opcode::to_s(uint8_t opcode) { + static std::vector s_opcodes = { "Query", "IQuery", "Status", "3", "Notify", "Update" }; + + if (opcode >= s_opcodes.size()) { + return std::to_string(opcode); + } + + return s_opcodes.at(opcode); +} + class BoundsCheckingPointer { public: diff --git a/pdns/dns.hh b/pdns/dns.hh index 53554ee50..adc8536db 100644 --- a/pdns/dns.hh +++ b/pdns/dns.hh @@ -71,6 +71,7 @@ class Opcode { public: enum { Query=0, IQuery=1, Status=2, Notify=4, Update=5 }; + static std::string to_s(uint8_t opcode); }; // enum for policy decisions, used by both auth and recursor. Not all values supported everywhere. diff --git a/pdns/dnsdist-lua-inspection.cc b/pdns/dnsdist-lua-inspection.cc index 25d9a187d..3bed0722e 100644 --- a/pdns/dnsdist-lua-inspection.cc +++ b/pdns/dnsdist-lua-inspection.cc @@ -439,7 +439,7 @@ void setupLuaInspection() std::multimap out; - boost::format fmt("%-7.1f %-47s %-12s %-5d %-25s %-5s %-6.1f %-2s %-2s %-2s %s\n"); + boost::format fmt("%-7.1f %-47s %-12s %-5d %-25s %-5s %-6.1f %-2s %-2s %-2s %-s\n"); g_outputBuffer+= (fmt % "Time" % "Client" % "Server" % "ID" % "Name" % "Type" % "Lat." % "TC" % "RD" % "AA" % "Rcode").str(); if(msec==-1) { @@ -451,7 +451,11 @@ void setupLuaInspection() dnmatch = c.name.isPartOf(*dn); if(nmmatch && dnmatch) { QType qt(c.qtype); - out.insert(make_pair(c.when, (fmt % DiffTime(now, c.when) % c.requestor.toStringWithPort() % "" % htons(c.dh.id) % c.name.toString() % qt.getName() % "" % (c.dh.tc ? "TC" : "") % (c.dh.rd? "RD" : "") % (c.dh.aa? "AA" : "") % "Question").str() )) ; + std::string extra; + if (c.dh.opcode != 0) { + extra = " (" + Opcode::to_s(c.dh.opcode) + ")"; + } + out.insert(make_pair(c.when, (fmt % DiffTime(now, c.when) % c.requestor.toStringWithPort() % "" % htons(c.dh.id) % c.name.toString() % qt.getName() % "" % (c.dh.tc ? "TC" : "") % (c.dh.rd? "RD" : "") % (c.dh.aa? "AA" : "") % ("Question" + extra)).str() )) ; if(limit && *limit==++num) break; -- 2.40.0