]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
get foundname from the node
authorEvan Hunt <each@isc.org>
Thu, 11 Apr 2024 03:48:24 +0000 (23:48 -0400)
committerEvan Hunt <each@isc.org>
Tue, 30 Apr 2024 19:50:01 +0000 (12:50 -0700)
when calling dns_qp_lookup() from qpcache, instead of passing
'foundname' so that a name would be constructed from the QP key,
we now just use the name field in the node data. this makes
dns_qp_lookup() run faster.

the same optimization has also been added to qpzone.

the documentation for dns_qp_lookup() has been updated to
discuss this performance consideration.

lib/dns/include/dns/qp.h
lib/dns/nametree.c
lib/dns/qpcache.c
lib/dns/qpzone.c

index 236d63faaf00986e81449c656f1d4de3f5007926..e2dbb71afadcee00a265aa94d85c3b2e064d1401 100644 (file)
@@ -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
index 77ecd309b8b9965dea08591b124decfc696f1890..24c51d504c32eb230b65fa2e6d6b351b195529f1 100644 (file)
@@ -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;
index 647b54bdc42b5172766dac9ef15a29c850bfe670..3c5c7afe8f414d72848516dce08d8e8c600aaa1f 100644 (file)
@@ -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) {
index a570a5c91824fe908cf669317fdd294099731db8..9f66d5469209f8c950f3e4e6be53678e0c23462e 100644 (file)
@@ -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);
+                       }
                }
        }