~ubuntu-branches/ubuntu/utopic/pdns/utopic-updates

« back to all changes in this revision

Viewing changes to pdns/dnsbulktest.cc

  • Committer: Package Import Robot
  • Author(s): Marc Haber, Marc Haber, Evgeni Golov
  • Date: 2012-05-11 23:51:27 UTC
  • mfrom: (1.1.9) (12.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120511235127-v0qjuaplfckcb2cd
Tags: 3.1-1
[ Marc Haber ]
* Imported Upstream version 3.1
  * reduce column size for 'algorithm' to 50. Closes: #662935
  * handle smallcaps RRs. Closes: #656788
* refresh patches
* remove unused patches
* add patch to turn off the traceback handler at run time
* add patch for changeset 2575 (race condition with supermasters)
* fix mysql multiarch build failure, set cflags etc to hardening defaults
* do not run bootstrap a build time, using autotools_dev
* use dh-autoreconf, remove autofoo created files from
  patches/fix-mongodb-backend-patch
* fix dh invocation
* create MySQL databases with engine=innodb instead of type
* set debian/compat to 9
* Standards-Version: 3.9.3 (no changes needed)
* add myself to uploaders, change Vcs-Header to my git. Closes: #672550

[ Evgeni Golov ]
* use system libpolarssl if present, local copy otherwise.
  Closes: #671856, #656861

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <boost/array.hpp>
3
3
#include <boost/accumulators/statistics.hpp>
4
4
#include <boost/accumulators/statistics/p_square_cumulative_distribution.hpp>
 
5
#include <boost/program_options.hpp>
5
6
#include "inflighter.cc"
6
7
#include <deque>
7
8
#include "namespaces.hh"
12
13
#include "dnsrecords.hh"
13
14
 
14
15
using namespace boost::accumulators;
 
16
namespace po = boost::program_options;
15
17
 
 
18
po::variables_map g_vm;
16
19
 
17
20
StatBag S;
18
21
 
 
22
bool g_quiet=false;
 
23
bool g_envoutput=false;
 
24
 
19
25
struct DNSResult
20
26
{
21
27
  vector<ComboAddress> ips;
59
65
    connect(d_socket, (struct sockaddr*)&remote, remote.getSocklen());
60
66
    d_oks = d_errors = d_nodatas = d_nxdomains = d_unknowns = 0;
61
67
    d_receiveds = d_receiveerrors = d_senderrors = 0;
62
 
    for(unsigned int id =0 ; id < numeric_limits<uint16_t>::max(); ++id) 
 
68
    for(unsigned int id =0 ; id < std::numeric_limits<uint16_t>::max(); ++id) 
63
69
      d_idqueue.push_back(id);
64
70
  }
65
71
  
108
114
      // parse packet, set 'id', fill out 'ip' 
109
115
      
110
116
      MOADNSParser mdp(string(buf, len));
111
 
      cout<<"Reply to question for qname='"<<mdp.d_qname<<"', qtype="<<DNSRecordContent::NumberToType(mdp.d_qtype)<<endl;
112
 
      cout<<"Rcode: "<<mdp.d_header.rcode<<", RD: "<<mdp.d_header.rd<<", QR: "<<mdp.d_header.qr;
113
 
      cout<<", TC: "<<mdp.d_header.tc<<", AA: "<<mdp.d_header.aa<<", opcode: "<<mdp.d_header.opcode<<endl;
 
117
      if(!g_quiet) {
 
118
        cout<<"Reply to question for qname='"<<mdp.d_qname<<"', qtype="<<DNSRecordContent::NumberToType(mdp.d_qtype)<<endl;
 
119
        cout<<"Rcode: "<<mdp.d_header.rcode<<", RD: "<<mdp.d_header.rd<<", QR: "<<mdp.d_header.qr;
 
120
        cout<<", TC: "<<mdp.d_header.tc<<", AA: "<<mdp.d_header.aa<<", opcode: "<<mdp.d_header.opcode<<endl;
 
121
      }
114
122
      dr.rcode = mdp.d_header.rcode;
115
123
      for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) {          
116
124
        if(i->first.d_place == 1 && i->first.d_type == QType::A)
118
126
        if(i->first.d_place == 2 && i->first.d_type == QType::SOA) {
119
127
          dr.seenauthsoa = 1;
120
128
        }
121
 
        cout<<i->first.d_place-1<<"\t"<<i->first.d_label<<"\tIN\t"<<DNSRecordContent::NumberToType(i->first.d_type);
122
 
        cout<<"\t"<<i->first.d_ttl<<"\t"<< i->first.d_content->getZoneRepresentation()<<"\n";
 
129
        if(!g_quiet)
 
130
        {
 
131
          cout<<i->first.d_place-1<<"\t"<<i->first.d_label<<"\tIN\t"<<DNSRecordContent::NumberToType(i->first.d_type);
 
132
          cout<<"\t"<<i->first.d_ttl<<"\t"<< i->first.d_content->getZoneRepresentation()<<"\n";
 
133
        }
123
134
      }
124
135
      
125
136
      id = mdp.d_header.id;
140
151
    (*d_acc)(usec/1000.0);
141
152
//    if(usec > 1000000)
142
153
  //    cerr<<"Slow: "<<domain<<" ("<<usec/1000.0<<" msec)\n";
143
 
    cout<<domain<<": ("<<usec/1000.0<<"msec) rcode: "<<dr.rcode;
