Changeset 544 for trunk/pdns/pdns/pdns_recursor.cc
- Timestamp:
- 11/11/05 12:57:50 (8 years ago)
- Files:
-
- 1 modified
-
trunk/pdns/pdns/pdns_recursor.cc (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/pdns_recursor.cc
r535 r544 209 209 static void writePid(void) 210 210 { 211 string fname= arg()["socket-dir"]+"/"+s_programname+".pid";211 string fname=::arg()["socket-dir"]+"/"+s_programname+".pid"; 212 212 ofstream of(fname.c_str()); 213 213 if(of) … … 222 222 set<DNSResourceRecord>nsset; 223 223 224 if( arg()["hint-file"].empty()) {224 if(::arg()["hint-file"].empty()) { 225 225 static char*ips[]={"198.41.0.4", "192.228.79.201", "192.33.4.12", "128.8.10.90", "192.203.230.10", "192.5.5.241", "192.112.36.4", "128.63.2.53", 226 226 "192.36.148.17","192.58.128.30", "193.0.14.129", "198.32.64.12", "202.12.27.33"}; … … 246 246 } 247 247 else { 248 ZoneParserTNG zpt( arg()["hint-file"]);248 ZoneParserTNG zpt(::arg()["hint-file"]); 249 249 DNSResourceRecord rr; 250 250 set<DNSResourceRecord> aset; … … 270 270 { 271 271 try { 272 bool quiet= arg().mustDo("quiet");272 bool quiet=::arg().mustDo("quiet"); 273 273 DNSComboWriter* dc=(DNSComboWriter *)p; 274 274 … … 376 376 sin.sin_family = AF_INET; 377 377 378 if(!IpToU32( arg()["query-local-address"], &sin.sin_addr.s_addr))379 throw AhuException("Unable to resolve local address '"+ arg()["query-local-address"] +"'");378 if(!IpToU32(::arg()["query-local-address"], &sin.sin_addr.s_addr)) 379 throw AhuException("Unable to resolve local address '"+ ::arg()["query-local-address"] +"'"); 380 380 381 381 int tries=10; … … 384 384 sin.sin_port = htons(port); 385 385 386 if ( bind(d_clientsock, (struct sockaddr *)&sin, sizeof(sin)) >= 0)386 if (::bind(d_clientsock, (struct sockaddr *)&sin, sizeof(sin)) >= 0) 387 387 break; 388 388 … … 398 398 { 399 399 vector<string>locals; 400 stringtok(locals, arg()["local-address"]," ,");400 stringtok(locals,::arg()["local-address"]," ,"); 401 401 402 402 if(locals.empty()) … … 421 421 } 422 422 423 sin.sin_port = htons( arg().asNum("local-port"));424 425 if ( bind(fd, (struct sockaddr *)&sin, sizeof(sin))<0)423 sin.sin_port = htons(::arg().asNum("local-port")); 424 425 if (::bind(fd, (struct sockaddr *)&sin, sizeof(sin))<0) 426 426 throw AhuException("Binding TCP server socket for "+*i+": "+stringerror()); 427 427 … … 429 429 listen(fd, 128); 430 430 s_tcpserversocks.push_back(fd); 431 L<<Logger::Error<<"Listening for TCP queries on "<<inet_ntoa(sin.sin_addr)<<":"<< arg().asNum("local-port")<<endl;431 L<<Logger::Error<<"Listening for TCP queries on "<<inet_ntoa(sin.sin_addr)<<":"<<::arg().asNum("local-port")<<endl; 432 432 } 433 433 } … … 436 436 { 437 437 vector<string>locals; 438 stringtok(locals, arg()["local-address"]," ,");438 stringtok(locals,::arg()["local-address"]," ,"); 439 439 440 440 if(locals.empty()) 441 441 throw AhuException("No local address specified"); 442 442 443 if( arg()["local-address"]=="0.0.0.0") {443 if(::arg()["local-address"]=="0.0.0.0") { 444 444 L<<Logger::Warning<<"It is advised to bind to explicit addresses with the --local-address option"<<endl; 445 445 } … … 457 457 throw AhuException("Unable to resolve local address '"+ *i +"'"); 458 458 459 sin.sin_port = htons( arg().asNum("local-port"));460 461 if ( bind(fd, (struct sockaddr *)&sin, sizeof(sin))<0)459 sin.sin_port = htons(::arg().asNum("local-port")); 460 461 if (::bind(fd, (struct sockaddr *)&sin, sizeof(sin))<0) 462 462 throw AhuException("Resolver binding to server socket for "+*i+": "+stringerror()); 463 463 464 464 Utility::setNonBlocking(fd); 465 465 d_udpserversocks.push_back(fd); 466 L<<Logger::Error<<"Listening for UDP queries on "<<inet_ntoa(sin.sin_addr)<<":"<< arg().asNum("local-port")<<endl;466 L<<Logger::Error<<"Listening for UDP queries on "<<inet_ntoa(sin.sin_addr)<<":"<<::arg().asNum("local-port")<<endl; 467 467 } 468 468 } … … 502 502 L<<Logger::Error<<"stats: "<<qcounter<<" questions, "<<RC.size()<<" cache entries, "<<SyncRes::s_negcache.size()<<" negative entries, " 503 503 <<(int)((RC.cacheHits*100.0)/(RC.cacheHits+RC.cacheMisses))<<"% cache hits"<<endl; 504 L<<Logger::Error<<"stats: throttle map: "<<SyncRes::s_throttle.size()<<", ns speeds: "<<SyncRes::s_nsSpeeds.size()<<endl; 504 L<<Logger::Error<<"stats: throttle map: "<<SyncRes::s_throttle.size()<<", ns speeds: " 505 <<SyncRes::s_nsSpeeds.size()<<", bytes: "<<RC.bytes()<<endl; 505 506 L<<Logger::Error<<"stats: outpacket/query ratio "<<(int)(SyncRes::s_outqueries*100.0/SyncRes::s_queries)<<"%"; 506 507 L<<Logger::Error<<", "<<(int)(SyncRes::s_throttledqueries*100.0/(SyncRes::s_outqueries+SyncRes::s_throttledqueries))<<"% throttled, " … … 521 522 RC.doPrune(); 522 523 int pruned=0; 523 for( map<string, NegCacheEntry>::iterator i = SyncRes::s_negcache.begin(); i != SyncRes::s_negcache.end();)524 for(SyncRes::negcache_t::iterator i = SyncRes::s_negcache.begin(); i != SyncRes::s_negcache.end();) 524 525 if(i->second.ttd > now) { 525 526 SyncRes::s_negcache.erase(i++); … … 528 529 else 529 530 ++i; 531 532 time_t limit=now-300; 533 for(SyncRes::nsspeeds_t::iterator i = SyncRes::s_nsSpeeds.begin() ; i!= SyncRes::s_nsSpeeds.end(); ) 534 if(i->second.stale(limit)) 535 SyncRes::s_nsSpeeds.erase(i++); 536 else 537 ++i; 538 530 539 // cerr<<"Pruned "<<pruned<<" records, left "<<SyncRes::s_negcache.size()<<"\n"; 531 540 last_prune=time(0); … … 603 612 try { 604 613 Utility::srandom(time(0)); 605 arg().set("soa-minimum-ttl","Don't change")="0";606 arg().set("soa-serial-offset","Don't change")="0";607 arg().set("no-shuffle","Don't change")="off";608 arg().set("aaaa-additional-processing","turn on to do AAAA additional processing (slow)")="off";609 arg().set("local-port","port to listen on")="53";610 arg().set("local-address","IP addresses to listen on, separated by spaces or commas")="0.0.0.0";611 arg().set("trace","if we should output heaps of logging")="off";612 arg().set("daemon","Operate as a daemon")="yes";613 arg().set("chroot","switch to chroot jail")="";614 arg().set("setgid","If set, change group id to this gid for more security")="";615 arg().set("setuid","If set, change user id to this uid for more security")="";616 arg().set("quiet","Suppress logging of questions and answers")="true";617 arg().set("config-dir","Location of configuration directory (recursor.conf)")=SYSCONFDIR;618 arg().set("socket-dir","Where the controlsocket will live")=LOCALSTATEDIR;619 arg().set("delegation-only","Which domains we only accept delegations from")="";620 arg().set("query-local-address","Source IP address for sending queries")="0.0.0.0";621 arg().set("client-tcp-timeout","Timeout in seconds when talking to TCP clients")="2";622 arg().set("max-tcp-clients","Maximum number of simultaneous TCP clients")="128";623 arg().set("hint-file", "If set, load root hints from this file")="";624 625 arg().setCmd("help","Provide a helpful message");614 ::arg().set("soa-minimum-ttl","Don't change")="0"; 615 ::arg().set("soa-serial-offset","Don't change")="0"; 616 ::arg().set("no-shuffle","Don't change")="off"; 617 ::arg().set("aaaa-additional-processing","turn on to do AAAA additional processing (slow)")="off"; 618 ::arg().set("local-port","port to listen on")="53"; 619 ::arg().set("local-address","IP addresses to listen on, separated by spaces or commas")="0.0.0.0"; 620 ::arg().set("trace","if we should output heaps of logging")="off"; 621 ::arg().set("daemon","Operate as a daemon")="yes"; 622 ::arg().set("chroot","switch to chroot jail")=""; 623 ::arg().set("setgid","If set, change group id to this gid for more security")=""; 624 ::arg().set("setuid","If set, change user id to this uid for more security")=""; 625 ::arg().set("quiet","Suppress logging of questions and answers")="true"; 626 ::arg().set("config-dir","Location of configuration directory (recursor.conf)")=SYSCONFDIR; 627 ::arg().set("socket-dir","Where the controlsocket will live")=LOCALSTATEDIR; 628 ::arg().set("delegation-only","Which domains we only accept delegations from")=""; 629 ::arg().set("query-local-address","Source IP address for sending queries")="0.0.0.0"; 630 ::arg().set("client-tcp-timeout","Timeout in seconds when talking to TCP clients")="2"; 631 ::arg().set("max-tcp-clients","Maximum number of simultaneous TCP clients")="128"; 632 ::arg().set("hint-file", "If set, load root hints from this file")=""; 633 634 ::arg().setCmd("help","Provide a helpful message"); 626 635 L.toConsole(Logger::Warning); 627 arg().laxParse(argc,argv); // do a lax parse628 629 string configname= arg()["config-dir"]+"/recursor.conf";636 ::arg().laxParse(argc,argv); // do a lax parse 637 638 string configname=::arg()["config-dir"]+"/recursor.conf"; 630 639 cleanSlashes(configname); 631 640 632 if(! arg().file(configname.c_str()))641 if(!::arg().file(configname.c_str())) 633 642 L<<Logger::Warning<<"Unable to parse configuration file '"<<configname<<"'"<<endl; 634 643 635 arg().parse(argc,argv);636 637 arg().set("delegation-only")=toLower(arg()["delegation-only"]);638 639 if( arg().mustDo("help")) {644 ::arg().parse(argc,argv); 645 646 ::arg().set("delegation-only")=toLower(::arg()["delegation-only"]); 647 648 if(::arg().mustDo("help")) { 640 649 cerr<<"syntax:"<<endl<<endl; 641 cerr<< arg().helpstring(arg()["help"])<<endl;650 cerr<<::arg().helpstring(::arg()["help"])<<endl; 642 651 exit(99); 643 652 } … … 656 665 657 666 658 if( arg().mustDo("trace")) {667 if(::arg().mustDo("trace")) { 659 668 SyncRes::setLog(true); 660 arg().set("quiet")="no";669 ::arg().set("quiet")="no"; 661 670 662 671 } … … 675 684 L<<Logger::Warning<<"Done priming cache with root hints"<<endl; 676 685 #ifndef WIN32 677 if( arg().mustDo("daemon")) {686 if(::arg().mustDo("daemon")) { 678 687 L.toConsole(Logger::Critical); 679 688 daemonize(); … … 687 696 688 697 int newgid=0; 689 if(! arg()["setgid"].empty())690 newgid=Utility::makeGidNumeric( arg()["setgid"]);698 if(!::arg()["setgid"].empty()) 699 newgid=Utility::makeGidNumeric(::arg()["setgid"]); 691 700 int newuid=0; 692 if(! arg()["setuid"].empty())693 newuid=Utility::makeUidNumeric( arg()["setuid"]);694 695 696 if (! arg()["chroot"].empty()) {697 if (chroot( arg()["chroot"].c_str())<0) {698 L<<Logger::Error<<"Unable to chroot to '"+ arg()["chroot"]+"': "<<strerror (errno)<<", exiting"<<endl;701 if(!::arg()["setuid"].empty()) 702 newuid=Utility::makeUidNumeric(::arg()["setuid"]); 703 704 705 if (!::arg()["chroot"].empty()) { 706 if (chroot(::arg()["chroot"].c_str())<0) { 707 L<<Logger::Error<<"Unable to chroot to '"+::arg()["chroot"]+"': "<<strerror (errno)<<", exiting"<<endl; 699 708 exit(1); 700 709 } … … 706 715 counter=0; 707 716 time_t now=0; 708 unsigned int maxTcpClients=arg().asNum("max-tcp-clients"); 717 unsigned int maxTcpClients=::arg().asNum("max-tcp-clients"); 718 int tcpLimit=::arg().asNum("client-tcp-timeout"); 709 719 for(;;) { 710 720 while(MT->schedule()); // housekeeping, let threads do their thing … … 732 742 733 743 vector<TCPConnection> sweeped; 734 int tcpLimit=arg().asNum("client-tcp-timeout"); 744 735 745 for(vector<TCPConnection>::iterator i=tcpconnections.begin();i!=tcpconnections.end();++i) { 736 746 if(now < i->startTime + tcpLimit) {