From: Colin Vidal Date: Mon, 8 Sep 2025 08:12:29 +0000 (+0200) Subject: update hooks tests to use NS_QUERY_RESET X-Git-Tag: v9.21.14~56^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=125e3832bc35bc788a19176ac01966832ff7cd66;p=thirdparty%2Fbind9.git update hooks tests to use NS_QUERY_RESET 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. --- diff --git a/bin/plugins/filter-a.c b/bin/plugins/filter-a.c index 7ff8048cde6..e8507397304 100644 --- a/bin/plugins/filter-a.c +++ b/bin/plugins/filter-a.c @@ -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; diff --git a/bin/plugins/filter-aaaa.c b/bin/plugins/filter-aaaa.c index b5d58a56409..3a0dc1a98c6 100644 --- a/bin/plugins/filter-aaaa.c +++ b/bin/plugins/filter-aaaa.c @@ -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; diff --git a/bin/tests/system/hooks/driver/test-async.c b/bin/tests/system/hooks/driver/test-async.c index 4cc8ef79431..0e7158be856 100644 --- a/bin/tests/system/hooks/driver/test-async.c +++ b/bin/tests/system/hooks/driver/test-async.c @@ -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; diff --git a/tests/ns/query_test.c b/tests/ns/query_test.c index 84f4f36704e..251d422cd1e 100644 --- a/tests/ns/query_test.c +++ b/tests/ns/query_test.c @@ -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); - } } /*