Changeset 1982

Show
Ignore:
Timestamp:
02/07/11 10:31:12 (2 years ago)
Author:
ahu
Message:

make sure that addKey lets us know if it worked, allowing us to spot non-working configurations
unthread the keycache, reintroducing the 'shared key' problem, but plugging a massive memory leak

Location:
trunk/pdns/pdns
Files:
2 modified

Legend:

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

    r1975 r1982  
    3636using namespace boost; 
    3737 
    38 __thread DNSSECKeeper::keycache_t* DNSSECKeeper::t_keycache; 
     38DNSSECKeeper::keycache_t DNSSECKeeper::s_keycache; 
    3939DNSSECKeeper::metacache_t DNSSECKeeper::s_metacache; 
    4040pthread_mutex_t DNSSECKeeper::s_metacachelock = PTHREAD_MUTEX_INITIALIZER; 
     41pthread_mutex_t DNSSECKeeper::s_keycachelock = PTHREAD_MUTEX_INITIALIZER; 
    4142 
    4243bool DNSSECKeeper::isSecuredZone(const std::string& zone)  
     
    4445  if(isPresigned(zone)) 
    4546    return true; 
    46            
    47   keycache_t::const_iterator iter = t_keycache->find(zone); 
    48   if(iter != t_keycache->end() && iter->d_ttd > (unsigned int)time(0)) {  
    49     if(iter->d_keys.empty()) 
    50       return false; 
     47   
     48  { 
     49    Lock l(&s_keycachelock); 
     50    keycache_t::const_iterator iter = s_keycache.find(zone); 
     51    if(iter != s_keycache.end() && iter->d_ttd > (unsigned int)time(0)) {  
     52      if(iter->d_keys.empty()) 
     53        return false; 
     54      else 
     55        return true; 
     56    } 
    5157    else 
    52       return true; 
    53   } 
    54   else 
    55     ;  
    56    
     58      ;  
     59  }   
    5760  keyset_t keys = getKeys(zone, true); 
    5861   
     
    7275} 
    7376 
    74 void DNSSECKeeper::addKey(const std::string& name, bool keyOrZone, int algorithm, int bits, bool active) 
     77bool DNSSECKeeper::addKey(const std::string& name, bool keyOrZone, int algorithm, int bits, bool active) 
    7578{ 
    7679  if(!bits) { 
     
    9396  dspk.d_algorithm = algorithm; 
    9497  dspk.d_flags = keyOrZone ? 257 : 256; 
    95   addKey(name, dspk, active); 
     98  return addKey(name, dspk, active); 
    9699} 
    97100 
    98101void DNSSECKeeper::clearCaches(const std::string& name) 
    99102{ 
    100   t_keycache->erase(name); // should this be broadcast in some way? 
    101    
     103  { 
     104    Lock l(&s_keycachelock); 
     105    s_keycache.erase(name);  
     106  } 
    102107  Lock l(&s_metacachelock); 
    103108  pair<metacache_t::iterator, metacache_t::iterator> range = s_metacache.equal_range(name); 
     
    107112 
    108113 
    109 void DNSSECKeeper::addKey(const std::string& name, const DNSSECPrivateKey& dpk, bool active) 
     114bool DNSSECKeeper::addKey(const std::string& name, const DNSSECPrivateKey& dpk, bool active) 
    110115{ 
    111116  clearCaches(name); 
     
    115120  kd.content = dpk.getKey()->convertToISC(); 
    116121 // now store it 
    117   d_keymetadb.addDomainKey(name, kd); 
     122  return d_keymetadb.addDomainKey(name, kd) >= 0; // >= 0 == s 
    118123} 
    119124 
     
    257262{ 
    258263  unsigned int now = time(0); 
    259   keycache_t::const_iterator iter = t_keycache->find(zone); 
    260      
    261   if(iter != t_keycache->end() && iter->d_ttd > now) {  
    262     keyset_t ret; 
    263     BOOST_FOREACH(const keyset_t::value_type& value, iter->d_keys) { 
    264       if(boost::indeterminate(allOrKeyOrZone) || allOrKeyOrZone == value.second.keyOrZone) 
    265         ret.push_back(value); 
    266     } 
    267     return ret; 
    268   } 
    269      
     264  { 
     265    Lock l(&s_keycachelock); 
     266    keycache_t::const_iterator iter = s_keycache.find(zone); 
     267       
     268    if(iter != s_keycache.end() && iter->d_ttd > now) {  
     269      keyset_t ret; 
     270      BOOST_FOREACH(const keyset_t::value_type& value, iter->d_keys) { 
     271        if(boost::indeterminate(allOrKeyOrZone) || allOrKeyOrZone == value.second.keyOrZone) 
     272          ret.push_back(value); 
     273      } 
     274      return ret; 
     275    } 
     276  }     
    270277  keyset_t retkeyset, allkeyset; 
    271278  vector<UeberBackend::KeyData> dbkeyset; 
     
    301308  kce.d_keys = allkeyset; 
    302309  kce.d_ttd = now + 30; 
    303   replacing_insert(*t_keycache, kce); 
     310  { 
     311    Lock l(&s_keycachelock); 
     312    replacing_insert(s_keycache, kce); 
     313  } 
    304314   
    305315  return retkeyset; 
    306316} 
    307317 
    308 void DNSSECKeeper::secureZone(const std::string& name, int algorithm) 
     318bool DNSSECKeeper::secureZone(const std::string& name, int algorithm) 
    309319{ 
    310320  clearCaches(name); // just to be sure ;) 
    311   addKey(name, true, algorithm); 
     321  return addKey(name, true, algorithm); 
    312322} 
    313323 
  • trunk/pdns/pdns/dnsseckeeper.hh

    r1969 r1982  
    3333  DNSSECKeeper() : d_keymetadb("key-only") 
    3434  { 
    35     if(!t_keycache) 
    36       t_keycache = new keycache_t(); 
    3735  } 
    3836  bool isSecuredZone(const std::string& zone); 
     
    4038  keyset_t getKeys(const std::string& zone, boost::tribool allOrKeyOrZone = boost::indeterminate); 
    4139  DNSSECPrivateKey getKeyById(const std::string& zone, unsigned int id); 
    42   void addKey(const std::string& zname, bool keyOrZone, int algorithm=5, int bits=0, bool active=true); 
    43   void addKey(const std::string& zname, const DNSSECPrivateKey& dpk, bool active=true); 
     40  bool addKey(const std::string& zname, bool keyOrZone, int algorithm=5, int bits=0, bool active=true); 
     41  bool addKey(const std::string& zname, const DNSSECPrivateKey& dpk, bool active=true); 
    4442  void removeKey(const std::string& zname, unsigned int id); 
    4543  void activateKey(const std::string& zname, unsigned int id); 
    4644  void deactivateKey(const std::string& zname, unsigned int id); 
    4745 
    48   void secureZone(const std::string& fname, int algorithm); 
     46  bool secureZone(const std::string& fname, int algorithm); 
    4947 
    5048  bool getNSEC3PARAM(const std::string& zname, NSEC3PARAMRecordContent* n3p=0, bool* narrow=0); 
     
    107105  > metacache_t; 
    108106 
    109   static __thread keycache_t* t_keycache; 
     107  static keycache_t s_keycache; 
    110108  static metacache_t s_metacache; 
    111109  static pthread_mutex_t s_metacachelock; 
     110  static pthread_mutex_t s_keycachelock; 
    112111}; 
    113112