]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
use dns_qp_getname() where possible
authorEvan Hunt <each@isc.org>
Thu, 11 Apr 2024 17:00:22 +0000 (10:00 -0700)
committerEvan Hunt <each@isc.org>
Tue, 30 Apr 2024 19:50:01 +0000 (12:50 -0700)
some calls to dns_qp_lookup() do not need partial matches, QP chains
or QP iterators. in these cases it's more efficient to use
dns_qp_getname().

lib/dns/qpcache.c
lib/dns/zt.c

index 3c5c7afe8f414d72848516dce08d8e8c600aaa1f..879496a6d3f926015d37ef0bd53101b93a9f54bb 100644 (file)
@@ -1499,10 +1499,10 @@ 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, NULL, NULL,
-                              NULL, (void **)&node, NULL);
+       result = dns_qp_getname(search->qpdb->tree, predecessor, (void **)&node,
+                               NULL);
        if (result != ISC_R_SUCCESS) {
-               return (ISC_R_NOTFOUND);
+               return (result);
        }
        dns_name_copy(&node->name, fname);
 
@@ -2793,21 +2793,16 @@ findnode(dns_db_t *db, const dns_name_t *name, bool create,
        isc_rwlocktype_t tlocktype = isc_rwlocktype_none;
 
        TREE_RDLOCK(&qpdb->tree_lock, &tlocktype);
-       result = dns_qp_lookup(qpdb->tree, name, NULL, NULL, NULL,
-                              (void **)&node, NULL);
+       result = dns_qp_getname(qpdb->tree, name, (void **)&node, NULL);
        if (result != ISC_R_SUCCESS) {
                if (!create) {
-                       if (result == DNS_R_PARTIALMATCH) {
-                               result = ISC_R_NOTFOUND;
-                       }
                        goto unlock;
                }
                /*
                 * Try to upgrade the lock and if that fails unlock then relock.
                 */
                TREE_FORCEUPGRADE(&qpdb->tree_lock, &tlocktype);
-               result = dns_qp_lookup(qpdb->tree, name, NULL, NULL, NULL,
-                                      (void **)&node, NULL);
+               result = dns_qp_getname(qpdb->tree, name, (void **)&node, NULL);
                if (result != ISC_R_SUCCESS) {
                        node = new_qpcnode(qpdb, name);
                        result = dns_qp_insert(qpdb->tree, node, 0);
index 7f1b4160234701f811d21094aa21cdc89ca646a7..edcb86ce18ddd5fd3182871886a746a86f760dce 100644 (file)
@@ -178,17 +178,22 @@ dns_zt_find(dns_zt_t *zt, const dns_name_t *name, dns_ztfind_t options,
 
        dns_qpmulti_query(zt->multi, &qpr);
 
-       result = dns_qp_lookup(&qpr, name, NULL, NULL, &chain, &pval, NULL);
-       if (exactopts == DNS_ZTFIND_EXACT && result == DNS_R_PARTIALMATCH) {
-               result = ISC_R_NOTFOUND;
-       } else if (exactopts == DNS_ZTFIND_NOEXACT && result == ISC_R_SUCCESS) {
-               /* get pval from the previous chain link */
-               int len = dns_qpchain_length(&chain);
-               if (len >= 2) {
-                       dns_qpchain_node(&chain, len - 2, NULL, &pval, NULL);
-                       result = DNS_R_PARTIALMATCH;
-               } else {
-                       result = ISC_R_NOTFOUND;
+       if (exactopts == DNS_ZTFIND_EXACT) {
+               result = dns_qp_getname(&qpr, name, &pval, NULL);
+       } else {
+               result = dns_qp_lookup(&qpr, name, NULL, NULL, &chain, &pval,
+                                      NULL);
+               if (exactopts == DNS_ZTFIND_NOEXACT && result == ISC_R_SUCCESS)
+               {
+                       /* get pval from the previous chain link */
+                       int len = dns_qpchain_length(&chain);
+                       if (len >= 2) {
+                               dns_qpchain_node(&chain, len - 2, NULL, &pval,
+                                                NULL);
+                               result = DNS_R_PARTIALMATCH;
+                       } else {
+                               result = ISC_R_NOTFOUND;
+                       }
                }
        }
        dns_qpread_destroy(zt->multi, &qpr);