]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
update hooks tests to use NS_QUERY_RESET
authorColin Vidal <colin@isc.org>
Mon, 8 Sep 2025 08:12:29 +0000 (10:12 +0200)
committerColin Vidal <colin@isc.org>
Tue, 9 Sep 2025 07:42:34 +0000 (09:42 +0200)
Update hooks-related unit tests since the removal of
NS_QUERY_QCTX_DESTROY and the introduction of NS_QUERY_RESET hook. This
also simplifies (a bit) the plugin usage as NS_QUERY_RESET is _always_
called when the client plugin is about to be freed from memory.

bin/plugins/filter-a.c
bin/plugins/filter-aaaa.c
bin/tests/system/hooks/driver/test-async.c
tests/ns/query_test.c

index 7ff8048cde694618ad0f64c459cacc5d1b1b0551..e850739730462cf428a57925bcdc70cb354e6838 100644 (file)
@@ -115,7 +115,7 @@ filter_prep_response_begin(void *arg, void *cbdata, isc_result_t *resp);
 static ns_hookresult_t
 filter_query_done_send(void *arg, void *cbdata, isc_result_t *resp);
 static ns_hookresult_t
-filter_qctx_destroy(void *arg, void *cbdata, isc_result_t *resp);
+filter_freeclientstate(void *arg, void *cbdata, isc_result_t *resp);
 
 /*%
  * Register the functions to be called at each hook point in 'hooktable', using
@@ -151,12 +151,12 @@ install_hooks(ns_hooktable_t *hooktable, isc_mem_t *mctx,
                .action_data = inst,
        };
 
-       const ns_hook_t filter_destroy = {
-               .action = filter_qctx_destroy,
+       const ns_hook_t filter_reset = {
+               .action = filter_freeclientstate,
                .action_data = inst,
        };
 
-       ns_hook_add(hooktable, mctx, NS_QUERY_QCTX_INITIALIZED, &filter_init);
+       ns_hook_add(hooktable, mctx, NS_QUERY_SETUP, &filter_init);
        ns_hook_add(hooktable, mctx, NS_QUERY_AUTHZONE_ATTACHED, &filter_init);
        ns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_BEGIN, &filter_respbegin);
        ns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_ANY_FOUND,
@@ -164,7 +164,7 @@ install_hooks(ns_hooktable_t *hooktable, isc_mem_t *mctx,
        ns_hook_add(hooktable, mctx, NS_QUERY_PREP_RESPONSE_BEGIN,
                    &filter_prepresp);
        ns_hook_add(hooktable, mctx, NS_QUERY_DONE_SEND, &filter_donesend);
-       ns_hook_add(hooktable, mctx, NS_QUERY_QCTX_DESTROYED, &filter_destroy);
+       ns_hook_add(hooktable, mctx, NS_QUERY_RESET, &filter_reset);
 }
 
 /**
@@ -862,16 +862,11 @@ filter_query_done_send(void *arg, void *cbdata, isc_result_t *resp) {
  * from hash table and return it to the memory pool.
  */
 static ns_hookresult_t
