]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make async hooks code use the 'recursions' array
authorMichał Kępień <michal@isc.org>
Tue, 14 Jun 2022 11:13:32 +0000 (13:13 +0200)
committerMichał Kępień <michal@isc.org>
Tue, 14 Jun 2022 11:13:32 +0000 (13:13 +0200)
Async hooks are the last feature using the client->fetchhandle and
client->query.fetch pointers.  Update ns_query_hookasync() and
query_hookresume() so that they use a dedicated slot in the 'recursions'
array.  Note that async hooks are still not expected to initiate
recursion if one was already started by a prior ns_query_recurse() call,
so the REQUIRE assertion in ns_query_hookasync() needs to check the
RECTYPE_NORMAL slot rather than the RECTYPE_HOOK one.

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

index 67b008c7fa62363ccaa969312704d10f0e72ca51..321e83eecaf4bd13adc5b890774a137e25d5a649 100644 (file)
@@ -46,6 +46,7 @@ typedef enum {
        RECTYPE_NORMAL,
        RECTYPE_PREFETCH,
        RECTYPE_RPZ,
+       RECTYPE_HOOK,
        RECTYPE_COUNT,
 } ns_query_rectype_t;
 
@@ -59,6 +60,8 @@ typedef enum {
        ((client)->query.recursions[RECTYPE_PREFETCH].handle)
 #define HANDLE_RECTYPE_RPZ(client) \
        ((client)->query.recursions[RECTYPE_RPZ].handle)
+#define HANDLE_RECTYPE_HOOK(client) \
+       ((client)->query.recursions[RECTYPE_HOOK].handle)
 
 /*%
  * Helper macros for accessing dns_fetch_t pointers for a specific recursion a
@@ -70,6 +73,8 @@ typedef enum {
        ((client)->query.recursions[RECTYPE_PREFETCH].fetch)
 #define FETCH_RECTYPE_RPZ(client) \
        ((client)->query.recursions[RECTYPE_RPZ].fetch)
+#define FETCH_RECTYPE_HOOK(client) \
+       ((client)->query.recursions[RECTYPE_HOOK].fetch)
 
 /*%
  * nameserver recursion parameters, to uniquely identify a recursion
index e2e55a243fdd7492e1a4a48e9d7d0f0141847015..17bfcd3ee7fd4bde1874516ec8bceb20ce11d9ea 100644 (file)
@@ -6693,12 +6693,11 @@ query_hookresume(isc_task_t *task, isc_event_t *event) {
        UNLOCK(&client->manager->reclock);
 
        /*
-        * This event is running under a client task, so it's safe to detach
-        * the fetch handle.  And it should be done before resuming query
-        * processing below, since that may trigger another recursion or
-        * asynchronous hook event.
+        * The fetch handle should be detached before resuming query processing
+        * below, since that may trigger another recursion or asynchronous hook
+        * event.
         */
-       isc_nmhandle_detach(&client->fetchhandle);
+       isc_nmhandle_detach(&HANDLE_RECTYPE_HOOK(client));
 
        client->state = NS_CLIENTSTATE_WORKING;
 
@@ -6814,7 +6813,7 @@ ns_query_hookasync(query_ctx_t *qctx, ns_query_starthookasync_t runasync,
 
        REQUIRE(NS_CLIENT_VALID(client));
        REQUIRE(client->query.hookactx == NULL);
-       REQUIRE(client->query.fetch == NULL);
+       REQUIRE(FETCH_RECTYPE_NORMAL(client) == NULL);
 
        result = check_recursionquota(client);
        if (result != ISC_R_SUCCESS) {
@@ -6837,12 +6836,11 @@ ns_query_hookasync(query_ctx_t *qctx, ns_query_starthookasync_t runasync,
         * attribute won't be checked anywhere.
         *
         * Hook-based asynchronous processing cannot coincide with normal
-        * recursion, so we can safely use fetchhandle here.  Unlike in
-        * ns_query_recurse(), we attach to the handle only if 'runasync'
-        * succeeds. It should be safe since we're either in the client
-        * task or pausing it.
+        * recursion.  Unlike in ns_query_recurse(), we attach to the handle
+        * only if 'runasync' succeeds. It should be safe since we're either in
+        * the client task or pausing it.
         */
-       isc_nmhandle_attach(client->handle, &client->fetchhandle);
+       isc_nmhandle_attach(client->handle, &HANDLE_RECTYPE_HOOK(client));
        return (ISC_R_SUCCESS);
 
 cleanup:
index dda2c07150dd3d68d4db9bbcb4a5fdae580a9b08..5636801b142b96d9c5afb67690434f7e814762e5 100644 (file)
@@ -709,11 +709,11 @@ hook_async_common(void *arg, void *data, isc_result_t *resultp,
                }
        } else {
                /*
-                * Resume from the completion of async event.
-                * fetchhandle should have been detached so that we can start
-                * another async event or DNS recursive resolution.
+                * Resume from the completion of async event.  The fetch handle
+                * should have been detached so that we can start another async
+                * event or DNS recursive resolution.
                 */
-               INSIST(qctx->client->fetchhandle == NULL);
+               INSIST(HANDLE_RECTYPE_HOOK(qctx->client) == NULL);
                asdata->async = false;
                switch (hookpoint) {
                case NS_QUERY_GOT_ANSWER_BEGIN: