From: Remi Gacogne Date: Wed, 10 Jan 2018 12:01:28 +0000 (+0100) Subject: Add a --pcap-dns-port option to dnsreplay (thanks hawk!) X-Git-Tag: dnsdist-1.3.0~124^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb07837fdbb8d949e43ed61334cb67c200021ef0;p=pdns Add a --pcap-dns-port option to dnsreplay (thanks hawk!) Allowing to replay queries received/sent from/to another port than 53. --- diff --git a/docs/manpages/dnsreplay.1.rst b/docs/manpages/dnsreplay.1.rst index 76367df92..15f796cb9 100644 --- a/docs/manpages/dnsreplay.1.rst +++ b/docs/manpages/dnsreplay.1.rst @@ -33,6 +33,7 @@ PORT --ecs-mask When EDNS forwarding an IP address, mask out first octet with this value --ecs-stamp Add original IP address as EDNS Client Subnet Option when forwarding to reference server +--pcap-dns-port Look at packets from or to this port in the PCAP. Default is 53. --packet-limit Stop after replaying *NUM* packets. Default for *NUM* is 0, which means no limit. --quiet If *FLAG* is set to 1. dnsreplay will not be very noisy with its diff --git a/pdns/dnsreplay.cc b/pdns/dnsreplay.cc index 4c5f218c9..64868b2d0 100644 --- a/pdns/dnsreplay.cc +++ b/pdns/dnsreplay.cc @@ -553,9 +553,6 @@ Orig 9 21 29 36 47 57 66 72 pruneQids(); } - -bool g_rdSelector; - static void generateOptRR(const std::string& optRData, string& res) { const uint8_t name = 0; @@ -603,12 +600,14 @@ static void addECSOption(char* packet, const size_t& packetSize, uint16_t* len, } } +static bool g_rdSelector; +static uint16_t g_pcapDnsPort; -bool sendPacketFromPR(PcapPacketReader& pr, const ComboAddress& remote, int stamp) +static bool sendPacketFromPR(PcapPacketReader& pr, const ComboAddress& remote, int stamp) { dnsheader* dh=(dnsheader*)pr.d_payload; bool sent=false; - if((ntohs(pr.d_udp->uh_dport)!=53 && ntohs(pr.d_udp->uh_sport)!=53) || dh->rd != g_rdSelector || (unsigned int)pr.d_len <= sizeof(dnsheader)) + if((ntohs(pr.d_udp->uh_dport)!=g_pcapDnsPort && ntohs(pr.d_udp->uh_sport)!=g_pcapDnsPort) || dh->rd != g_rdSelector || (unsigned int)pr.d_len <= sizeof(dnsheader)) return sent; QuestionData qd; @@ -704,6 +703,7 @@ try ("help,h", "produce help message") ("version", "show version number") ("packet-limit", po::value()->default_value(0), "stop after this many packets") + ("pcap-dns-port", po::value()->default_value(53), "look at packets from or to this port in the PCAP (defaults to 53)") ("quiet", po::value()->default_value(true), "don't be too noisy") ("recursive", po::value()->default_value(true), "look at recursion desired packets, or not (defaults true)") ("speedup", po::value()->default_value(1), "replay at this speedup") @@ -750,6 +750,7 @@ try uint32_t packetLimit = g_vm["packet-limit"].as(); g_rdSelector = g_vm["recursive"].as(); + g_pcapDnsPort = g_vm["pcap-dns-port"].as(); g_quiet = g_vm["quiet"].as();