]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
first baby steps to dnssec in lmdb-backend
authorKees Monshouwer <mind04@monshouwer.org>
Thu, 29 May 2014 20:09:06 +0000 (22:09 +0200)
committermind04 <mind04@monshouwer.org>
Tue, 24 Jun 2014 16:23:28 +0000 (18:23 +0200)
modules/lmdbbackend/lmdbbackend.cc
modules/lmdbbackend/lmdbbackend.hh
pdns/zone2lmdb.cc

index 3417a79220877c5ea06762f9fb6cd65abfc23622..0a2e470cc0b225446f737080acfb06ef9676cc6a 100644 (file)
@@ -48,7 +48,7 @@ void LMDBBackend::open_db() {
     if( (rc = mdb_env_create(&env))  )
         throw PDNSException("Couldn't open LMDB database " + path + ": mdb_env_create() returned " + mdb_strerror(rc));
 
-    if( (rc = mdb_env_set_maxdbs( env, 3 )) )
+    if( (rc = mdb_env_set_maxdbs( env, 5 )) )
         throw PDNSException("Couldn't open LMDB database " + path + ": mdb_env_set_maxdbs() returned " + mdb_strerror(rc));
 
     if( (rc = mdb_env_open(env, path.c_str(), MDB_RDONLY, 0)) )
@@ -72,6 +72,16 @@ void LMDBBackend::open_db() {
     if( ( rc = mdb_cursor_open(txn, data_extended_db, &data_extended_cursor)) )
         throw PDNSException("Couldn't open cursor on LMDB data_extended database " + path + ": mdb_cursor_open() returned " + mdb_strerror(rc));
 
+    if( (rc = mdb_dbi_open(txn, "rrsig", MDB_DUPSORT, &rrsig_db) ))
+        throw PDNSException("Couldn't open LMDB rrsig database " + path + ": mdb_dbi_open() returned " + mdb_strerror(rc));
+    if( ( rc = mdb_cursor_open(txn, rrsig_db, &rrsig_cursor)) )
+        throw PDNSException("Couldn't open cursor on LMDB rrsig database " + path + ": mdb_cursor_open() returned " + mdb_strerror(rc));
+
+    if( (rc = mdb_dbi_open(txn, "nsecx", 0, &nsecx_db) ))
+        throw PDNSException("Couldn't open LMDB nsecx database " + path + ": mdb_dbi_open() returned " + mdb_strerror(rc));
+    if( ( rc = mdb_cursor_open(txn, nsecx_db, &nsecx_cursor)) )
+        throw PDNSException("Couldn't open cursor on LMDB nsecx database " + path + ": mdb_cursor_open() returned " + mdb_strerror(rc));
+
 }
 
 void LMDBBackend::close_db() {
@@ -80,9 +90,13 @@ void LMDBBackend::close_db() {
     mdb_cursor_close(data_cursor);
     mdb_cursor_close(zone_cursor);
     mdb_cursor_close(data_extended_cursor);
+    mdb_cursor_close(rrsig_cursor);
+    mdb_cursor_close(nsecx_cursor);
     mdb_dbi_close(env, data_db);
     mdb_dbi_close(env, zone_db);
     mdb_dbi_close(env, data_extended_db);
+    mdb_dbi_close(env, rrsig_db);
+    mdb_dbi_close(env, nsecx_db);
     mdb_txn_abort(txn);
     mdb_env_close(env);
 }
@@ -114,6 +128,8 @@ bool LMDBBackend::getAuthZone( string &rev_zone )
     mdb_cursor_renew( txn, zone_cursor );
     mdb_cursor_renew( txn, data_cursor );
     mdb_cursor_renew( txn, data_extended_cursor );
+    mdb_cursor_renew( txn, rrsig_cursor );
+    mdb_cursor_renew( txn, nsecx_cursor );
 
     // Find the nearest record, or the last record if none
     if( mdb_cursor_get(zone_cursor, &key, &data, MDB_SET_RANGE) )
@@ -121,11 +137,9 @@ bool LMDBBackend::getAuthZone( string &rev_zone )
 
     rev_zone.assign( (const char *)key.mv_data, key.mv_size );
 
-    DEBUGLOG("Auth key: " << rev_zone <<endl);
-
-    /* Only skip this bit if we got an exact hit on the SOA. otherwise we have
-     * to go back to the previous record */
-    if( orig.compare( rev_zone ) != 0 ) {
+    /* Only skip this bit if we got an exact hit on the SOA or if the key is a shoter
+     * version of rev_zone. Otherwise we have to go back to the previous record */
+    if( orig.compare( 0, rev_zone.length(), rev_zone ) != 0 ) {
         /* Skip back 1 entry to what should be a substring of what was searched
          * for (or a totally different entry) */
         if( mdb_cursor_get(zone_cursor, &key, &data, MDB_PREV) ) {
@@ -137,6 +151,8 @@ bool LMDBBackend::getAuthZone( string &rev_zone )
         rev_zone.assign( (const char *)key.mv_data, key.mv_size );
     }
 
+    DEBUGLOG("Auth key: " << rev_zone <<endl);
+
     return true;
 }
 
index 8a9bc561db8b95e8fb58c37508eabf485ebc7aa6..ba881941e21f06b2a432bd9eab43153243858a43 100644 (file)
@@ -11,9 +11,9 @@ class LMDBBackend : public DNSReversedBackend
 private:
 
     MDB_env *env;
-    MDB_dbi data_db, zone_db, data_extended_db;
+    MDB_dbi data_db, zone_db, data_extended_db, rrsig_db, nsecx_db,;
     MDB_txn *txn;
-    MDB_cursor *data_cursor, *zone_cursor, *data_extended_cursor;
+    MDB_cursor *data_cursor, *zone_cursor, *data_extended_cursor, *rrsig_cursor, *nsecx_cursor;
 
     // Domain that we are querying for in list()/lookup()/get(). In original case and direction.
     string d_origdomain;
index e7d7b643415e8d79febc682410156c540a5a58ce..b552300bc3a9253b3023c2bebe21731e1038b680 100644 (file)
@@ -49,13 +49,13 @@ int g_numRecords=0;
 int g_numRefs=0;
 
 MDB_env *env;
-MDB_dbi data_db, zone_db, data_extended_db;
+MDB_dbi data_db, zone_db, data_extended_db, rrsig_db, nsecx_db;
 MDB_txn *txn, *txn_zone;
 
 void openDB(){
   mdb_env_create(&env);
   mdb_env_set_mapsize(env, 1*1024*1024*1024);
-  mdb_env_set_maxdbs(env, 3);
+  mdb_env_set_maxdbs(env, 5);
   mdb_env_open(env, "./", 0, 0644);
 
   mdb_txn_begin(env, NULL, 0, &txn);
@@ -63,6 +63,8 @@ void openDB(){
   mdb_dbi_open(txn, "zone", MDB_CREATE, &zone_db);
   mdb_dbi_open(txn, "data", MDB_CREATE | MDB_DUPSORT, &data_db);
   mdb_dbi_open(txn, "extended_data", MDB_CREATE, &data_extended_db);
+  mdb_dbi_open(txn, "rrsig", MDB_CREATE | MDB_DUPSORT, &rrsig_db);
+  mdb_dbi_open(txn, "nsecx", MDB_CREATE, &nsecx_db);
 }
 
 void closeDB(){
@@ -70,6 +72,8 @@ void closeDB(){
   mdb_dbi_close(env, data_db);
   mdb_dbi_close(env, zone_db);
   mdb_dbi_close(env, data_extended_db);
+  mdb_dbi_close(env, rrsig_db);
+  mdb_dbi_close(env, nsecx_db);
   mdb_env_close(env);
 }