144
 
    BOOST_FOREACH(const ComboAddress& ca, dr.ips) {
145
 
      cout<<", "<<ca.toString();
 
154
    if(!g_quiet) {
 
155
      cout<<domain<<": ("<<usec/1000.0<<"msec) rcode: "<<dr.rcode;
 
156
      BOOST_FOREACH(const ComboAddress& ca, dr.ips) {
 
157
        cout<<", "<<ca.toString();
 
158
      }
 
159
      cout<<endl;
146
160
    }
147
 
    cout<<endl;
148
161
    if(dr.rcode == RCode::NXDomain) {
149
162
      d_nxdomains++;
150
163
    }
156
169
    else if(!dr.ips.empty())
157
170
      d_oks++;
158
171
    else {
159
 
      cout<<"UNKNOWN!! ^^"<<endl;
 
172
      if(!g_quiet) cout<<"UNKNOWN!! ^^"<<endl;
160
173
      d_unknowns++;
161
174
    }
162
175
  }
166
179
  
167
180
};
168
181
 
169
 
 
170
182
int main(int argc, char** argv)
171
183
{
172
 
  if(argc != 3 && argc != 4) {
173
 
    cerr<<"Syntax: dnsbulktest ip-address port number [limit] < top-1m.csv"<<endl;
174
 
    exit(1);
175
 
  }
176
 
  SendReceive sr(argv[1], atoi(argv[2]));
177
 
  unsigned int limit = 0;
178
 
  if(argc==4)
179
 
    limit = atoi(argv[3]);
 
184
  po::options_description desc("Allowed options");
 
185
  desc.add_options()
 
186
    ("help,h", "produce help message")
 
187
    ("quiet,q", "be quiet about individual queries")
 
188
    ("envoutput,e", "write report in shell environment format")
 
189
  ;
 
190
 
 
191
  po::options_description alloptions;
 
192
  po::options_description hidden("hidden options");
 
193
  hidden.add_options()
 
194
    ("ip-address", po::value<string>(), "ip-address")
 
195
    ("portnumber", po::value<uint16_t>(), "portnumber")
 
196
    ("limit", po::value<uint32_t>()->default_value(0), "limit");
 
197
 
 
198
  alloptions.add(desc).add(hidden);
 
199
  po::positional_options_description p;
 
200
  p.add("ip-address", 1);
 
201
  p.add("portnumber", 1);
 
202
  p.add("limit", 1);
 
203
 
 
204
  po::store(po::command_line_parser(argc, argv).options(alloptions).positional(p).run(), g_vm);
 
205
  po::notify(g_vm);
 
206
 
 
207
  if (g_vm.count("help")) {
 
208
    cerr << "Usage: dnsbulktest [--options] ip-address portnumber [limit]"<<endl;
 
209
    cerr << desc << "\n";
 
210
    return EXIT_SUCCESS;
 
211
  }
 
212
  
 
213
  if(!g_vm.count("portnumber")) {
 
214
    cerr<<"Fatal, need to specify ip-address and portnumber"<<endl;
 
215
    cerr << "Usage: dnsbulktest [--options] ip-address portnumber [limit]"<<endl;
 
216
    cerr << desc << "\n";
 
217
    return EXIT_FAILURE;
 
218
  }
 
219
 
 
220
  g_quiet = g_vm.count("quiet")>0;
 
221
  g_envoutput = g_vm.count("envoutput")>0;
 
222
 
 
223
  SendReceive sr(g_vm["ip-address"].as<string>(), g_vm["portnumber"].as<uint16_t>());
 
224
  unsigned int limit = g_vm["limit"].as<unsigned int>();
180
225
    
181
226
  reportAllTypes();
182
227
  vector<string> domains;
187
232
  string line;
188
233
  
189
234
  pair<string, string> split;
 
235
  string::size_type pos;
190
236
  while(stringfgets(stdin, line)) {
191
237
    if(limit && domains.size() >= limit)
192
238
      break;
193
239
      
194
240
    trim_right(line);
195
241
    split=splitField(line,',');
 
242
    pos=split.second.find('/');
 
243
    if(pos != string::npos) // alexa has whole urls in the list now..
 
244
      split.second.resize(pos);
 
245
    if(find_if(split.second.begin(), split.second.end(), isalpha) == split.second.end())
 
246
    {
 
247
      continue; // this was an IP address
 
248
    }
196
249
    domains.push_back(split.second);
197
250
    domains.push_back("www."+split.second);
198
251
  }
239
292
        cerr << statfmt % extended_p_square(*sr.d_acc)[i] % (100*sr.d_probs[i]);
240
293
    }
241
294
 
242
 
 
243
 
 
 
295
  if(g_envoutput) {
 
296
    cout<<"DBT_QUEUED="<<domains.size()<<endl;
 
297
    cout<<"DBT_SENDERRORS="<<sr.d_senderrors<<endl;
 
298
    cout<<"DBT_RECEIVED="<<sr.d_receiveds<<endl;
 
299
    cout<<"DBT_TIMEOUTS="<<inflighter.getTimeouts()<<endl;
 
300
    cout<<"DBT_UNEXPECTEDS="<<inflighter.getUnexpecteds()<<endl;
 
301
    cout<<"DBT_OKPERCENTAGE="<<((float)sr.d_oks/domains.size()*100)<<endl;
 
302
    cout<<"DBT_OKPERCENTAGEINT="<<(int)((float)sr.d_oks/domains.size()*100)<<endl;
 
303
  }
244
304
}
245
 
 
246