From: Alessio Podda Date: Mon, 6 Jul 2026 08:26:31 +0000 (+0200) Subject: Turn authdb into a enum X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=3450c28fe63643e4ffc4e236ff44dd8f14f4713a;p=thirdparty%2Fbind9.git Turn authdb into a enum Given that now authdb is now an integer id, we can fold the authdb variable into it by turning it into a sentinel value. --- diff --git a/lib/ns/include/ns/query.h b/lib/ns/include/ns/query.h index c6eb341391c..fe566f71b65 100644 --- a/lib/ns/include/ns/query.h +++ b/lib/ns/include/ns/query.h @@ -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; diff --git a/lib/ns/query.c b/lib/ns/query.c index 9e675084dc5..a695ff5ca6f 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -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;