]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Turn authdb into a enum
authorAlessio Podda <alessio@isc.org>
Mon, 6 Jul 2026 08:26:31 +0000 (10:26 +0200)
committerAlessio Podda <alessio@isc.org>
Fri, 17 Jul 2026 11:48:46 +0000 (11:48 +0000)
Given that now authdb is now an integer id, we can fold the authdb
variable into it by turning it into a sentinel value.

lib/ns/include/ns/query.h
lib/ns/query.c

index c6eb341391c867c88d34148c5019b45141dfbf3a..fe566f71b652d4a555d2df283bceea817a980860 100644 (file)
@@ -47,6 +47,9 @@ typedef struct dns_getdb_options {
        bool stalefirst : 1;
 } dns_getdb_options_t;
 
+#define NS_QUERY_AUTHDB_UNSET ((uintptr_t)0)
+#define NS_QUERY_AUTHDB_NONE  UINTPTR_MAX
+
 /*%
  * recursion type; various features can initiate recursion and this enum value
  * allows common code paths to differentiate between them
@@ -137,11 +140,10 @@ struct ns_query {
        unsigned int    dboptions;
        unsigned int    fetchoptions;
        dns_db_t       *gluedb;
-       uintptr_t   authdb; /* Database identity; not an attached reference. */
-       dns_zone_t *authzone;
-       bool        authdbset;
-       bool        isreferral;
-       isc_mutex_t fetchlock;
+       uintptr_t authdb_id; /* Database identity; not an attached reference. */
+       dns_zone_t      *authzone;
+       bool             isreferral;
+       isc_mutex_t      fetchlock;
        ns_hookasync_t  *hookasyncctx;
        dns_rpz_st_t    *rpz_st;
        isc_bufferlist_t namebufs;
index 9e675084dc5ae263ada342b936241eda4ae2e96d..a695ff5ca6fab40c458869d9ba8e84d771b803dc 100644 (file)
@@ -821,8 +821,7 @@ query_reset(ns_client_t *client, bool everything) {
        client->query.dboptions = 0;
        client->query.fetchoptions = 0;
        client->query.gluedb = NULL;
-       client->query.authdb = 0;
-       client->query.authdbset = false;
+       client->query.authdb_id = NS_QUERY_AUTHDB_UNSET;
        client->query.isreferral = false;
        client->query.dns64_options = 0;
        client->query.dns64_ttl = UINT32_MAX;
@@ -1010,7 +1009,8 @@ query_validatezonedb(ns_client_t *client, const dns_name_t *name,
         */
        if (client->query.rpz_st == NULL &&
            !(client->query.wantrecursion && client->query.recursionok) &&
-           client->query.authdbset && (uintptr_t)db != client->query.authdb)
+           client->query.authdb_id != NS_QUERY_AUTHDB_UNSET &&
+           (uintptr_t)db != client->query.authdb_id)
        {
                return DNS_R_REFUSED;
        }
@@ -1659,11 +1659,7 @@ query_additionalauth(query_ctx_t *qctx, const dns_name_t *name,
         * First, look within the same zone database for authoritative
         * additional data.
         */
-       if (!client->query.authdbset || client->query.authdb == 0) {
-               return ISC_R_NOTFOUND;
-       }
-
-       dbversion = ns_client_findversionid(client, client->query.authdb);
+       dbversion = ns_client_findversionid(client, client->query.authdb_id);
        if (dbversion == NULL) {
                return ISC_R_NOTFOUND;
        }
@@ -4903,7 +4899,7 @@ query_trace(query_ctx_t *qctx) {
                 "origqname:%s, timer:%d, authdb:%d, referral:%d, id:%hu",
                 iabuf, qabuf, qctx->client->query.restarts, qbuf,
                 (int)qctx->client->query.timerset,
-                (int)qctx->client->query.authdbset,
+                (int)(qctx->client->query.authdb_id != NS_QUERY_AUTHDB_UNSET),
                 (int)qctx->client->query.isreferral,
                 qctx->client->message->id);
        CCTRACE(ISC_LOG_DEBUG(3), mbuf);
@@ -5313,21 +5309,19 @@ ns__query_start(query_ctx_t *qctx) {
         * Update query statistics.
         */
        if (qctx->fresp == NULL && qctx->client->query.restarts == 0) {
-               if (qctx->is_zone) {
-                       if (qctx->zone != NULL) {
-                               /*
-                                * if is_zone = true, zone = NULL then this is
-                                * a DLZ zone.  Don't attempt to attach zone.
-                                */
-                               dns_zone_attach(qctx->zone,
-                                               &qctx->client->query.authzone);
-                               qctx->zhooks =
-                                       dns_zone_gethooktable(qctx->zone);
-                               CALL_HOOK(NS_QUERY_AUTHZONE_ATTACHED, qctx);
-                       }
-                       qctx->client->query.authdb = (uintptr_t)qctx->db;
+               /*
+                * If this is a DLZ zone, qctx->is_zone is true but qctx->zone
+                * is NULL, so there is no zone object to attach.
+                */
+               if (qctx->is_zone && qctx->zone != NULL) {
+                       dns_zone_attach(qctx->zone,
+                                       &qctx->client->query.authzone);
+                       qctx->zhooks = dns_zone_gethooktable(qctx->zone);
+                       CALL_HOOK(NS_QUERY_AUTHZONE_ATTACHED, qctx);
                }
-               qctx->client->query.authdbset = true;
+               qctx->client->query.authdb_id = qctx->is_zone
+                                                       ? (uintptr_t)qctx->db
+                                                       : NS_QUERY_AUTHDB_NONE;
 
                isc_nmhandle_t *handle = qctx->client->inner.handle;