]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Don't use static stub when returning best NS
authorMark Andrews <marka@isc.org>
Wed, 28 Feb 2024 07:01:55 +0000 (18:01 +1100)
committerMark Andrews <marka@isc.org>
Thu, 14 Mar 2024 04:33:25 +0000 (15:33 +1100)
If we find a static stub zone in query_addbestns look for a parent
zone which isn't a static stub.

(cherry picked from commit 40816e4e35a413d3241fed794afc16ce6db06c76)

lib/ns/query.c

index 98de1be7f7d84709cff79de121c47b32fd9516ae..537d332a56d14fbf9a3f2dd2ef0d625ae35c75cd 100644 (file)
@@ -11246,20 +11246,49 @@ query_addbestns(query_ctx_t *qctx) {
        isc_buffer_t b;
        dns_clientinfomethods_t cm;
        dns_clientinfo_t ci;
+       dns_name_t qname;
 
        CTRACE(ISC_LOG_DEBUG(3), "query_addbestns");
 
        dns_clientinfomethods_init(&cm, ns_client_sourceip);
        dns_clientinfo_init(&ci, client, NULL);
 
+       dns_name_init(&qname, NULL);
+       dns_name_clone(client->query.qname, &qname);
+
        /*
         * Find the right database.
         */
-       result = query_getdb(client, client->query.qname, dns_rdatatype_ns, 0,
-                            &zone, &db, &version, &is_zone);
-       if (result != ISC_R_SUCCESS) {
-               goto cleanup;
-       }
+       do {
+               result = query_getdb(client, &qname, dns_rdatatype_ns, 0, &zone,
+                                    &db, &version, &is_zone);
+               if (result != ISC_R_SUCCESS) {
+                       goto cleanup;
+               }
+
+               /*
+                * If this is a static stub zone look for a parent zone.
+                */
+               if (zone != NULL &&
+                   dns_zone_gettype(zone) == dns_zone_staticstub)
+               {
+                       unsigned int labels = dns_name_countlabels(&qname);
+                       dns_db_detach(&db);
+                       dns_zone_detach(&zone);
+                       version = NULL;
+                       if (labels != 1) {
+                               dns_name_split(&qname, labels - 1, NULL,
+                                              &qname);
+                               continue;
+                       }
+                       if (!USECACHE(client)) {
+                               goto cleanup;
+                       }
+                       dns_db_attach(client->view->cachedb, &db);
+                       is_zone = false;
+               }
+               break;
+       } while (true);
 
 db_find:
        /*