From: bert hubert Date: Tue, 11 Jun 2013 14:01:08 +0000 (+0200) Subject: rename tcpbench to dnstcpbench, add documentation, add command line parsing X-Git-Tag: rec-3.6.0-rc1~682 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=36658df5338b0b15e54072ba4756765368e9479c;p=thirdparty%2Fpdns.git rename tcpbench to dnstcpbench, add documentation, add command line parsing --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 6d50bbd860..2c538a552d 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -39,7 +39,7 @@ sbin_PROGRAMS = pdns_server bin_PROGRAMS = pdns_control pdnssec dnsreplay endif -EXTRA_PROGRAMS=pdns_recursor sdig tcpbench tsig-tests speedtest pdns_control dnsscope dnsgram \ +EXTRA_PROGRAMS=pdns_recursor sdig dnstcpbench tsig-tests speedtest pdns_control dnsscope dnsgram \ testrunner \ toysdig dnsdemog dnswasher dnsscan nproxy notify pdnssec dnsbulktest nsec3dig # dnslabel # tcptorture @@ -142,10 +142,11 @@ sdig_SOURCES=sdig.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh unix_utility.cc \ logger.cc statbag.cc qtype.cc sillyrecords.cc nsecrecords.cc base32.cc -tcpbench_SOURCES=tcpbench.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \ +dnstcpbench_SOURCES=dnstcpbench.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \ misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh unix_utility.cc \ logger.cc statbag.cc qtype.cc sillyrecords.cc nsecrecords.cc base32.cc - +dnstcpbench_LDFLAGS=$(BOOST_PROGRAM_OPTIONS_LDFLAGS) +dnstcpbench_LDADD=$(BOOST_PROGRAM_OPTIONS_LIBS) nsec3dig_SOURCES=nsec3dig.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc \ dnswriter.hh dnssecinfra.cc \ diff --git a/pdns/tcpbench.cc b/pdns/dnstcpbench.cc similarity index 56% rename from pdns/tcpbench.cc rename to pdns/dnstcpbench.cc index 0f4c047dac..ce0f7cd7b5 100644 --- a/pdns/tcpbench.cc +++ b/pdns/dnstcpbench.cc @@ -5,20 +5,24 @@ #include "dnsrecords.hh" #include "statbag.hh" #include -StatBag S; +#include +StatBag S; +namespace po = boost::program_options; +po::variables_map g_vm; +bool g_verbose; bool g_onlyTCP; -AtomicCounter g_networkErrors, g_otherErrors, g_OK, g_truncates; +unsigned int g_timeoutMsec; +AtomicCounter g_networkErrors, g_otherErrors, g_OK, g_truncates, g_authAnswers, g_timeOuts; // echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle - void doQuery(const std::string& qname, uint16_t qtype, const ComboAddress& dest) try { vector packet; DNSPacketWriter pw(packet, qname, qtype); - + int res; string reply; if(!g_onlyTCP) { @@ -26,6 +30,14 @@ try udpsock.sendTo(string((char*)&*packet.begin(), (char*)&*packet.end()), dest); ComboAddress origin; + res = waitForData(udpsock.getHandle(), 0, 1000 * g_timeoutMsec); + if(res < 0) + throw NetworkError("Error waiting for response"); + if(!res) { + g_timeOuts++; + return; + } + udpsock.recvFrom(reply, origin); MOADNSParser mdp(reply); if(!mdp.d_header.tc) @@ -33,19 +45,25 @@ try g_truncates++; } - Socket sock(InterNetwork, Stream); int tmp=1; if(setsockopt(sock.getHandle(),SOL_SOCKET,SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0) throw runtime_error("Unable to set socket reuse: "+string(strerror(errno))); sock.connect(dest); - uint16_t len; - len = htons(packet.size()); - if(sock.write((char *) &len, 2) != 2) - throw AhuException("tcp write failed"); - - sock.writen(string((char*)&*packet.begin(), (char*)&*packet.end())); + uint16_t len = htons(packet.size()); + string tcppacket((char*)& len, 2); + tcppacket.append((char*)&*packet.begin(), (char*)&*packet.end()); + + sock.writen(tcppacket); + + res = waitForData(sock.getHandle(), 0, 1000 * g_timeoutMsec); + if(res < 0) + throw NetworkError("Error waiting for response"); + if(!res) { + g_timeOuts++; + return; + } if(sock.read((char *) &len, 2) != 2) throw AhuException("tcp read failed"); @@ -66,6 +84,8 @@ try MOADNSParser mdp(reply); // cout<<"Had correct TCP/IP response, "<()->default_value(10), "wait for this amount of milliseconds for an answer") + ("workers", po::value()->default_value(100), "number of parallel workers"); + + hidden.add_options() + ("remote-host", po::value(), "remote-host") + ("remote-port", po::value()->default_value(53), "remote-port"); + alloptions.add(desc).add(hidden); + + po::positional_options_description p; + p.add("remote-host", 1); + p.add("remote-port", 1); + + po::store(po::command_line_parser(argc, argv).options(alloptions).positional(p).run(), g_vm); + po::notify(g_vm); + + if(g_vm.count("help")) { + cout << desc<(); + reportAllTypes(); - g_onlyTCP=false; - uint16_t port=53; - if(argc < 2) { + if(g_vm["remote-host"].empty()) { cerr<<"Syntax: tcpbench remote [port] < queries"< 2) - port = atoi(argv[2]); - g_dest = ComboAddress(argv[1], port); - unsigned int numworkers=100; + g_dest = ComboAddress(g_vm["remote-host"].as().c_str(), g_vm["remote-port"].as()); + + unsigned int numworkers=g_vm["workers"].as(); + + if(g_verbose) { + cout<<"Sending queries to: "< + +NAME +---- +dnstcpbench - tool to perform TCP benchmarking of nameservers + +SYNOPSIS +-------- +'dnstcpbench' [--help] [--verbose] [--udp-first, -u] [--workers] [--timeout-msec] remote-ip-address [remote-port] + +DESCRIPTION +----------- +dnstcpbench reads DNS queries from standard input and sends them out in +parallel to a remote nameserver. By default TCP/IP is used, but optionally, +UDP is tried first, which allows for the benchmarking of TCP/IP fallback. + +The input format is one query per line: qname single-space qtype. An +example: + www.powerdns.com ANY + powerdns.com MX + +OPTIONS +------- + +--verbose:: + Be wordy on what the program is doing + +--udp-first, -u:: + Attempt resolution via UDP first, only do TCP if truncated answer is + received + +--workers:: + Number of parallel worker threads to use. + +--timeout-msec:: + Number of milliseconds to wait for an answer + +--help:: + Provide a helpful message + +BUGS +---- +Currently the timeout code does not actually perform non-blocking connects +or writes. So a slow connect or slow writes will still cause low +performance and delays. + +Does not yet support IPv6 testing. + +AUTHOR +------ +Written by PowerDNS.COM BV, bert hubert, + +RESOURCES +--------- +Website: http://www.powerdns.com + +COPYING +------- +Copyright (C) 2013 PowerDNS.COM BV. Free use of this software +is granted under the terms of the GNU General Public License (GPL) version +2. +