~ubuntu-branches/ubuntu/trusty/pdns/trusty-backports

« back to all changes in this revision

Viewing changes to pdns/dnsscope.cc

  • Committer: Package Import Robot
  • Author(s): Matthijs Möhlmann
  • Date: 2011-11-19 11:58:10 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20111119115810-5u926cmriehkt5j7
Tags: 3.0-1
* New upstream version (Closes: #624330, #626909, #617476, #498918, #500572)
  (Closes: #645539, #623036, #521791, #583161, #590285, #499396)
* Update Standards-Version to 3.9.2
* Add lua backend.
* Use new style dh instead of individual dh_* commands.
* Add Homepage to debian/control (Closes: #634947)
* Add pdnssec and dnsreplay utility.
* Use dbconfig-common to populate / upgrade databases.
* Update patch addconfigdir, do not parse ucf-dist files.
* Update manpage pdns_control and include a list of options (Closes: #621724)
* Add manpage for pdnssec.
* Add prerm scripts to the backends, stop the pdns server.
* Add patch from upstream to properly parse priority. (Closes: #533023)

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
#include <algorithm>
11
11
#include "anadns.hh"
12
12
 
13
 
using namespace boost;
14
 
using namespace std;
 
13
#include "namespaces.hh"
 
14
#include "namespaces.hh"
15
15
 
16
16
StatBag S;
17
17
 
26
26
  int d_qcount;
27
27
  int d_answercount;
28
28
 
29
 
  struct timeval d_firstquestiontime;
 
29
  struct pdns_timeval d_firstquestiontime;
30
30
};
31
31
 
32
32
typedef map<QuestionIdentifier, QuestionData> statmap_t;
58
58
 
59
59
  while(pr.getUDPPacket()) {
60
60
    if((ntohs(pr.d_udp->uh_dport)==5300 || ntohs(pr.d_udp->uh_sport)==5300 ||
61
 
        ntohs(pr.d_udp->uh_dport)==53   || ntohs(pr.d_udp->uh_sport)==53) &&
 
61
        ntohs(pr.d_udp->uh_dport)==53   || ntohs(pr.d_udp->uh_sport)==53) &&
62
62
        pr.d_len > 12) {
63
63
      try {
64
 
        MOADNSParser mdp((const char*)pr.d_payload, pr.d_len);
65
 
 
66
 
        lowestTime=min((time_t)lowestTime,  (time_t)pr.d_pheader.ts.tv_sec);
67
 
        highestTime=max((time_t)highestTime, (time_t)pr.d_pheader.ts.tv_sec);
68
 
 
69
 
        string name=mdp.d_qname+"|"+DNSRecordContent::NumberToType(mdp.d_qtype);
70
 
        
71
 
        QuestionIdentifier qi=QuestionIdentifier::create(pr.d_ip, pr.d_udp, mdp);
72
 
 
73
 
        if(!mdp.d_header.qr) {
74
 
          //      cout<<"Question for '"<< name <<"'\n";
75
 
 
76
 
          QuestionData& qd=statmap[qi];
77
 
          
78
 
          if(!qd.d_firstquestiontime.tv_sec)
79
 
            qd.d_firstquestiontime=pr.d_pheader.ts;
80
 
          qd.d_qcount++;
81
 
        }
82
 
        else  {  // NO ERROR or NXDOMAIN
83
 
          QuestionData& qd=statmap[qi];
84
 
 
85
 
          if(!qd.d_qcount)
86
 
            untracked++;
87
 
 
88
 
          qd.d_answercount++;
89
 
          //      cout<<"Answer to '"<< name <<"': RCODE="<<(int)mdp.d_rcode<<", "<<mdp.d_answers.size()<<" answers\n";
90
 
          if(qd.d_qcount) {
91
 
            uint32_t usecs= (pr.d_pheader.ts.tv_sec - qd.d_firstquestiontime.tv_sec) * 1000000 +  
92
 
                            (pr.d_pheader.ts.tv_usec - qd.d_firstquestiontime.tv_usec) ;
93
 
            //      cout<<"Took: "<<usecs<<"usec\n";
94
 
            if(usecs<2049000)
95
 
              cumul[usecs]++;
96
 
            else
97
 
              reallylate++;
98
 
 
99
 
            
100
 
            if(mdp.d_header.rcode != 0 && mdp.d_header.rcode!=3) 
101
 
              errorresult++;
102
 
          }
103
 
 
104
 
          if(!qd.d_qcount || qd.d_qcount == qd.d_answercount)
105
 
            statmap.erase(statmap.find(qi));
106
 
        }
107
 
 
108
 
        rcodes[mdp.d_header.rcode]++;
 
64
        MOADNSParser mdp((const char*)pr.d_payload, pr.d_len);
 
65
 
 
66
        lowestTime=min((time_t)lowestTime,  (time_t)pr.d_pheader.ts.tv_sec);
 
67
        highestTime=max((time_t)highestTime, (time_t)pr.d_pheader.ts.tv_sec);
 
68
 
 
69
        string name=mdp.d_qname+"|"+DNSRecordContent::NumberToType(mdp.d_qtype);
 
70
        
 
71
        QuestionIdentifier qi=QuestionIdentifier::create(pr.d_ip, pr.d_udp, mdp);
 
72
 
 
73
        if(!mdp.d_header.qr) {
 
74
          //      cout<<"Question for '"<< name <<"'\n";
 
75
 
 
76
          QuestionData& qd=statmap[qi];
 
77
          
 
78
          if(!qd.d_firstquestiontime.tv_sec)
 
79
            qd.d_firstquestiontime=pr.d_pheader.ts;
 
80
          qd.d_qcount++;
 
81
        }
 
82
        else  {  // NO ERROR or NXDOMAIN
 
83
          QuestionData& qd=statmap[qi];
 
84
 
 
85
          if(!qd.d_qcount)
 
86
            untracked++;
 
87
 
 
88
          qd.d_answercount++;
 
89
          //      cout<<"Answer to '"<< name <<"': RCODE="<<(int)mdp.d_rcode<<", "<<mdp.d_answers.size()<<" answers\n";
 
90
          if(qd.d_qcount) {
 
91
            uint32_t usecs= (pr.d_pheader.ts.tv_sec - qd.d_firstquestiontime.tv_sec) * 1000000 +  
 
92
                            (pr.d_pheader.ts.tv_usec - qd.d_firstquestiontime.tv_usec) ;
 
93
            //      cout<<"Took: "<<usecs<<"usec\n";
 
94
            if(usecs<2049000)
 
95
              cumul[usecs]++;
 
96
            else
 
97
              reallylate++;
 
98
 
 
99
            
 
100
            if(mdp.d_header.rcode != 0 && mdp.d_header.rcode!=3) 
 
101
              errorresult++;
 
102
          }
 
103
 
 
104
          if(!qd.d_qcount || qd.d_qcount == qd.d_answercount)
 
105
            statmap.erase(statmap.find(qi));
 
106
         }
 
107
 
 
108
        rcodes[mdp.d_header.rcode]++;
109
109
      }
110
110
      catch(MOADNSException& mde) {
111
 
        //      cerr<<"error parsing packet: "<<mde.what()<<endl;
112
 
        if(pw)
113
 
          pw->write();
114
 
        dnserrors++;
115
 
        continue;
 
111
        //      cerr<<"error parsing packet: "<<mde.what()<<endl;
 
112
        if(pw)
 
113
          pw->write();
 
114
        dnserrors++;
 
115
        continue;
116
116
      }
117
117
      catch(std::exception& e) {
118
 
        if(pw)
119
 
          pw->write();
120
 
        bogus++;
121
 
        continue;
 
118
        if(pw)
 
119
          pw->write();
 
120
        bogus++;
 
121
        continue;
122
122
      }
123
123
    }
124
124
  }
184
184
  done[1024000];
185
185
  done[2048000];
186
186
 
187
 
  cout.setf(ios::fixed);
 
187
  cout.setf(std::ios::fixed);
188
188
  cout.precision(2);
189
189
  sum=0;
190
190
  
194
194
 
195
195
    for(done_t::iterator j=done.begin(); j!=done.end(); ++j)
196
196
      if(!j->second && i->first > j->first) {
197
 
        j->second=true;
 
197
        j->second=true;
198
198
 
199
 
        perc=sum*100.0/totpackets;
200
 
        if(j->first < 1024)
201
 
          cout<< perc <<"% of questions answered within " << j->first << " usec (";
202
 
        else
203
 
          cout<< perc <<"% of questions answered within " << j->first/1000.0 << " msec (";
204
 
        
205
 
        cout<<perc-lastperc<<"%)\n";
206
 
        lastperc=sum*100.0/totpackets;
 
199
        perc=sum*100.0/totpackets;
 
200
        if(j->first < 1024)
 
201
          cout<< perc <<"% of questions answered within " << j->first << " usec (";
 
202
        else
 
203
          cout<< perc <<"% of questions answered within " << j->first/1000.0 << " msec (";
 
204
        
 
205
        cout<<perc-lastperc<<"%)\n";
 
206
        lastperc=sum*100.0/totpackets;
207
207
      }
208
208
  }
209
209