Ticket #304: patch-also-notify-20100610.diff

File patch-also-notify-20100610.diff, 10.0 KB (added by anon, 3 years ago)
  • pdns/backends/bind/bindbackend2.cc

    old new  
    228228  shared_ptr<State> state = s_state; 
    229229 
    230230  for(id_zone_map_t::const_iterator i = state->id_zone_map.begin(); i != state->id_zone_map.end() ; ++i) { 
    231     if(!i->second.d_masters.empty()) 
     231    if(!i->second.d_masters.empty() && this->alsoNotify.empty() && i->second.d_also_notify.empty()) 
    232232      continue; 
    233233    soadata.serial=0; 
    234234    try { 
     
    307307  return false; 
    308308} 
    309309 
     310void Bind2Backend::alsoNotifies(const string &domain, set<string> *ips) 
     311{ 
     312  shared_ptr<State> state = s_state; 
     313  // combine global list with local list 
     314  for(set<string>::iterator i = this->alsoNotify.begin(); i != this->alsoNotify.end(); i++) { 
     315    (*ips).insert(*i); 
     316  } 
     317  for(id_zone_map_t::const_iterator i = state->id_zone_map.begin(); i != state->id_zone_map.end() ; ++i) { 
     318    if(i->second.d_name==domain) { 
     319      for(set<string>::iterator it = i->second.d_also_notify.begin(); it != i->second.d_also_notify.end(); it++) { 
     320        (*ips).insert(*it); 
     321      } 
     322      return; 
     323    } 
     324  }    
     325} 
    310326 
    311327//! lowercase, strip trailing . 
    312328static string canonic(string ret) 
     
    512528    } 
    513529       
    514530    vector<BindDomainInfo> domains=BP.getDomains(); 
    515      
     531    this->alsoNotify = BP.getAlsoNotify(); 
     532 
    516533    s_binddirectory=BP.getDirectory(); 
    517534    //    ZP.setDirectory(d_binddirectory); 
    518535 
     
    567584        bbd->d_name=i->name; 
    568585        bbd->d_filename=i->filename; 
    569586        bbd->d_masters=i->masters; 
     587        bbd->d_also_notify=i->alsoNotify; 
    570588         
    571589        if(!bbd->d_loaded || !bbd->current()) { 
    572590          //      L<<Logger::Info<<d_logprefix<<" parsing '"<<i->name<<"' from file '"<<i->filename<<"'"<<endl; 
  • pdns/backends/bind/bindbackend2.hh

    old new  
    8484  unsigned int d_id;  //!< internal id of the domain 
    8585  time_t d_lastcheck; //!< last time domain was checked for freshness 
    8686  vector<string> d_masters;     //!< IP address of the master of this domain 
     87  set<string> d_also_notify; //!< IP list of hosts to also notify 
    8788 
    8889  uint32_t d_lastnotified; //!< Last serial number we notified our slaves of 
    8990 
     
    121122  bool commitTransaction(); 
    122123  bool abortTransaction(); 
    123124 
     125  void alsoNotifies(const string &domain, set<string> *ips); 
     126 
    124127  typedef map<string, int, CIStringCompare> name_id_map_t; 
    125128  typedef map<uint32_t, BB2DomainInfo> id_zone_map_t; 
    126129 
     
    184187  static string s_binddirectory;                              //!< this is used to store the 'directory' setting of the bind configuration 
    185188  string d_logprefix; 
    186189 
     190  set<string> alsoNotify; //!< this is used to store the also-notify list of interested peers. 
     191 
    187192  int d_transaction_id; 
    188193  string d_transaction_tmpname; 
    189194 
  • pdns/backends/bind/bindlexer.l

    old new  
    109109 
    110110file                    return FILETOK; 
    111111options                 return OPTIONSTOK; 
     112also-notify             return ALSONOTIFYTOK; 
    112113acl                     return ACLTOK; 
    113114logging                 return LOGGINGTOK; 
    114115directory               return DIRECTORYTOK; 
  • pdns/backends/bind/bindparser.yy

    old new  
    7272        bind_directory=d_dir.c_str(); 
    7373} 
    7474 
     75void BindParser::addAlsoNotify(const string & host) 
     76{ 
     77        alsoNotify.insert(host); 
     78} 
     79 
    7580const string &BindParser::getDirectory() 
    7681{ 
    7782        return d_dir; 
     
    101106%} 
    102107 
    103108%token AWORD QUOTEDWORD OBRACE EBRACE SEMICOLON ZONETOK FILETOK OPTIONSTOK 
    104 %token DIRECTORYTOK ACLTOK LOGGINGTOK CLASSTOK TYPETOK MASTERTOK 
     109%token DIRECTORYTOK ACLTOK LOGGINGTOK CLASSTOK TYPETOK MASTERTOK ALSONOTIFYTOK 
    105110 
    106111%% 
    107112 
     
    147152        LOGGINGTOK OBRACE options_commands EBRACE 
    148153        ; 
    149154 
     155 
    150156acl_command: 
    151157        ACLTOK quotedname acl_block |   ACLTOK filename acl_block 
    152158        ; 
     
    168174        options_command SEMICOLON options_commands 
    169175        ; 
    170176 
    171 options_command: command | options_directory_command 
     177options_command: command | options_directory_command | also_notify_command 
    172178        ; 
    173179 
    174180options_directory_command: DIRECTORYTOK quotedname 
     
    178184        } 
    179185        ; 
    180186 
     187also_notify_command: ALSONOTIFYTOK OBRACE also_notify_list EBRACE  
     188        ; 
     189 
     190also_notify_list:  
     191        | 
     192        also_notify SEMICOLON also_notify_list 
     193        ; 
    181194 
     195also_notify: AWORD 
     196        { 
     197                parent->addAlsoNotify($1); 
     198                free($1); 
     199        } 
     200        ; 
    182201terms: /* empty */ 
    183202        | 
    184203        terms term 
     
    199218        zone_commands zone_command SEMICOLON 
    200219        ; 
    201220 
    202 zone_command: command | zone_file_command | zone_type_command | zone_masters_command 
     221zone_command: command | zone_file_command | zone_type_command | zone_masters_command | zone_also_notify_command 
    203222        ; 
    204223 
    205224zone_masters_command: MASTERTOK OBRACE masters EBRACE 
    206225        ; 
    207226 
     227zone_also_notify_command: ALSONOTIFYTOK OBRACE zone_also_notify_list EBRACE 
     228        ; 
     229 
     230zone_also_notify_list: 
     231        | 
     232        zone_also_notify SEMICOLON zone_also_notify_list 
     233        ; 
     234 
     235zone_also_notify: AWORD 
     236        { 
     237                s_di.alsoNotify.insert($1); 
     238                free($1); 
     239        } 
     240        ; 
     241 
    208242masters: /* empty */ 
    209243        |  
    210244        masters master SEMICOLON  
     
    243277        ; 
    244278 
    245279filename: AWORD 
    246         ; 
    247  No newline at end of file 
     280        ; 
  • pdns/backends/bind/bindparser.hh

    old new  
    2121#include <string> 
    2222#include <map> 
    2323#include <vector> 
     24#include <set> 
    2425 
    2526using namespace std; 
    2627 
     
    3435  { 
    3536    name=filename=type=""; 
    3637    masters.clear(); 
     38    alsoNotify.clear(); 
    3739    d_dev=0; 
    3840    d_ino=0; 
    3941  } 
     
    4143  string viewName; 
    4244  string filename; 
    4345  vector<string> masters; 
     46  set<string> alsoNotify; 
    4447  string type; 
    4548     
    4649  dev_t d_dev; 
     
    7881  const string &getDirectory(); 
    7982  const vector<BindDomainInfo>& getDomains(); 
    8083  void setVerbose(bool verbose); 
     84  void addAlsoNotify(const string &host); 
     85  set<string> & getAlsoNotify() { return this->alsoNotify; }  
    8186private: 
    8287  string d_dir; 
    8388  bool d_verbose; 
    8489  typedef map<string,string> zonedomain_t; 
    85  
     90  set<string> alsoNotify; 
    8691  vector<BindDomainInfo> d_zonedomains; 
    8792}; 
    8893 
  • pdns/ueberbackend.cc

    old new  
    284284  PC.insert(q.qname, q.qtype, PacketCache::QUERYCACHE, rr.serialize(), queryttl, q.zoneId); 
    285285} 
    286286 
     287void UeberBackend::alsoNotifies(const string &domain, set<string> *ips) 
     288{ 
     289  for ( vector< DNSBackend * >::iterator i = backends.begin(); i != backends.end(); ++i ) 
     290    (*i)->alsoNotifies(domain,ips); 
     291} 
    287292 
    288293UeberBackend::~UeberBackend() 
    289294{ 
  • pdns/ueberbackend.hh

    old new  
    124124  void getUnfreshSlaveInfos(vector<DomainInfo>* domains); 
    125125  void getUpdatedMasters(vector<DomainInfo>* domains); 
    126126  bool getDomainInfo(const string &domain, DomainInfo &di); 
     127  void alsoNotifies(const string &domain, set<string> *ips);  
    127128  void rediscover(string* status=0); 
    128129  void reload(); 
    129130private: 
  • pdns/common_startup.cc

    old new  
    8080  ::arg().set("launch","Which backends to launch and order to query them in")=""; 
    8181  ::arg().setSwitch("disable-axfr","Disable zonetransfers but do allow TCP queries")="no"; 
    8282  ::arg().set("allow-axfr-ips","Allow zonetransfers only to these subnets")="0.0.0.0/0"; 
     83  ::arg().set("also-notify","Global setting for also-notify domains")=""; 
    8384  ::arg().set("slave-cycle-interval","Reschedule failed SOA serial checks once every .. seconds")="60"; 
    8485 
    8586  ::arg().set("tcp-control-address","If set, PowerDNS can be controlled over TCP on this address")=""; 
  • pdns/communicator.cc

    old new  
    163163    for(vector<string>::const_iterator k=nsips.begin();k!=nsips.end();++k) 
    164164      ips.insert(*k); 
    165165  } 
    166    
     166  
     167  // inject also-notify from backends and global config 
     168 
     169  set<string>alsoNotify; 
     170  B->alsoNotifies(domain, &alsoNotify); 
     171 
     172  for(vector<string>::const_iterator k=d_an.begin();k!=d_an.end();k++) 
     173     alsoNotify.insert(*k); 
     174 
     175  for(set<string>::const_iterator k=alsoNotify.begin();k!=alsoNotify.end();++k) 
     176     ips.insert(*k); 
     177 
    167178  // make calls to d_nq.add(domain, ip); 
    168179  for(set<string>::const_iterator j=ips.begin();j!=ips.end();++j) { 
    169180    L<<Logger::Warning<<"Queued notification of domain '"<<domain<<"' to "<<*j<<endl; 
    170181    d_nq.add(domain,*j); 
    171182  } 
    172    
    173   set<string>alsoNotify; 
    174   B->alsoNotifies(domain, &alsoNotify); 
    175    
    176   for(set<string>::const_iterator j=alsoNotify.begin();j!=alsoNotify.end();++j) { 
    177     L<<Logger::Warning<<"Queued also-notification of domain '"<<domain<<"' to "<<*j<<endl; 
    178     d_nq.add(domain,*j); 
    179   } 
    180183} 
    181184 
    182185bool CommunicatorClass::notifyDomain(const string &domain) 
     
    425428    signal(SIGPIPE,SIG_IGN); 
    426429#endif // WIN32 
    427430    L<<Logger::Error<<"Master/slave communicator launching"<<endl; 
     431    
     432    // parse d_an 
     433    if (!::arg()["also-notify"].empty()) { 
     434            vector<string> parts; 
     435            stringtok( parts, ::arg()["also-notify"], ", \t" );  
     436            for( vector<string>::const_iterator i = parts.begin(); i != parts.end(); ++i )  
     437              d_an.push_back( *i ); // add to also-notify list 
     438    } 
     439 
    428440    PacketHandler P; 
    429441    d_tickinterval=::arg().asNum("slave-cycle-interval"); 
    430442    makeNotifySocket(); 
  • pdns/communicator.hh

    old new  
    165165  Semaphore d_any_sem; 
    166166  time_t d_tickinterval; 
    167167  NotificationQueue d_nq; 
     168  vector<string> d_an; // also notify list  
    168169  bool d_masterschanged, d_slaveschanged; 
    169170}; 
    170171