Changeset 1457

Show
Ignore:
Timestamp:
12/21/09 14:40:30 (9 months ago)
Author:
ahu
Message:

some whitespace changes, add 'rec_control reload-acls' (leaks some memory!), plus fix issue with TCP/IP errors leading to exceptions, debugged by Josh Berry of Plusnet PLC.

Location:
trunk/pdns/pdns
Files:
3 modified

Legend:

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

    r1454 r1457  
    9797//MemcachedCommunicator* g_mc; 
    9898// DHCPCommunicator* g_dc; 
     99 
    99100map<int, ComboAddress> g_listenSocketsAddresses; // is shared across all threads right now 
     101 
    100102struct DNSComboWriter { 
    101103  DNSComboWriter(const char* data, uint16_t len, const struct timeval& now) : d_mdp(data, len), d_now(now),  
     
    661663        } 
    662664 
    663         pw.commit(); 
     665      pw.commit(); 
    664666      } 
    665667    } 
     
    689691 
    690692      if(ret == 0)  
    691         L<<Logger::Error<<"EOF writing TCP answer to "<<dc->getRemote()<<endl; 
     693        L<<Logger::Error<<"EOF writing TCP answer to "<<dc->getRemote()<<endl; 
    692694      else if(ret < 0 )   
    693         L<<Logger::Error<<"Error writing TCP answer to "<<dc->getRemote()<<": "<< strerror(errno) <<endl; 
     695        L<<Logger::Error<<"Error writing TCP answer to "<<dc->getRemote()<<": "<< strerror(errno) <<endl; 
    694696      else if((unsigned int)ret != 2 + packet.size()) 
    695         L<<Logger::Error<<"Oops, partial answer sent to "<<dc->getRemote()<<" for "<<dc->d_mdp.d_qname<<" (size="<< (2 + packet.size()) <<", sent "<<ret<<")"<<endl; 
     697        L<<Logger::Error<<"Oops, partial answer sent to "<<dc->getRemote()<<" for "<<dc->d_mdp.d_qname<<" (size="<< (2 + packet.size()) <<", sent "<<ret<<")"<<endl; 
    696698      else 
    697         hadError=false; 
     699        hadError=false; 
    698700       
    699701      // update tcp connection status, either by closing or moving to 'BYTE0' 
    700  
     702     
    701703      if(hadError) { 
    702         t_fdm->removeReadFD(dc->d_socket); 
    703         TCPConnection::closeAndCleanup(dc->d_socket, dc->d_remote); 
     704        // no need to remove us from FDM, we weren't there 
     705        TCPConnection::closeAndCleanup(dc->d_socket, dc->d_remote); 
    704706      } 
    705707      else { 
    706         TCPConnection tc; 
    707         tc.fd=dc->d_socket; 
    708         tc.state=TCPConnection::BYTE0; 
    709         tc.remote=dc->d_remote; 
    710         Utility::gettimeofday(&g_now, 0); // needs to be updated 
    711         tc.startTime=g_now.tv_sec; 
    712         t_fdm->addReadFD(tc.fd, handleRunningTCPQuestion, tc); 
    713         t_fdm->setReadTTD(tc.fd, g_now, g_tcpTimeout); 
     708        TCPConnection tc; 
     709        tc.fd=dc->d_socket; 
     710        tc.state=TCPConnection::BYTE0; 
     711        tc.remote=dc->d_remote; 
     712        Utility::gettimeofday(&g_now, 0); // needs to be updated 
     713        tc.startTime=g_now.tv_sec; 
     714        t_fdm->addReadFD(tc.fd, handleRunningTCPQuestion, tc); 
     715        t_fdm->setReadTTD(tc.fd, g_now, g_tcpTimeout); 
    714716      } 
    715717    } 
     
    718720      L<<Logger::Error<<t_id<<" ["<<MT->getTid()<<"] answer to "<<(dc->d_mdp.d_header.rd?"":"non-rd ")<<"question '"<<dc->d_mdp.d_qname<<"|"<<DNSRecordContent::NumberToType(dc->d_mdp.d_qtype); 
    719721      L<<"': "<<ntohs(pw.getHeader()->ancount)<<" answers, "<<ntohs(pw.getHeader()->arcount)<<" additional, took "<<sr.d_outqueries<<" packets, "<< 
    720         sr.d_throttledqueries<<" throttled, "<<sr.d_timeouts<<" timeouts, "<<sr.d_tcpoutqueries<<" tcp connections, rcode="<<res<<endl; 
     722      sr.d_throttledqueries<<" throttled, "<<sr.d_timeouts<<" timeouts, "<<sr.d_tcpoutqueries<<" tcp connections, rcode="<<res<<endl; 
    721723    } 
    722724 
     
    17191721} 
    17201722 
    1721  
    1722  
    1723  
    17241723void* recursorThread(void*); 
     1724 
     1725void parseACLs() 
     1726{ 
     1727  static bool l_initialized; 
     1728  if(l_initialized) { 
     1729    string configname=::arg()["config-dir"]+"/recursor.conf"; 
     1730    cleanSlashes(configname); 
     1731     
     1732    if(!::arg().preParseFile(configname.c_str(), "allow-from-file"))  
     1733      L<<Logger::Warning<<"Unable to re-parse configuration file '"<<configname<<"'"<<endl; 
     1734     
     1735    ::arg().preParseFile(configname.c_str(), "allow-from"); 
     1736  } 
     1737  l_initialized = true; 
     1738  if(!::arg()["allow-from-file"].empty()) { 
     1739    string line; 
     1740    NetmaskGroup* allowFrom=new NetmaskGroup; 
     1741    ifstream ifs(::arg()["allow-from-file"].c_str()); 
     1742    if(!ifs) { 
     1743      throw AhuException("Could not open '"+::arg()["allow-from-file"]+"': "+stringerror()); 
     1744    } 
     1745 
     1746    string::size_type pos; 
     1747    while(getline(ifs,line)) { 
     1748      pos=line.find('#'); 
     1749      if(pos!=string::npos) 
     1750        line.resize(pos); 
     1751      trim(line); 
     1752      if(line.empty()) 
     1753        continue; 
     1754 
     1755      allowFrom->addMask(line); 
     1756    } 
     1757    g_allowFrom = allowFrom; 
     1758    L<<Logger::Warning<<"Done parsing " << g_allowFrom->size() <<" allow-from ranges from file '"<<::arg()["allow-from-file"]<<"' - overriding 'allow-from' setting"<<endl; 
     1759  } 
     1760  else if(!::arg()["allow-from"].empty()) { 
     1761    NetmaskGroup* allowFrom=new NetmaskGroup; 
     1762    vector<string> ips; 
     1763    stringtok(ips, ::arg()["allow-from"], ", "); 
     1764    L<<Logger::Warning<<"Only allowing queries from: "; 
     1765    for(vector<string>::const_iterator i = ips.begin(); i!= ips.end(); ++i) { 
     1766      allowFrom->addMask(*i); 
     1767      if(i!=ips.begin()) 
     1768        L<<Logger::Warning<<", "; 
     1769      L<<Logger::Warning<<*i; 
     1770    } 
     1771    L<<Logger::Warning<<endl; 
     1772    g_allowFrom = allowFrom; 
     1773  } 
     1774  else if(::arg()["local-address"]!="127.0.0.1" && ::arg().asNum("local-port")==53) 
     1775    L<<Logger::Error<<"WARNING: Allowing queries from all IP addresses - this can be a security risk!"<<endl; 
     1776} 
    17251777 
    17261778int serviceMain(int argc, char*argv[]) 
     
    17551807  seedRandom(::arg()["entropy-source"]); 
    17561808 
    1757   if(!::arg()["allow-from-file"].empty()) { 
    1758     string line; 
    1759     g_allowFrom=new NetmaskGroup; 
    1760     ifstream ifs(::arg()["allow-from-file"].c_str()); 
    1761     if(!ifs) { 
    1762       throw AhuException("Could not open '"+::arg()["allow-from-file"]+"': "+stringerror()); 
    1763     } 
    1764  
    1765     string::size_type pos; 
    1766     while(getline(ifs,line)) { 
    1767       pos=line.find('#'); 
    1768       if(pos!=string::npos) 
    1769         line.resize(pos); 
    1770       trim(line); 
    1771       if(line.empty()) 
    1772         continue; 
    1773  
    1774       g_allowFrom->addMask(line); 
    1775     } 
    1776     L<<Logger::Warning<<"Done parsing " << g_allowFrom->size() <<" allow-from ranges from file '"<<::arg()["allow-from-file"]<<"' - overriding 'allow-from' setting"<<endl; 
    1777   } 
    1778   else if(!::arg()["allow-from"].empty()) { 
    1779     g_allowFrom=new NetmaskGroup; 
    1780     vector<string> ips; 
    1781     stringtok(ips, ::arg()["allow-from"], ", "); 
    1782     L<<Logger::Warning<<"Only allowing queries from: "; 
    1783     for(vector<string>::const_iterator i = ips.begin(); i!= ips.end(); ++i) { 
    1784       g_allowFrom->addMask(*i); 
    1785       if(i!=ips.begin()) 
    1786         L<<Logger::Warning<<", "; 
    1787       L<<Logger::Warning<<*i; 
    1788     } 
    1789     L<<Logger::Warning<<endl; 
    1790   } 
    1791   else if(::arg()["local-address"]!="127.0.0.1" && ::arg().asNum("local-port")==53) 
    1792     L<<Logger::Error<<"WARNING: Allowing queries from all IP addresses - this can be a security risk!"<<endl; 
    1793    
    1794  
     1809  parseACLs(); 
     1810   
    17951811  if(!::arg()["dont-query"].empty()) { 
    17961812    g_dontQuery=new NetmaskGroup; 
  • trunk/pdns/pdns/rec_channel_rec.cc

    r1453 r1457  
    405405  } 
    406406 
     407  if(cmd=="reload-acls") { 
     408    try { 
     409      parseACLs(); 
     410    }  
     411    catch(exception& e)  
     412    { 
     413      return e.what() + string("\n"); 
     414    } 
     415    return "ok\n"; 
     416  } 
     417 
    407418 
    408419  if(cmd=="top-remotes") 
  • trunk/pdns/pdns/syncres.hh

    r1454 r1457  
    548548 
    549549string doQueueReloadLuaScript(vector<string>::const_iterator begin, vector<string>::const_iterator end); 
    550  
     550void parseACLs(); 
    551551extern RecursorStats g_stats; 
    552552