]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
findzonecut: helper function for cache lookup
authorColin Vidal <colin@isc.org>
Tue, 16 Dec 2025 13:22:10 +0000 (14:22 +0100)
committerColin Vidal <colin@isc.org>
Thu, 8 Jan 2026 19:26:32 +0000 (20:26 +0100)
Extract the cache lookup implementation from `dns_view_findzonecut()`
into a separate helper function.

Also, when the cache result is not ISC_R_SUCCESS (which is the only
"success" value from the existing code in this case), the return value
is overriden to DNS_R_NXDOMAIN. This enables the caller (in follow-up
commit) to differentiate the case where a zone is found, but for
whatever reason, no delegation is in there, from the case where no zone
is found. Separating those cases enables the caller to know whether it
needs to hit the cache/hints or not.

lib/dns/view.c

index 40b473dd4a8baea8c3f7e90063de3c69667f84c5..276acd3c083ced9bff5e0367325e9595bd57d4b6 100644 (file)
@@ -983,6 +983,32 @@ dns_view_simplefind(dns_view_t *view, const dns_name_t *name,
        return result;
 }
 
+static isc_result_t
+findzonecut_cache(dns_view_t *view, const dns_name_t *name, dns_name_t *fname,
+                 dns_name_t *dcname, isc_stdtime_t now, unsigned int options,
+                 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset) {
+       isc_result_t result = DNS_R_NXDOMAIN;
+
+       if (view->cachedb != NULL) {
+               result = dns_db_findzonecut(view->cachedb, name, options, now,
+                                           NULL, fname, dcname, rdataset,
+                                           sigrdataset);
+       }
+
+       /*
+        * Cache miss returns ISC_R_NOTFOUND, but to not confuse it
+        * with a zone found without delegation matching `name` (nor partial),
+        * keep DNS_R_NXDOMAIN, so the hints can be checked.
+        */
+       if (result != ISC_R_SUCCESS) {
+               dns_rdataset_cleanup(rdataset);
+               dns_rdataset_cleanup(sigrdataset);
+               result = DNS_R_NXDOMAIN;
+       }
+
+       return result;
+}
+
 static isc_result_t
 findzonecut_hints(dns_view_t *view, dns_name_t *fname, dns_name_t *dcname,
                  isc_stdtime_t now, dns_rdataset_t *rdataset) {
@@ -1114,8 +1140,8 @@ db_find:
                        goto db_find;
                }
        } else {
-               result = dns_db_findzonecut(db, name, options, now, NULL, fname,
-                                           dcname, rdataset, sigrdataset);
+               result = findzonecut_cache(view, name, fname, dcname, now,
+                                          options, rdataset, sigrdataset);
                if (result == ISC_R_SUCCESS) {
                        if (zfname != NULL &&
                            (!dns_name_issubdomain(fname, zfname) ||
@@ -1128,7 +1154,7 @@ db_find:
                                 */
                                use_zone = true;
                        }
-               } else if (result == ISC_R_NOTFOUND) {
+               } else if (result == DNS_R_NXDOMAIN) {
                        if (zfname != NULL) {
                                /*
                                 * We didn't find anything in the cache, but we
@@ -1142,8 +1168,6 @@ db_find:
                                 */
                                try_hints = true;
                                result = ISC_R_SUCCESS;
-                       } else {
-                               result = DNS_R_NXDOMAIN;
                        }
                } else {
                        /*