Commit 1a635b54 authored by Michał Kępień's avatar Michał Kępień Committed by Ondřej Surý
Browse files

Make async hooks code use the 'recursions' array

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.
parent 435b4eee
......@@ -174,7 +174,6 @@ struct ns_client {
isc_nmhandle_t *sendhandle; /* Waiting for send callback */
isc_nmhandle_t *reqhandle; /* Waiting for request callback
(query, update, notify) */
isc_nmhandle_t *fetchhandle; /* Waiting for recursive fetch */
isc_nmhandle_t *updatehandle; /* Waiting for update callback */
unsigned char *tcpbuf;
dns_message_t *message;
......
......@@ -46,6 +46,7 @@ typedef enum {
RECTYPE_NORMAL,
RECTYPE_PREFETCH,
RECTYPE_RPZ,
RECTYPE_HOOK,
RECTYPE_COUNT,
} ns_query_rectype_t;
......@@ -77,7 +78,6 @@ struct ns_query {
bool authdbset;
bool isreferral;
isc_mutex_t fetchlock;
dns_fetch_t *fetch;
ns_hookasync_t *hookactx;
dns_rpz_st_t *rpz_st;
isc_bufferlist_t namebufs;
......
......@@ -6799,12 +6799,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(&client->query.recursions[RECTYPE_HOOK].handle);
client->state = NS_CLIENTSTATE_WORKING;
......@@ -6920,7 +6919,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(client->query.recursions[RECTYPE_NORMAL].fetch == NULL);
result = check_recursionquota(client);
if (result != ISC_R_SUCCESS) {
......@@ -6946,12 +6945,12 @@ 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,
&client->query.recursions[RECTYPE_HOOK].handle);
return (ISC_R_SUCCESS);
cleanup:
......
......@@ -723,11 +723,12 @@ 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(qctx->client->query.recursions[RECTYPE_HOOK].handle ==
NULL);
asdata->async = false;
switch (hookpoint) {
case NS_QUERY_GOT_ANSWER_BEGIN:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment