From d372faa2131f3dc5d17e5cc62df8341c9a1a2ad9 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 16 Nov 2020 12:09:20 +0100 Subject: [PATCH] dnsdist: Add the response code in the packet cache dump --- pdns/Makefile.am | 1 + pdns/dnsdist-cache.cc | 9 ++++++++- pdns/dnsdistdist/Makefile.am | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pdns/Makefile.am b/pdns/Makefile.am index d85f1d7050..2dad7ca4ba 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -1523,6 +1523,7 @@ fuzz_target_proxyprotocol_LDFLAGS = $(fuzz_targets_ldflags) fuzz_target_proxyprotocol_LDADD = $(fuzz_targets_libs) fuzz_target_dnsdistcache_SOURCES = \ + dns.cc dns.hh \ dnsdist-cache.cc dnsdist-cache.hh \ dnsdist-ecs.cc dnsdist-ecs.hh \ dnslabeltext.cc \ diff --git a/pdns/dnsdist-cache.cc b/pdns/dnsdist-cache.cc index 79f12234f2..ddf00bfa94 100644 --- a/pdns/dnsdist-cache.cc +++ b/pdns/dnsdist-cache.cc @@ -474,7 +474,14 @@ uint64_t DNSDistPacketCache::dump(int fd) count++; try { - fprintf(fp.get(), "%s %" PRId64 " %s ; key %" PRIu32 ", length %" PRIu16 ", tcp %d, added %" PRId64 "\n", value.qname.toString().c_str(), static_cast(value.validity - now), QType(value.qtype).getName().c_str(), entry.first, value.len, value.tcp, static_cast(value.added)); + uint8_t rcode = 0; + if (value.len >= sizeof(dnsheader)) { + dnsheader dh; + memcpy(&dh, value.value.data(), sizeof(dnsheader)); + rcode = dh.rcode; + } + + fprintf(fp.get(), "%s %" PRId64 " %s ; rcode %" PRIu8 ", key %" PRIu32 ", length %" PRIu16 ", tcp %d, added %" PRId64 "\n", value.qname.toString().c_str(), static_cast(value.validity - now), QType(value.qtype).getName().c_str(), rcode, entry.first, value.len, value.tcp, static_cast(value.added)); } catch(...) { fprintf(fp.get(), "; error printing '%s'\n", value.qname.empty() ? "EMPTY" : value.qname.toString().c_str()); diff --git a/pdns/dnsdistdist/Makefile.am b/pdns/dnsdistdist/Makefile.am index 1bea3b3330..a5f6c811e8 100644 --- a/pdns/dnsdistdist/Makefile.am +++ b/pdns/dnsdistdist/Makefile.am @@ -210,7 +210,7 @@ testrunner_SOURCES = \ bpf-filter.cc bpf-filter.hh \ cachecleaner.hh \ circular_buffer.hh \ - dns.hh \ + dns.cc dns.hh \ dnscrypt.cc dnscrypt.hh \ dnsdist-backend.cc \ dnsdist-cache.cc dnsdist-cache.hh \ -- 2.47.2