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.
This commit is contained in:
Evan Hunt
2024-03-05 16:53:22 -08:00
parent 42be125727
commit b156167620
5 changed files with 41 additions and 20 deletions
+14 -17
View 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. */
+13 -1
View 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);
}
+12 -2
View 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
+1
View 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,
};
/*
+1
View 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