Changeset 140 for trunk/pdns/pdns/pdns_recursor.cc
- Timestamp:
- 01/23/03 16:34:53 (10 years ago)
- Files:
-
- 1 modified
-
trunk/pdns/pdns/pdns_recursor.cc (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/pdns_recursor.cc
r138 r140 24 24 #include <netdb.h> 25 25 #include <stdio.h> 26 #include <signal.h> 26 27 #include <stdlib.h> 27 28 #include <unistd.h> … … 50 51 int d_serversock; 51 52 52 53 /*54 Jan 20 00:21:40 [48570] new question arrived for 'idealx.com|MX' from 127.0.0.155 Jan 20 00:21:40 [48571] new question arrived for 'idealx.com|MX' from 127.0.0.156 Jan 20 00:21:40 [48572] new question arrived for 'idealx.com|MX' from 127.0.0.157 Jan 20 00:21:40 [48573] new question arrived for 'idealx.com|MX' from 127.0.0.158 Jan 20 00:21:44 [48573] sent answer to question for 'idealx.com|MX' to 127.0.0.1, 0 answers, 0 additional, sent 2 packets, rcode=259 Jan 20 00:21:44 [48573] sent answer to question for 'idealx.com|MX' to 127.0.0.1, 0 answers, 0 additional, sent 2 packets, rcode=260 Jan 20 00:21:44 [48573] sent answer to question for 'idealx.com|MX' to 127.0.0.1, 0 answers, 0 additional, sent 2 packets, rcode=261 Jan 20 00:21:44 [48573] sent answer to question for 'idealx.com|MX' to 127.0.0.1, 0 answers, 0 additional, sent 2 packets, rcode=262 */63 64 53 struct PacketID 65 54 { … … 84 73 } 85 74 86 MTasker<PacketID,string> MT( 200000);75 MTasker<PacketID,string> MT(100000); // could probably be way lower 87 76 88 77 /* these two functions are used by LWRes */ … … 108 97 return 1; 109 98 } 110 111 99 112 100 typedef map<string,set<DNSResourceRecord> > cache_t; … … 119 107 if(res) 120 108 *res=j->second; 121 cacheHits++; 109 122 110 return (unsigned int)j->second.begin()->ttl-time(0); 123 111 } 124 cacheMisses++; 112 125 113 return -1; 126 114 } … … 139 127 // prime root cache 140 128 static char*ips[]={"198.41.0.4", "128.9.0.107", "192.33.4.12", "128.8.10.90", "192.203.230.10", "192.5.5.241", "192.112.36.4", "128.63.2.53", 141 "192.36.148.17","19 8.41.0.10", "193.0.14.129", "198.32.64.12", "202.12.27.33"};129 "192.36.148.17","192.58.128.30", "193.0.14.129", "198.32.64.12", "202.12.27.33"}; 142 130 DNSResourceRecord arr, nsrr; 143 131 arr.qtype=QType::A; … … 165 153 { 166 154 try { 155 bool quiet=arg().mustDo("quiet"); 167 156 DNSPacket P=*(DNSPacket *)p; 168 157 … … 175 164 176 165 SyncRes sr; 177 L<<Logger::Error<<"["<<MT.getTid()<<"] question for '"<<P.qdomain<<"|"<<P.qtype.getName()<<"' from "<<P.getRemote()<<endl; 166 if(!quiet) 167 L<<Logger::Error<<"["<<MT.getTid()<<"] question for '"<<P.qdomain<<"|"<<P.qtype.getName()<<"' from "<<P.getRemote()<<endl; 168 178 169 sr.setId(MT.getTid()); 179 170 if(!P.d.rd) … … 191 182 const char *buffer=R->getData(); 192 183 sendto(d_serversock,buffer,R->len,0,(struct sockaddr *)(R->remote),R->d_socklen); 193 L<<Logger::Error<<"["<<MT.getTid()<<"] answer to "<<(P.d.rd?"":"non-rd ")<<"question '"<<P.qdomain<<"|"<<P.qtype.getName(); 194 L<<"': "<<ntohs(R->d.ancount)<<" answers, "<<ntohs(R->d.arcount)<<" additional, took "<<sr.d_outqueries<<" packets, rcode="<<res<<endl; 184 if(!quiet) { 185 L<<Logger::Error<<"["<<MT.getTid()<<"] answer to "<<(P.d.rd?"":"non-rd ")<<"question '"<<P.qdomain<<"|"<<P.qtype.getName(); 186 L<<"': "<<ntohs(R->d.ancount)<<" answers, "<<ntohs(R->d.arcount)<<" additional, took "<<sr.d_outqueries<<" packets, rcode="<<res<<endl; 187 } 188 189 sr.d_outqueries ? cacheMisses++ : cacheHits++; 195 190 196 191 delete R; … … 273 268 } 274 269 int counter, qcounter; 270 bool statsWanted; 271 272 void usr1Handler(int) 273 { 274 statsWanted=true; 275 } 276 void doStats(void) 277 { 278 if(qcounter) { 279 L<<Logger::Error<<"stats: "<<qcounter<<" questions, "<<cache.size()<<" cache entries, "<<SyncRes::s_negcache.size()<<" negative entries, " 280 <<(int)((cacheHits*100.0)/(cacheHits+cacheMisses))<<"% cache hits"; 281 L<<Logger::Error<<", outpacket/query ratio "<<(int)(SyncRes::s_outqueries*100.0/SyncRes::s_queries)<<"%"<<endl; 282 } 283 statsWanted=false; 284 } 275 285 276 286 void houseKeeping(void *) … … 278 288 static time_t last_stat, last_rootupdate; 279 289 280 if(time(0)-last_stat>1800) { 281 if(qcounter) { 282 L<<Logger::Error<<"stats: "<<qcounter<<" questions, "<<cache.size()<<" cache entries, " 283 <<(int)((cacheHits*100.0)/(cacheHits+cacheMisses))<<"% cache hits"; 284 L<<Logger::Error<<", outpacket/query ratio "<<(int)(SyncRes::s_outqueries*100.0/SyncRes::s_queries)<<"%"<<endl; 285 } 290 if(time(0)-last_stat>1800) { 291 doStats(); 286 292 last_stat=time(0); 287 293 } … … 308 314 arg().set("soa-serial-offset","Don't change")="0"; 309 315 arg().set("aaaa-additional-processing","turn on to do AAAA additional processing (slow)")="off"; 310 arg().set("local-port","port to listen on")="53 00";316 arg().set("local-port","port to listen on")="53"; 311 317 arg().set("local-address","port to listen on")="0.0.0.0"; 312 318 arg().set("trace","if we should output heaps of logging")="off"; 313 arg().set("daemon","Operate as a daemon")="no"; 319 arg().set("daemon","Operate as a daemon")="yes"; 320 arg().set("quiet","Suppress logging of questions and answers")="off"; 321 arg().set("config-dir","Location of configuration directory (recursor.conf)")=SYSCONFDIR; 314 322 arg().setCmd("help","Provide a helpful message"); 315 316 arg().parse(argc, argv); 323 L.toConsole(Logger::Warning); 324 arg().laxParse(argc,argv); // do a lax parse 325 326 string configname=arg()["config-dir"]+"/recursor.conf"; 327 cleanSlashes(configname); 328 329 if(!arg().file(configname.c_str())) 330 L<<Logger::Warning<<"Unable to parse configuration file '"<<configname<<"'"<<endl; 331 332 arg().parse(argc,argv); 333 317 334 318 335 if(arg().mustDo("help")) { … … 322 339 } 323 340 324 325 341 L.setName("pdns_recursor"); 326 L.toConsole(Logger::Warning);327 342 328 343 if(arg().mustDo("trace")) … … 343 358 daemonize(); 344 359 } 360 signal(SIGUSR1,usr1Handler); 361 345 362 for(;;) { 346 363 while(MT.schedule()); // housekeeping, let threads do their thing 347 364 348 if(!((counter++)%100 0))365 if(!((counter++)%100)) 349 366 MT.makeThread(houseKeeping,0); 367 if(statsWanted) 368 doStats(); 350 369 351 370 socklen_t addrlen=sizeof(fromaddr); … … 362 381 FD_SET( d_serversock, &readfds ); 363 382 int selret = select( max(d_clientsock,d_serversock) + 1, &readfds, NULL, NULL, &tv ); 364 if (selret == -1) 383 if(selret<=0) 384 if (selret == -1 && errno!=EINTR) 365 385 throw AhuException("Select returned: "+stringerror()); 366 if(!selret) // nothing happened 367 continue; 386 else 387 continue; 388 368 389 369 390 if(FD_ISSET(d_clientsock,&readfds)) { // do we have a question response?