From: Mark Andrews Date: Wed, 28 Feb 2024 07:01:55 +0000 (+1100) Subject: Don't use static stub when returning best NS X-Git-Tag: v9.19.23~38^2~2 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=40816e4e35a413d3241fed794afc16ce6db06c76;p=thirdparty%2Fbind9.git Don't use static stub when returning best NS If we find a static stub zone in query_addbestns look for a parent zone which isn't a static stub. --- diff --git a/lib/ns/query.c b/lib/ns/query.c index efe33a9dd9b..27573870de3 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -10908,20 +10908,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: /*