2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 13:08:06 +00:00

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.
This commit is contained in:
Michał Kępień 2022-06-14 13:13:32 +02:00
parent 76070fbf33
commit 0fd787c8b8

View File

@ -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;