From: Evan Hunt Date: Thu, 1 Feb 2024 00:47:30 +0000 (-0800) Subject: add dns_db_nodefullname() X-Git-Tag: v9.19.22~10^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=89c4c1aa878c831de409cdb6ed30193b69230e51;p=thirdparty%2Fbind9.git add dns_db_nodefullname() 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. --- diff --git a/bin/tests/system/dyndb/driver/db.c b/bin/tests/system/dyndb/driver/db.c index 62ee2800429..9fa587d16d0 100644 --- a/bin/tests/system/dyndb/driver/db.c +++ b/bin/tests/system/dyndb/driver/db.c @@ -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. */ diff --git a/lib/dns/db.c b/lib/dns/db.c index 41a75b497a2..149fc95f894 100644 --- a/lib/dns/db.c +++ b/lib/dns/db.c @@ -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); +} diff --git a/lib/dns/include/dns/db.h b/lib/dns/include/dns/db.h index b6362d99eed..7643ec3debd 100644 --- a/lib/dns/include/dns/db.h +++ b/lib/dns/include/dns/db.h @@ -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 diff --git a/lib/dns/qp-cachedb.c b/lib/dns/qp-cachedb.c index e5c351453f5..cc0562bb7c0 100644 --- a/lib/dns/qp-cachedb.c +++ b/lib/dns/qp-cachedb.c @@ -1549,6 +1549,7 @@ dns_dbmethods_t dns__qpdb_cachemethods = { .unlocknode = dns__qpdb_unlocknode, .expiredata = expiredata, .deletedata = dns__qpdb_deletedata, + .nodefullname = dns__qpdb_nodefullname, }; /* diff --git a/lib/dns/qp-zonedb.c b/lib/dns/qp-zonedb.c index b545b506bf8..2c6b9cac376 100644 --- a/lib/dns/qp-zonedb.c +++ b/lib/dns/qp-zonedb.c @@ -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