2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

remove dns_client_request() and related code

continues the cleanup of dns_client started in the previous commit.
This commit is contained in:
Evan Hunt
2021-03-22 18:14:37 -07:00
committed by Ondřej Surý
parent fb2a352e7c
commit 1beb05f3e2
12 changed files with 1 additions and 1745 deletions

View File

@@ -56,9 +56,6 @@
#define RCTX_MAGIC ISC_MAGIC('R', 'c', 't', 'x')
#define RCTX_VALID(c) ISC_MAGIC_VALID(c, RCTX_MAGIC)
#define REQCTX_MAGIC ISC_MAGIC('R', 'q', 'c', 'x')
#define REQCTX_VALID(c) ISC_MAGIC_VALID(c, REQCTX_MAGIC)
#define UCTX_MAGIC ISC_MAGIC('U', 'c', 't', 'x')
#define UCTX_VALID(c) ISC_MAGIC_VALID(c, UCTX_MAGIC)
@@ -103,7 +100,6 @@ struct dns_client {
/* Locked */
dns_viewlist_t viewlist;
ISC_LIST(struct resctx) resctxs;
ISC_LIST(struct reqctx) reqctxs;
};
#define DEF_FIND_TIMEOUT 5
@@ -157,39 +153,6 @@ typedef struct resarg {
bool canceled;
} resarg_t;
/*%
* Internal state for a single DNS request
*/
typedef struct reqctx {
/* Unlocked */
unsigned int magic;
isc_mutex_t lock;
dns_client_t *client;
unsigned int parseoptions;
/* Locked */
ISC_LINK(struct reqctx) link;
bool canceled;
dns_tsigkey_t *tsigkey;
dns_request_t *request;
dns_clientreqevent_t *event;
} reqctx_t;
/*%
* Argument of an internal event for synchronous DNS request.
*/
typedef struct reqarg {
/* Unlocked */
isc_appctx_t *actx;
dns_client_t *client;
isc_mutex_t lock;
/* Locked */
isc_result_t result;
dns_clientreqtrans_t *trans;
bool canceled;
} reqarg_t;
static void
client_resfind(resctx_t *rctx, dns_fetchevent_t *event);
@@ -415,7 +378,6 @@ dns_client_createx(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
dns_view_freeze(view); /* too early? */
ISC_LIST_INIT(client->resctxs);
ISC_LIST_INIT(client->reqctxs);
client->mctx = NULL;
isc_mem_attach(mctx, &client->mctx);
@@ -1404,302 +1366,3 @@ cleanup:
}
return (result);
}
/*%
* Simple request routines
*/
static void
request_done(isc_task_t *task, isc_event_t *event) {
dns_requestevent_t *reqev = NULL;
dns_request_t *request;
isc_result_t result, eresult;
reqctx_t *ctx;
UNUSED(task);
REQUIRE(event->ev_type == DNS_EVENT_REQUESTDONE);
reqev = (dns_requestevent_t *)event;
request = reqev->request;
result = eresult = reqev->result;
ctx = reqev->ev_arg;
REQUIRE(REQCTX_VALID(ctx));
isc_event_free(&event);
LOCK(&ctx->lock);
if (eresult == ISC_R_SUCCESS) {
result = dns_request_getresponse(request, ctx->event->rmessage,
ctx->parseoptions);
}
if (ctx->tsigkey != NULL) {
dns_tsigkey_detach(&ctx->tsigkey);
}
if (ctx->canceled) {
ctx->event->result = ISC_R_CANCELED;
} else {
ctx->event->result = result;
}
task = ctx->event->ev_sender;
ctx->event->ev_sender = ctx;
isc_task_sendanddetach(&task, ISC_EVENT_PTR(&ctx->event));
UNLOCK(&ctx->lock);
}
static void
localrequest_done(isc_task_t *task, isc_event_t *event) {
reqarg_t *reqarg = event->ev_arg;
dns_clientreqevent_t *rev = (dns_clientreqevent_t *)event;
UNUSED(task);
REQUIRE(event->ev_type == DNS_EVENT_CLIENTREQDONE);
LOCK(&reqarg->lock);
reqarg->result = rev->result;
dns_client_destroyreqtrans(&reqarg->trans);
isc_event_free(&event);
if (!reqarg->canceled) {
UNLOCK(&reqarg->lock);
/* Exit from the internal event loop */
isc_app_ctxsuspend(reqarg->actx);
} else {
/*
* We have already exited from the loop (due to some
* unexpected event). Just clean the arg up.
*/
UNLOCK(&reqarg->lock);
isc_mutex_destroy(&reqarg->lock);
isc_mem_put(reqarg->client->mctx, reqarg, sizeof(*reqarg));
}
}
isc_result_t
dns_client_request(dns_client_t *client, dns_message_t *qmessage,
dns_message_t *rmessage, const isc_sockaddr_t *server,
unsigned int options, unsigned int parseoptions,
dns_tsec_t *tsec, unsigned int timeout,
unsigned int udptimeout, unsigned int udpretries) {
isc_appctx_t *actx;
reqarg_t *reqarg;
isc_result_t result;
REQUIRE(DNS_CLIENT_VALID(client));
REQUIRE(qmessage != NULL);
REQUIRE(rmessage != NULL);
if ((client->attributes & DNS_CLIENTATTR_OWNCTX) == 0 &&
(options & DNS_CLIENTREQOPT_ALLOWRUN) == 0)
{
/*
* If the client is run under application's control, we need
* to create a new running (sub)environment for this
* particular resolution.
*/
return (ISC_R_NOTIMPLEMENTED); /* XXXTBD */
} else {
actx = client->actx;
}
reqarg = isc_mem_get(client->mctx, sizeof(*reqarg));
isc_mutex_init(&reqarg->lock);
reqarg->actx = actx;
reqarg->client = client;
reqarg->trans = NULL;
reqarg->canceled = false;
result = dns_client_startrequest(
client, qmessage, rmessage, server, options, parseoptions, tsec,
timeout, udptimeout, udpretries, client->task,
localrequest_done, reqarg, &reqarg->trans);
if (result != ISC_R_SUCCESS) {
isc_mutex_destroy(&reqarg->lock);
isc_mem_put(client->mctx, reqarg, sizeof(*reqarg));
return (result);
}
/*
* Start internal event loop. It blocks until the entire process
* is completed.
*/
result = isc_app_ctxrun(actx);
LOCK(&reqarg->lock);
if (result == ISC_R_SUCCESS || result == ISC_R_SUSPEND) {
result = reqarg->result;
}
if (reqarg->trans != NULL) {
/*
* Unusual termination (perhaps due to signal). We need some
* tricky cleanup process.
*/
reqarg->canceled = true;
dns_client_cancelresolve(reqarg->trans);
UNLOCK(&reqarg->lock);
/* reqarg will be freed in the event handler. */
} else {
UNLOCK(&reqarg->lock);
isc_mutex_destroy(&reqarg->lock);
isc_mem_put(client->mctx, reqarg, sizeof(*reqarg));
}
return (result);
}
isc_result_t
dns_client_startrequest(dns_client_t *client, dns_message_t *qmessage,
dns_message_t *rmessage, const isc_sockaddr_t *server,
unsigned int options, unsigned int parseoptions,
dns_tsec_t *tsec, unsigned int timeout,
unsigned int udptimeout, unsigned int udpretries,
isc_task_t *task, isc_taskaction_t action, void *arg,
dns_clientreqtrans_t **transp) {
isc_result_t result;
dns_view_t *view = NULL;
isc_task_t *tclone = NULL;
dns_clientreqevent_t *event = NULL;
reqctx_t *ctx = NULL;
dns_tsectype_t tsectype = dns_tsectype_none;
unsigned int reqoptions;
REQUIRE(DNS_CLIENT_VALID(client));
REQUIRE(qmessage != NULL);
REQUIRE(rmessage != NULL);
REQUIRE(transp != NULL && *transp == NULL);
if (tsec != NULL) {
tsectype = dns_tsec_gettype(tsec);
if (tsectype != dns_tsectype_tsig) {
return (ISC_R_NOTIMPLEMENTED); /* XXX */
}
}
LOCK(&client->lock);
result = dns_viewlist_find(&client->viewlist, DNS_CLIENTVIEW_NAME,
qmessage->rdclass, &view);
UNLOCK(&client->lock);
if (result != ISC_R_SUCCESS) {
return (result);
}
reqoptions = 0;
if ((options & DNS_CLIENTREQOPT_TCP) != 0) {
reqoptions |= DNS_REQUESTOPT_TCP;
}
tclone = NULL;
isc_task_attach(task, &tclone);
event = (dns_clientreqevent_t *)isc_event_allocate(
client->mctx, tclone, DNS_EVENT_CLIENTREQDONE, action, arg,
sizeof(*event));
ctx = isc_mem_get(client->mctx, sizeof(*ctx));
isc_mutex_init(&ctx->lock);
ctx->client = client;
ISC_LINK_INIT(ctx, link);
ctx->parseoptions = parseoptions;
ctx->canceled = false;
ctx->event = event;
ctx->event->rmessage = rmessage;
ctx->tsigkey = NULL;
if (tsec != NULL) {
dns_tsec_getkey(tsec, &ctx->tsigkey);
}
ctx->magic = REQCTX_MAGIC;
LOCK(&client->lock);
ISC_LIST_APPEND(client->reqctxs, ctx, link);
isc_refcount_increment(&client->references);
UNLOCK(&client->lock);
ctx->request = NULL;
result = dns_request_createvia(view->requestmgr, qmessage, NULL, server,
-1, reqoptions, ctx->tsigkey, timeout,
udptimeout, udpretries, client->task,
request_done, ctx, &ctx->request);
if (result == ISC_R_SUCCESS) {
dns_view_detach(&view);
*transp = (dns_clientreqtrans_t *)ctx;
return (ISC_R_SUCCESS);
}
isc_refcount_decrement1(&client->references);
LOCK(&client->lock);
ISC_LIST_UNLINK(client->reqctxs, ctx, link);
UNLOCK(&client->lock);
isc_mutex_destroy(&ctx->lock);
isc_mem_put(client->mctx, ctx, sizeof(*ctx));
isc_event_free(ISC_EVENT_PTR(&event));
isc_task_detach(&tclone);
dns_view_detach(&view);
return (result);
}
void
dns_client_cancelrequest(dns_clientreqtrans_t *trans) {
reqctx_t *ctx;
REQUIRE(trans != NULL);
ctx = (reqctx_t *)trans;
REQUIRE(REQCTX_VALID(ctx));
LOCK(&ctx->lock);
if (!ctx->canceled) {
ctx->canceled = true;
if (ctx->request != NULL) {
dns_request_cancel(ctx->request);
}
}
UNLOCK(&ctx->lock);
}
void
dns_client_destroyreqtrans(dns_clientreqtrans_t **transp) {
reqctx_t *ctx;
isc_mem_t *mctx;
dns_client_t *client;
REQUIRE(transp != NULL);
ctx = (reqctx_t *)*transp;
*transp = NULL;
REQUIRE(REQCTX_VALID(ctx));
client = ctx->client;
REQUIRE(DNS_CLIENT_VALID(client));
REQUIRE(ctx->event == NULL);
REQUIRE(ctx->request != NULL);
dns_request_destroy(&ctx->request);
mctx = client->mctx;
LOCK(&client->lock);
INSIST(ISC_LINK_LINKED(ctx, link));
ISC_LIST_UNLINK(client->reqctxs, ctx, link);
UNLOCK(&client->lock);
isc_mutex_destroy(&ctx->lock);
ctx->magic = 0;
isc_mem_put(mctx, ctx, sizeof(*ctx));
dns_client_destroy(&client);
}