Show
Ignore:
Timestamp:
11/11/05 12:57:50 (8 years ago)
Author:
ahu
Message:

big rename, arg() -> ::arg(), bind() -> ::bind()
remove a read from the configuration from out of the loop - we looked stuff up per packet
add pruning of nsspeeds

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/pdns_recursor.cc

    r535 r544  
    209209static void writePid(void) 
    210210{ 
    211   string fname=arg()["socket-dir"]+"/"+s_programname+".pid"; 
     211  string fname=::arg()["socket-dir"]+"/"+s_programname+".pid"; 
    212212  ofstream of(fname.c_str()); 
    213213  if(of) 
     
    222222  set<DNSResourceRecord>nsset; 
    223223 
    224   if(arg()["hint-file"].empty()) { 
     224  if(::arg()["hint-file"].empty()) { 
    225225    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",  
    226226                       "192.36.148.17","192.58.128.30", "193.0.14.129", "198.32.64.12", "202.12.27.33"}; 
     
    246246  } 
    247247  else { 
    248     ZoneParserTNG zpt(arg()["hint-file"]); 
     248    ZoneParserTNG zpt(::arg()["hint-file"]); 
    249249    DNSResourceRecord rr; 
    250250    set<DNSResourceRecord> aset; 
     
    270270{ 
    271271  try { 
    272     bool quiet=arg().mustDo("quiet"); 
     272    bool quiet=::arg().mustDo("quiet"); 
    273273    DNSComboWriter* dc=(DNSComboWriter *)p; 
    274274 
     
    376376  sin.sin_family = AF_INET; 
    377377 
    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"] +"'");  
    380380 
    381381  int tries=10; 
     
    384384    sin.sin_port = htons(port);  
    385385     
    386     if (bind(d_clientsock, (struct sockaddr *)&sin, sizeof(sin)) >= 0)  
     386    if (::bind(d_clientsock, (struct sockaddr *)&sin, sizeof(sin)) >= 0)  
    387387      break; 
    388388     
     
    398398{ 
    399399  vector<string>locals; 
    400   stringtok(locals,arg()["local-address"]," ,"); 
     400  stringtok(locals,::arg()["local-address"]," ,"); 
    401401 
    402402  if(locals.empty()) 
     
    421421    } 
    422422     
    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)  
    426426      throw AhuException("Binding TCP server socket for "+*i+": "+stringerror()); 
    427427     
     
    429429    listen(fd, 128); 
    430430    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; 
    432432  } 
    433433} 
     
    436436{ 
    437437  vector<string>locals; 
    438   stringtok(locals,arg()["local-address"]," ,"); 
     438  stringtok(locals,::arg()["local-address"]," ,"); 
    439439 
    440440  if(locals.empty()) 
    441441    throw AhuException("No local address specified"); 
    442442   
    443   if(arg()["local-address"]=="0.0.0.0") { 
     443  if(::arg()["local-address"]=="0.0.0.0") { 
    444444    L<<Logger::Warning<<"It is advised to bind to explicit addresses with the --local-address option"<<endl; 
    445445  } 
     
    457457      throw AhuException("Unable to resolve local address '"+ *i +"'");  
    458458     
    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)  
    462462      throw AhuException("Resolver binding to server socket for "+*i+": "+stringerror()); 
    463463     
    464464    Utility::setNonBlocking(fd); 
    465465    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; 
    467467  } 
    468468} 
     
    502502    L<<Logger::Error<<"stats: "<<qcounter<<" questions, "<<RC.size()<<" cache entries, "<<SyncRes::s_negcache.size()<<" negative entries, " 
    503503     <<(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; 
    505506    L<<Logger::Error<<"stats: outpacket/query ratio "<<(int)(SyncRes::s_outqueries*100.0/SyncRes::s_queries)<<"%"; 
    506507    L<<Logger::Error<<", "<<(int)(SyncRes::s_throttledqueries*100.0/(SyncRes::s_outqueries+SyncRes::s_throttledqueries))<<"% throttled, " 
     
    521522    RC.doPrune(); 
    522523    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();)  
    524525      if(i->second.ttd > now) { 
    525526        SyncRes::s_negcache.erase(i++); 
     
    528529      else 
    529530        ++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 
    530539    //    cerr<<"Pruned "<<pruned<<" records, left "<<SyncRes::s_negcache.size()<<"\n"; 
    531540    last_prune=time(0); 
     
    603612  try { 
    604613    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"); 
    626635    L.toConsole(Logger::Warning); 
    627     arg().laxParse(argc,argv); // do a lax parse 
    628  
    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"; 
    630639    cleanSlashes(configname); 
    631640 
    632     if(!arg().file(configname.c_str()))  
     641    if(!::arg().file(configname.c_str()))  
    633642      L<<Logger::Warning<<"Unable to parse configuration file '"<<configname<<"'"<<endl; 
    634643 
    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")) { 
    640649      cerr<<"syntax:"<<endl<<endl; 
    641       cerr<<arg().helpstring(arg()["help"])<<endl; 
     650      cerr<<::arg().helpstring(::arg()["help"])<<endl; 
    642651      exit(99); 
    643652    } 
     
    656665 
    657666 
    658   if(arg().mustDo("trace")) { 
     667  if(::arg().mustDo("trace")) { 
    659668      SyncRes::setLog(true); 
    660       arg().set("quiet")="no"; 
     669      ::arg().set("quiet")="no"; 
    661670       
    662671  } 
     
    675684    L<<Logger::Warning<<"Done priming cache with root hints"<<endl; 
    676685#ifndef WIN32 
    677     if(arg().mustDo("daemon")) { 
     686    if(::arg().mustDo("daemon")) { 
    678687      L.toConsole(Logger::Critical); 
    679688      daemonize(); 
     
    687696 
    688697    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"]); 
    691700    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; 
    699708            exit(1); 
    700709        } 
     
    706715    counter=0; 
    707716    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"); 
    709719    for(;;) { 
    710720      while(MT->schedule()); // housekeeping, let threads do their thing 
     
    732742 
    733743      vector<TCPConnection> sweeped; 
    734       int tcpLimit=arg().asNum("client-tcp-timeout"); 
     744 
    735745      for(vector<TCPConnection>::iterator i=tcpconnections.begin();i!=tcpconnections.end();++i) { 
    736746        if(now < i->startTime + tcpLimit) {