-filter_qctx_destroy(void *arg, void *cbdata, isc_result_t *resp) {
+filter_freeclientstate(void *arg, void *cbdata, isc_result_t *resp) {
        query_ctx_t *qctx = (query_ctx_t *)arg;
        filter_instance_t *inst = (filter_instance_t *)cbdata;
 
        *resp = ISC_R_UNSET;
-
-       if (!qctx->detach_client) {
-               return NS_HOOK_CONTINUE;
-       }
-
        client_state_destroy(qctx, inst);
 
        return NS_HOOK_CONTINUE;
index b5d58a564090354b1e16fa60c2a208c7a77c5773..3a0dc1a98c6c50fbfc83320e77d5856c71fae65f 100644 (file)
@@ -115,7 +115,7 @@ filter_prep_response_begin(void *arg, void *cbdata, isc_result_t *resp);
 static ns_hookresult_t
 filter_query_done_send(void *arg, void *cbdata, isc_result_t *resp);
 static ns_hookresult_t
-filter_qctx_destroy(void *arg, void *cbdata, isc_result_t *resp);
+filter_freeclientstate(void *arg, void *cbdata, isc_result_t *resp);
 
 /*%
  * Register the functions to be called at each hook point in 'hooktable', using
@@ -151,12 +151,12 @@ install_hooks(ns_hooktable_t *hooktable, isc_mem_t *mctx,
                .action_data = inst,
        };
 
-       const ns_hook_t filter_destroy = {
-               .action = filter_qctx_destroy,
+       const ns_hook_t filter_reset = {
+               .action = filter_freeclientstate,
                .action_data = inst,
        };
 
-       ns_hook_add(hooktable, mctx, NS_QUERY_QCTX_INITIALIZED, &filter_init);
+       ns_hook_add(hooktable, mctx, NS_QUERY_SETUP, &filter_init);
        ns_hook_add(hooktable, mctx, NS_QUERY_AUTHZONE_ATTACHED, &filter_init);
        ns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_BEGIN, &filter_respbegin);
        ns_hook_add(hooktable, mctx, NS_QUERY_RESPOND_ANY_FOUND,
@@ -164,7 +164,7 @@ install_hooks(ns_hooktable_t *hooktable, isc_mem_t *mctx,
        ns_hook_add(hooktable, mctx, NS_QUERY_PREP_RESPONSE_BEGIN,
                    &filter_prepresp);
        ns_hook_add(hooktable, mctx, NS_QUERY_DONE_SEND, &filter_donesend);
-       ns_hook_add(hooktable, mctx, NS_QUERY_QCTX_DESTROYED, &filter_destroy);
+       ns_hook_add(hooktable, mctx, NS_QUERY_RESET, &filter_reset);
 }
 
 /**
@@ -865,16 +865,11 @@ filter_query_done_send(void *arg, void *cbdata, isc_result_t *resp) {
  * from hash table and return it to the memory pool.
  */
 static ns_hookresult_t
-filter_qctx_destroy(void *arg, void *cbdata, isc_result_t *resp) {
+filter_freeclientstate(void *arg, void *cbdata, isc_result_t *resp) {
        query_ctx_t *qctx = (query_ctx_t *)arg;
        filter_instance_t *inst = (filter_instance_t *)cbdata;
 
        *resp = ISC_R_UNSET;
-
-       if (!qctx->detach_client) {
-               return NS_HOOK_CONTINUE;
-       }
-
        client_state_destroy(qctx, inst);
 
        return NS_HOOK_CONTINUE;
index 4cc8ef79431ef38e5395f5704dc51bc70ef68e9d..0e7158be8564262696e853371eb37ef5263fa6de 100644 (file)
@@ -66,11 +66,11 @@ typedef struct state {
  * Forward declarations of functions referenced in install_hooks().
  */
 static ns_hookresult_t
-async_qctx_initialize(void *arg, void *cbdata, isc_result_t *resp);
+async_query_setup(void *arg, void *cbdata, isc_result_t *resp);
 static ns_hookresult_t
 async_query_done_begin(void *arg, void *cbdata, isc_result_t *resp);
 static ns_hookresult_t
-async_qctx_destroy(void *arg, void *cbdata, isc_result_t *resp);
+async_query_reset(void *arg, void *cbdata, isc_result_t *resp);
 
 /*%
  * Register the functions to be called at each hook point in 'hooktable', using
@@ -81,22 +81,22 @@ async_qctx_destroy(void *arg, void *cbdata, isc_result_t *resp);
 static void
 install_hooks(ns_hooktable_t *hooktable, isc_mem_t *mctx,
              async_instance_t *inst) {
-       const ns_hook_t async_init = {
-               .action = async_qctx_initialize,
+       const ns_hook_t async_setup = {
+               .action = async_query_setup,
                .action_data = inst,
        };
        const ns_hook_t async_donebegin = {
                .action = async_query_done_begin,
                .action_data = inst,
        };
-       const ns_hook_t async_destroy = {
-               .action = async_qctx_destroy,
+       const ns_hook_t async_reset = {
+               .action = async_query_reset,
                .action_data = inst,
        };
 
-       ns_hook_add(hooktable, mctx, NS_QUERY_QCTX_INITIALIZED, &async_init);
+       ns_hook_add(hooktable, mctx, NS_QUERY_SETUP, &async_setup);
        ns_hook_add(hooktable, mctx, NS_QUERY_DONE_BEGIN, &async_donebegin);
-       ns_hook_add(hooktable, mctx, NS_QUERY_QCTX_DESTROYED, &async_destroy);
+       ns_hook_add(hooktable, mctx, NS_QUERY_RESET, &async_reset);
 }
 
 static void
@@ -242,12 +242,12 @@ client_state_destroy(const query_ctx_t *qctx, async_instance_t *inst) {
 }
 
 static ns_hookresult_t
-async_qctx_initialize(void *arg, void *cbdata, isc_result_t *resp) {
+async_query_setup(void *arg, void *cbdata, isc_result_t *resp) {
        query_ctx_t *qctx = (query_ctx_t *)arg;
        async_instance_t *inst = (async_instance_t *)cbdata;
        state_t *state = NULL;
 
-       logmsg("qctx init hook");
+       logmsg("query setup hook");
        *resp = ISC_R_UNSET;
 
        state = client_state_get(qctx, inst);
@@ -330,17 +330,12 @@ async_query_done_begin(void *arg, void *cbdata, isc_result_t *resp) {
 }
 
 static ns_hookresult_t
-async_qctx_destroy(void *arg, void *cbdata, isc_result_t *resp) {
+async_query_reset(void *arg, void *cbdata, isc_result_t *resp) {
        query_ctx_t *qctx = (query_ctx_t *)arg;
        async_instance_t *inst = (async_instance_t *)cbdata;
 
-       logmsg("qctx destroy hook");
+       logmsg("query reset hook");
        *resp = ISC_R_UNSET;
-
-       if (!qctx->detach_client) {
-               return NS_HOOK_CONTINUE;
-       }
-
        client_state_destroy(qctx, inst);
 
        return NS_HOOK_CONTINUE;
index 84f4f36704ed4e50404e00bcc5387876c13af390..251d422cd1e43e769e39c1a1e0873e9e7376c602 100644 (file)
@@ -828,20 +828,6 @@ hook_async_query_done_begin(void *arg, void *data, isc_result_t *resultp) {
        return hook_async_common(arg, data, resultp, NS_QUERY_DONE_BEGIN);
 }
 
-/*
- * hook on destroying actx.  Can't be used for async event, but we use this
- * to remember the qctx at that point.
- */
-static ns_hookresult_t
-ns_test_qctx_destroy_hook(void *arg, void *data, isc_result_t *resultp) {
-       query_ctx_t *qctx = arg;
-       hookasync_data_t *asdata = data;
-
-       asdata->qctx = *qctx; /* remember passed ctx for inspection */
-       *resultp = ISC_R_UNSET;
-       return NS_HOOK_CONTINUE;
-}
-
 static void
 run_hookasync_test(const ns__query_hookasync_test_params_t *test) {
        query_ctx_t *qctx = NULL;
@@ -856,10 +842,6 @@ run_hookasync_test(const ns__query_hookasync_test_params_t *test) {
                .action = test->action,
                .action_data = &asdata,
        };
-       const ns_hook_t destroyhook = {
-               .action = ns_test_qctx_destroy_hook,
-               .action_data = &asdata,
-       };
        isc_statscounter_t srvfail_cnt;
        bool expect_servfail = false;
 
@@ -880,8 +862,6 @@ run_hookasync_test(const ns__query_hookasync_test_params_t *test) {
                ns_hook_add(ns__hook_table, isc_g_mctx, test->hookpoint2,
                            &testhook);
        }
-       ns_hook_add(ns__hook_table, isc_g_mctx, NS_QUERY_QCTX_DESTROYED,
-                   &destroyhook);
 
        {
                const ns_test_qctx_create_params_t qctx_params = {
@@ -972,18 +952,11 @@ run_hookasync_test(const ns__query_hookasync_test_params_t *test) {
 
        /*
         * Confirm SERVFAIL has been sent if it was expected.
-        * Also, the last-generated qctx should have detach_client being true.
         */
        if (expect_servfail) {
                INSIST(ns_stats_get_counter(
                               qctx->client->manager->sctx->nsstats,
                               ns_statscounter_servfail) == srvfail_cnt + 1);
-               if (test->do_cancel) {
-                       /* qctx was created on resume and copied in hook */
-                       INSIST(asdata.qctx.detach_client);
-               } else {
-                       INSIST(qctx->detach_client);
-               }
        }
 
        /*