]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
add dns_db_nodefullname()
authorEvan Hunt <each@isc.org>
Thu, 1 Feb 2024 00:47:30 +0000 (16:47 -0800)
committerMatthijs Mekking <matthijs@isc.org>
Wed, 6 Mar 2024 09:49:02 +0000 (10:49 +0100)
the dyndb test requires a mechanism to retrieve the name associated
with a database node, and since the database no longer uses RBT for
its underlying storage, dns_rbt_fullnamefromnode() doesn't work.
addressed this by adding dns_db_nodefullname() to the database API.

bin/tests/system/dyndb/driver/db.c
lib/dns/db.c
lib/dns/include/dns/db.h
lib/dns/qp-cachedb.c
lib/dns/qp-zonedb.c

index 62ee280042949e5b52a4bbd0983d9ab4614cc164..9fa587d16d07f115e7052f161726c85afb66b340 100644 (file)
@@ -76,21 +76,6 @@ struct sampledb {
 
 typedef struct sampledb sampledb_t;
 
-/*
- * Get full DNS name from the node.
- *
- * @warning
- * The code silently expects that "node" came from RBTDB and thus
- * assumption dns_dbnode_t (from RBTDB) == dns_rbtnode_t is correct.
- *
- * This should work as long as we use only RBTDB and nothing else.
- */
-static isc_result_t
-sample_name_fromnode(dns_dbnode_t *node, dns_name_t *name) {
-       dns_rbtnode_t *rbtnode = (dns_rbtnode_t *)node;
-       return (dns_rbt_fullnamefromnode(rbtnode, name));
-}
-
 static void
 destroy(dns_db_t *db) {
        sampledb_t *sampledb = (sampledb_t *)db;
@@ -252,7 +237,8 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
        if (rdataset->type == dns_rdatatype_a ||
            rdataset->type == dns_rdatatype_aaaa)
        {
-               CHECK(sample_name_fromnode(node, dns_fixedname_name(&name)));
+               CHECK(dns_db_nodefullname(sampledb->rbtdb, node,
+                                         dns_fixedname_name(&name)));
                CHECK(syncptrs(sampledb->inst, dns_fixedname_name(&name),
                               rdataset, DNS_DIFFOP_ADD));
        }
@@ -282,7 +268,8 @@ subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
        if (rdataset->type == dns_rdatatype_a ||
            rdataset->type == dns_rdatatype_aaaa)
        {
-               CHECK(sample_name_fromnode(node, dns_fixedname_name(&name)));
+               CHECK(dns_db_nodefullname(sampledb->rbtdb, node,
+                                         dns_fixedname_name(&name)));
                CHECK(syncptrs(sampledb->inst, dns_fixedname_name(&name),
                               rdataset, DNS_DIFFOP_DEL));
        }
@@ -431,6 +418,15 @@ setcachestats(dns_db_t *db, isc_stats_t *stats) {
        return (dns_db_setcachestats(sampledb->rbtdb, stats));
 }
 
+static isc_result_t
+nodefullname(dns_db_t *db, dns_dbnode_t *node, dns_name_t *name) {
+       sampledb_t *sampledb = (sampledb_t *)db;
+
+       REQUIRE(VALID_SAMPLEDB(sampledb));
+
+       return (dns_db_nodefullname(sampledb->rbtdb, node, name));
+}
+
 /*
  * DB interface definition. Database driver uses this structure to
  * determine which implementation of dns_db_*() function to call.
@@ -464,6 +460,7 @@ static dns_dbmethods_t sampledb_methods = {
        .findnodeext = findnodeext,
        .findext = findext,
        .setcachestats = setcachestats,
+       .nodefullname = nodefullname,
 };
 
 /* Auxiliary driver functions. */
index 41a75b497a2138e077f4793411a6fcd8760a0bbf..149fc95f8941e399c29e552859ff7e2bf08fe7e9 100644 (file)
@@ -142,7 +142,7 @@ dns_db_create(isc_mem_t *mctx, const char *db_type, const dns_name_t *origin,
 
 #if DNS_DB_TRACE
                fprintf(stderr, "dns_db_create:%s:%s:%d:%p->references = 1\n",
-                       __func__, __FILE__, __LINE__ 1, *dbp);
+                       __func__, __FILE__, __LINE__ 1, *dbp);
 #endif
                return (result);
        }
@@ -1149,3 +1149,15 @@ dns_db_deletedata(dns_db_t *db, dns_dbnode_t *node, void *data) {
                (db->methods->deletedata)(db, node, data);
        }
 }
+
+isc_result_t
+dns_db_nodefullname(dns_db_t *db, dns_dbnode_t *node, dns_name_t *name) {
+       REQUIRE(db != NULL);
+       REQUIRE(node != NULL);
+       REQUIRE(name != NULL);
+
+       if (db->methods->nodefullname != NULL) {
+               return ((db->methods->nodefullname)(db, node, name));
+       }
+       return (ISC_R_NOTIMPLEMENTED);
+}
index b6362d99eedb31661877e14b40954013849f84bb..7643ec3debdbaadf5d7cdfa2fc3ef42b70d43191 100644 (file)
@@ -179,6 +179,8 @@ typedef struct dns_dbmethods {
                                dns_rdataset_t *rdataset, dns_message_t *msg);
        void (*expiredata)(dns_db_t *db, dns_dbnode_t *node, void *data);
        void (*deletedata)(dns_db_t *db, dns_dbnode_t *node, void *data);
+       isc_result_t (*nodefullname)(dns_db_t *db, dns_dbnode_t *node,
+                                    dns_name_t *name);
 } dns_dbmethods_t;
 
 typedef isc_result_t (*dns_dbcreatefunc_t)(isc_mem_t       *mctx,
@@ -1782,6 +1784,14 @@ dns_db_deletedata(dns_db_t *db, dns_dbnode_t *node, void *data);
  * data from an LRU list or a heap.
  */
 
-void
-dns_db_expiredata(dns_db_t *db, dns_dbnode_t *node, void *data);
+isc_result_t
+dns_db_nodefullname(dns_db_t *db, dns_dbnode_t *node, dns_name_t *name);
+/*%<
+ * Get the name associated with a database node.
+ *
+ * Requires:
+ *
+ * \li 'db' is a valid database
+ * \li 'node' and 'name' are not NULL
+ */
 ISC_LANG_ENDDECLS
index e5c351453f529c29983b4a9078679af55ff18841..cc0562bb7c06f5fda5beabfe57d658f37bb9e307 100644 (file)
@@ -1549,6 +1549,7 @@ dns_dbmethods_t dns__qpdb_cachemethods = {
        .unlocknode = dns__qpdb_unlocknode,
        .expiredata = expiredata,
        .deletedata = dns__qpdb_deletedata,
+       .nodefullname = dns__qpdb_nodefullname,
 };
 
 /*
index b545b506bf89d2633cfe5018c71d52312e3036fe..2c6b9cac376f1f7f309039c8f12ea1420099ad70 100644 (file)
@@ -2379,6 +2379,7 @@ dns_dbmethods_t dns__qpdb_zonemethods = {
        .unlocknode = dns__qpdb_unlocknode,
        .addglue = addglue,
        .deletedata = dns__qpdb_deletedata,
+       .nodefullname = dns__qpdb_nodefullname,
 };
 
 void