Changeset 1982
- Timestamp:
- 02/07/11 10:31:12 (2 years ago)
- Location:
- trunk/pdns/pdns
- Files:
-
- 2 modified
-
dbdnsseckeeper.cc (modified) (8 diffs)
-
dnsseckeeper.hh (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/dbdnsseckeeper.cc
r1975 r1982 36 36 using namespace boost; 37 37 38 __thread DNSSECKeeper::keycache_t* DNSSECKeeper::t_keycache;38 DNSSECKeeper::keycache_t DNSSECKeeper::s_keycache; 39 39 DNSSECKeeper::metacache_t DNSSECKeeper::s_metacache; 40 40 pthread_mutex_t DNSSECKeeper::s_metacachelock = PTHREAD_MUTEX_INITIALIZER; 41 pthread_mutex_t DNSSECKeeper::s_keycachelock = PTHREAD_MUTEX_INITIALIZER; 41 42 42 43 bool DNSSECKeeper::isSecuredZone(const std::string& zone) … … 44 45 if(isPresigned(zone)) 45 46 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 } 51 57 else 52 return true; 53 } 54 else 55 ; 56 58 ; 59 } 57 60 keyset_t keys = getKeys(zone, true); 58 61 … … 72 75 } 73 76 74 voidDNSSECKeeper::addKey(const std::string& name, bool keyOrZone, int algorithm, int bits, bool active)77 bool DNSSECKeeper::addKey(const std::string& name, bool keyOrZone, int algorithm, int bits, bool active) 75 78 { 76 79 if(!bits) { … … 93 96 dspk.d_algorithm = algorithm; 94 97 dspk.d_flags = keyOrZone ? 257 : 256; 95 addKey(name, dspk, active);98 return addKey(name, dspk, active); 96 99 } 97 100 98 101 void DNSSECKeeper::clearCaches(const std::string& name) 99 102 { 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 } 102 107 Lock l(&s_metacachelock); 103 108 pair<metacache_t::iterator, metacache_t::iterator> range = s_metacache.equal_range(name); … … 107 112 108 113 109 voidDNSSECKeeper::addKey(const std::string& name, const DNSSECPrivateKey& dpk, bool active)114 bool DNSSECKeeper::addKey(const std::string& name, const DNSSECPrivateKey& dpk, bool active) 110 115 { 111 116 clearCaches(name); … … 115 120 kd.content = dpk.getKey()->convertToISC(); 116 121 // now store it 117 d_keymetadb.addDomainKey(name, kd);122 return d_keymetadb.addDomainKey(name, kd) >= 0; // >= 0 == s 118 123 } 119 124 … … 257 262 { 258 263 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 } 270 277 keyset_t retkeyset, allkeyset; 271 278 vector<UeberBackend::KeyData> dbkeyset; … … 301 308 kce.d_keys = allkeyset; 302 309 kce.d_ttd = now + 30; 303 replacing_insert(*t_keycache, kce); 310 { 311 Lock l(&s_keycachelock); 312 replacing_insert(s_keycache, kce); 313 } 304 314 305 315 return retkeyset; 306 316 } 307 317 308 voidDNSSECKeeper::secureZone(const std::string& name, int algorithm)318 bool DNSSECKeeper::secureZone(const std::string& name, int algorithm) 309 319 { 310 320 clearCaches(name); // just to be sure ;) 311 addKey(name, true, algorithm);321 return addKey(name, true, algorithm); 312 322 } 313 323 -
trunk/pdns/pdns/dnsseckeeper.hh
r1969 r1982 33 33 DNSSECKeeper() : d_keymetadb("key-only") 34 34 { 35 if(!t_keycache)36 t_keycache = new keycache_t();37 35 } 38 36 bool isSecuredZone(const std::string& zone); … … 40 38 keyset_t getKeys(const std::string& zone, boost::tribool allOrKeyOrZone = boost::indeterminate); 41 39 DNSSECPrivateKey getKeyById(const std::string& zone, unsigned int id); 42 voidaddKey(const std::string& zname, bool keyOrZone, int algorithm=5, int bits=0, bool active=true);43 voidaddKey(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); 44 42 void removeKey(const std::string& zname, unsigned int id); 45 43 void activateKey(const std::string& zname, unsigned int id); 46 44 void deactivateKey(const std::string& zname, unsigned int id); 47 45 48 voidsecureZone(const std::string& fname, int algorithm);46 bool secureZone(const std::string& fname, int algorithm); 49 47 50 48 bool getNSEC3PARAM(const std::string& zname, NSEC3PARAMRecordContent* n3p=0, bool* narrow=0); … … 107 105 > metacache_t; 108 106 109 static __thread keycache_t* t_keycache;107 static keycache_t s_keycache; 110 108 static metacache_t s_metacache; 111 109 static pthread_mutex_t s_metacachelock; 110 static pthread_mutex_t s_keycachelock; 112 111 }; 113 112