From 0fd787c8b895e785c25a048036a3d33ed176d38c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Tue, 14 Jun 2022 13:13:32 +0200 Subject: [PATCH] Enable ns_query_t to track multiple recursions When a client waits for a prefetch- or RPZ-triggered recursion to complete, its netmgr handle is attached to client->prefetchhandle and a reference to the resolver fetch is stored in client->query.prefetch. Both of these features use the same fields mentioned above. This makes the code fragile and hard to follow as its logically distinct parts become intertwined for no obvious reason. Furthermore, storing pointers related to a specific recursion process in two different structures makes their purpose harder to grasp than it has to be. To alleviate the problem, extend ns_query_t with an array of structures containing recursion-related pointers. Each feature able to initiate recursion is supposed to use its own slot in that array, allowing logically unrelated code paths to be untangled. Prefetch and RPZ will be the first users of that array. Define helper macros for accessing specific recursion-related pointers in order to improve code readability. --- lib/ns/include/ns/query.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/ns/include/ns/query.h b/lib/ns/include/ns/query.h index a1851abc1e..8476705386 100644 --- a/lib/ns/include/ns/query.h +++ b/lib/ns/include/ns/query.h @@ -38,6 +38,34 @@ typedef struct ns_dbversion { ISC_LINK(struct ns_dbversion) link; } ns_dbversion_t; +/*% + * recursion type; various features can initiate recursion and this enum value + * allows common code paths to differentiate between them + */ +typedef enum { + RECTYPE_PREFETCH, + RECTYPE_RPZ, + RECTYPE_COUNT, +} ns_query_rectype_t; + +/*% + * Helper macros for accessing isc_nmhandle_t pointers for a specific recursion + * a given client is associated with. + */ +#define HANDLE_RECTYPE_PREFETCH(client) \ + ((client)->query.recursions[RECTYPE_PREFETCH].handle) +#define HANDLE_RECTYPE_RPZ(client) \ + ((client)->query.recursions[RECTYPE_RPZ].handle) + +/*% + * Helper macros for accessing dns_fetch_t pointers for a specific recursion a + * given client is associated with. + */ +#define FETCH_RECTYPE_PREFETCH(client) \ + ((client)->query.recursions[RECTYPE_PREFETCH].fetch) +#define FETCH_RECTYPE_RPZ(client) \ + ((client)->query.recursions[RECTYPE_RPZ].fetch) + /*% * nameserver recursion parameters, to uniquely identify a recursion * query; this is used to detect a recursion loop @@ -94,6 +122,11 @@ struct ns_query { bool is_zone; } redirect; + struct { + isc_nmhandle_t *handle; + dns_fetch_t *fetch; + } recursions[RECTYPE_COUNT]; + ns_query_recparam_t recparam; dns_keytag_t root_key_sentinel_keyid;