From 7211d47b451bd3f6b984a9d75051b4275836a5af Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 10 Jan 2019 22:41:47 +0100 Subject: [PATCH] add -f,--filter-name option to dnsscope to limit processing to queries within a certain domain --- docs/manpages/dnsscope.1.rst | 1 + pdns/dnsscope.cc | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/manpages/dnsscope.1.rst b/docs/manpages/dnsscope.1.rst index 921d8585f..3945d9ebb 100644 --- a/docs/manpages/dnsscope.1.rst +++ b/docs/manpages/dnsscope.1.rst @@ -23,6 +23,7 @@ INFILE flag set. By default, we process all DNS packets in *INFILE*. --ipv4= Process IPv4 packets. On by default, disable with **--ipv4 false**. --ipv6= Process IPv6 packets. On by default, disable with **--ipv6 false**. +-f, --filter-name= Only process packets within this domain --full-histogram Write out histogram with specified bin-size to 'full-histogram' --log-histogram Write out a log-histogram of response times to 'log-histogram' --no-servfail-stats Remove servfail responses from latency statistics diff --git a/pdns/dnsscope.cc b/pdns/dnsscope.cc index 82a36acad..841a0bf45 100644 --- a/pdns/dnsscope.cc +++ b/pdns/dnsscope.cc @@ -144,6 +144,7 @@ try ("log-histogram", "Write a log-histogram to file 'log-histogram'") ("full-histogram", po::value(), "Write a log-histogram to file 'full-histogram' with this millisecond bin size") #endif + ("filter-name,f", po::value(), "Do statistics only for queries within this domain") ("load-stats,l", po::value()->default_value(""), "if set, emit per-second load statistics (questions, answers, outstanding)") ("no-servfail-stats", "Don't include servfails in response time stats") ("servfail-tree", "Figure out subtrees that generate servfails") @@ -177,6 +178,11 @@ try exit(0); } + DNSName filtername; + if(g_vm.count("filter-name")) + filtername = DNSName(g_vm["filter-name"].as()); + uint32_t nameMismatch = 0; + StatNode root; bool verbose = g_vm.count("verbose"); @@ -245,7 +251,12 @@ try rdFilterMismatch++; continue; } - + + if(!filtername.empty() && !qname.isPartOf(filtername)) { + nameMismatch++; + continue; + } + if(!header.qr) { uint16_t udpsize, z; if(getEDNSUDPPayloadSizeAndZ((const char*)pr.d_payload, pr.d_len, &udpsize, &z)) { @@ -390,6 +401,8 @@ try cout<