diff --git a/lib/dns/include/dns/qp.h b/lib/dns/include/dns/qp.h index 236d63faaf..e2dbb71afa 100644 --- a/lib/dns/include/dns/qp.h +++ b/lib/dns/include/dns/qp.h @@ -536,9 +536,12 @@ dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name, * * If 'foundname' is not NULL, it will be updated to contain the name * that was found (if any). The return code, ISC_R_SUCCESS or - * DNS_R_PARTIALMATCH, indicates whether the name found is name that - * was requested, or an ancestor. If the result is ISC_R_NOTFOUND, - * 'foundname' will not be updated. + * DNS_R_PARTIALMATCH, indicates whether the name found is the name + * that was requested, or an ancestor. If the result is ISC_R_NOTFOUND, + * 'foundname' will not be updated. (NOTE: the name will be constructed + * from the QP key of the found node, and this can be time-consuming. + * In performance-critical code, it is faster to store a copy of the + * name in the node data and use that instead of passing 'foundname'.) * * If 'chain' is not NULL, it is updated to contain a QP chain with * references to the populated nodes in the tree between the root and diff --git a/lib/dns/nametree.c b/lib/dns/nametree.c index 77ecd309b8..24c51d504c 100644 --- a/lib/dns/nametree.c +++ b/lib/dns/nametree.c @@ -278,9 +278,12 @@ dns_nametree_covered(dns_nametree_t *nametree, const dns_name_t *name, REQUIRE(VALID_NAMETREE(nametree)); dns_qpmulti_query(nametree->table, &qpr); - result = dns_qp_lookup(&qpr, name, found, NULL, NULL, (void **)&node, + result = dns_qp_lookup(&qpr, name, NULL, NULL, NULL, (void **)&node, NULL); if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { + if (found != NULL) { + dns_name_copy(&node->name, found); + } switch (nametree->type) { case DNS_NAMETREE_BOOL: ret = node->set; diff --git a/lib/dns/qpcache.c b/lib/dns/qpcache.c index 647b54bdc4..3c5c7afe8f 100644 --- a/lib/dns/qpcache.c +++ b/lib/dns/qpcache.c @@ -1499,11 +1499,12 @@ find_coveringnsec(search_t *search, const dns_name_t *name, * Lookup the predecessor in the main tree. */ node = NULL; - result = dns_qp_lookup(search->qpdb->tree, predecessor, fname, NULL, + result = dns_qp_lookup(search->qpdb->tree, predecessor, NULL, NULL, NULL, (void **)&node, NULL); if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); } + dns_name_copy(&node->name, fname); lock = &(search->qpdb->node_locks[node->locknum].lock); NODE_RDLOCK(lock, &nlocktype); @@ -1597,8 +1598,11 @@ find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, /* * Search down from the root of the tree. */ - result = dns_qp_lookup(search.qpdb->tree, name, foundname, NULL, + result = dns_qp_lookup(search.qpdb->tree, name, NULL, NULL, &search.chain, (void **)&node, NULL); + if (result != ISC_R_NOTFOUND && foundname != NULL) { + dns_name_copy(&node->name, foundname); + } /* * Check the QP chain to see if there's a node above us with a @@ -1619,17 +1623,16 @@ find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, dns_qpchain_node(&search.chain, i, NULL, (void **)&encloser, NULL); - if (encloser->delegating) { - zcresult = check_zonecut( - encloser, (void *)&search DNS__DB_FLARG_PASS); - if (zcresult != DNS_R_CONTINUE) { - result = DNS_R_PARTIALMATCH; - dns_qpchain_node(&search.chain, i, foundname, - NULL, NULL); - search.chain.len = i - 1; - node = encloser; - break; + zcresult = check_zonecut(encloser, + (void *)&search DNS__DB_FLARG_PASS); + if (zcresult != DNS_R_CONTINUE) { + result = DNS_R_PARTIALMATCH; + search.chain.len = i - 1; + node = encloser; + if (foundname != NULL) { + dns_name_copy(&node->name, foundname); } + break; } } @@ -2034,8 +2037,11 @@ findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options, /* * Search down from the root of the tree. */ - result = dns_qp_lookup(search.qpdb->tree, name, dcname, NULL, + result = dns_qp_lookup(search.qpdb->tree, name, NULL, NULL, &search.chain, (void **)&node, NULL); + if (result != ISC_R_NOTFOUND) { + dns_name_copy(&node->name, dcname); + } if ((options & DNS_DBFIND_NOEXACT) != 0 && result == ISC_R_SUCCESS) { int len = dns_qpchain_length(&search.chain); if (len >= 2) { diff --git a/lib/dns/qpzone.c b/lib/dns/qpzone.c index a570a5c918..9f66d54692 100644 --- a/lib/dns/qpzone.c +++ b/lib/dns/qpzone.c @@ -3382,8 +3382,11 @@ find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, /* * Search down from the root of the tree. */ - result = dns_qp_lookup(&search.qpr, name, foundname, &search.iter, + result = dns_qp_lookup(&search.qpr, name, NULL, &search.iter, &search.chain, (void **)&node, NULL); + if (result != ISC_R_NOTFOUND) { + dns_name_copy(&node->name, foundname); + } /* * Check the QP chain to see if there's a node above us with a @@ -3404,10 +3407,11 @@ find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, tresult = check_zonecut(n, &search DNS__DB_FLARG_PASS); if (tresult != DNS_R_CONTINUE) { result = tresult; - dns_qpchain_node(&search.chain, i, foundname, NULL, - NULL); search.chain.len = i - 1; node = n; + if (foundname != NULL) { + dns_name_copy(&node->name, foundname); + } } }