mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
refactor dns_resolver to use loop callbacks
callback events from dns_resolver_createfetch() are now posted using isc_async_run. other modules which called the resolver and maintained task/taskmgr objects for this purpose have been cleaned up.
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
#include <isc/result.h>
|
||||
#include <isc/safe.h>
|
||||
#include <isc/sockaddr.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/adb.h>
|
||||
@@ -76,7 +75,6 @@ struct dns_client {
|
||||
unsigned int magic;
|
||||
unsigned int attributes;
|
||||
isc_mem_t *mctx;
|
||||
isc_task_t *task;
|
||||
isc_loop_t *loop;
|
||||
isc_nm_t *nm;
|
||||
dns_dispatchmgr_t *dispatchmgr;
|
||||
@@ -135,7 +133,7 @@ typedef struct resarg {
|
||||
} resarg_t;
|
||||
|
||||
static void
|
||||
client_resfind(resctx_t *rctx, dns_fetchevent_t *event);
|
||||
client_resfind(resctx_t *rctx, dns_fetchresponse_t *event);
|
||||
static void
|
||||
destroyrestrans(dns_clientrestrans_t **transp);
|
||||
|
||||
@@ -203,8 +201,7 @@ getudpdispatch(int family, dns_dispatchmgr_t *dispatchmgr,
|
||||
|
||||
static isc_result_t
|
||||
createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_loopmgr_t *loopmgr,
|
||||
isc_taskmgr_t *taskmgr, isc_nm_t *nm,
|
||||
isc_tlsctx_cache_t *tlsctx_client_cache,
|
||||
isc_nm_t *nm, isc_tlsctx_cache_t *tlsctx_client_cache,
|
||||
dns_dispatchmgr_t *dispatchmgr, dns_dispatch_t *dispatchv4,
|
||||
dns_dispatch_t *dispatchv6, dns_view_t **viewp) {
|
||||
isc_result_t result;
|
||||
@@ -221,7 +218,7 @@ createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_loopmgr_t *loopmgr,
|
||||
goto cleanup_view;
|
||||
}
|
||||
|
||||
result = dns_view_createresolver(view, loopmgr, taskmgr, 1, nm, 0,
|
||||
result = dns_view_createresolver(view, loopmgr, 1, nm, 0,
|
||||
tlsctx_client_cache, dispatchmgr,
|
||||
dispatchv4, dispatchv6);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
@@ -243,9 +240,8 @@ cleanup_view:
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_client_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr,
|
||||
isc_taskmgr_t *taskmgr, isc_nm_t *nm, unsigned int options,
|
||||
isc_tlsctx_cache_t *tlsctx_client_cache,
|
||||
dns_client_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, isc_nm_t *nm,
|
||||
unsigned int options, isc_tlsctx_cache_t *tlsctx_client_cache,
|
||||
dns_client_t **clientp, const isc_sockaddr_t *localaddr4,
|
||||
const isc_sockaddr_t *localaddr6) {
|
||||
isc_result_t result;
|
||||
@@ -255,7 +251,6 @@ dns_client_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr,
|
||||
dns_view_t *view = NULL;
|
||||
|
||||
REQUIRE(mctx != NULL);
|
||||
REQUIRE(taskmgr != NULL);
|
||||
REQUIRE(nm != NULL);
|
||||
REQUIRE(tlsctx_client_cache != NULL);
|
||||
REQUIRE(clientp != NULL && *clientp == NULL);
|
||||
@@ -268,14 +263,9 @@ dns_client_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr,
|
||||
.nm = nm,
|
||||
};
|
||||
|
||||
result = isc_task_create(taskmgr, &client->task, 0);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup_lock;
|
||||
}
|
||||
|
||||
result = dns_dispatchmgr_create(mctx, nm, &client->dispatchmgr);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup_task;
|
||||
goto cleanup_client;
|
||||
}
|
||||
(void)setsourceports(mctx, client->dispatchmgr);
|
||||
|
||||
@@ -310,7 +300,7 @@ dns_client_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr,
|
||||
isc_refcount_init(&client->references, 1);
|
||||
|
||||
/* Create the default view for class IN */
|
||||
result = createview(mctx, dns_rdataclass_in, loopmgr, taskmgr, nm,
|
||||
result = createview(mctx, dns_rdataclass_in, loopmgr, nm,
|
||||
tlsctx_client_cache, client->dispatchmgr,
|
||||
dispatchv4, dispatchv6, &view);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
@@ -345,9 +335,7 @@ cleanup_dispatchmgr:
|
||||
dns_dispatch_detach(&dispatchv6);
|
||||
}
|
||||
dns_dispatchmgr_detach(&client->dispatchmgr);
|
||||
cleanup_task:
|
||||
isc_task_detach(&client->task);
|
||||
cleanup_lock:
|
||||
cleanup_client:
|
||||
isc_mem_put(mctx, client, sizeof(*client));
|
||||
|
||||
return (result);
|
||||
@@ -368,8 +356,6 @@ destroyclient(dns_client_t *client) {
|
||||
|
||||
dns_dispatchmgr_detach(&client->dispatchmgr);
|
||||
|
||||
isc_task_detach(&client->task);
|
||||
|
||||
client->magic = 0;
|
||||
|
||||
isc_mem_putanddetach(&client->mctx, client, sizeof(*client));
|
||||
@@ -459,15 +445,13 @@ putrdataset(isc_mem_t *mctx, dns_rdataset_t **rdatasetp) {
|
||||
}
|
||||
|
||||
static void
|
||||
fetch_done(isc_task_t *task, isc_event_t *event) {
|
||||
resctx_t *rctx = event->ev_arg;
|
||||
dns_fetchevent_t *fevent;
|
||||
fetch_done(void *arg) {
|
||||
dns_fetchresponse_t *resp = (dns_fetchresponse_t *)arg;
|
||||
resctx_t *rctx = resp->arg;
|
||||
|
||||
REQUIRE(RCTX_VALID(rctx));
|
||||
REQUIRE(rctx->client->task == task);
|
||||
fevent = (dns_fetchevent_t *)event;
|
||||
|
||||
client_resfind(rctx, fevent);
|
||||
client_resfind(rctx, resp);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
@@ -494,7 +478,7 @@ start_fetch(resctx_t *rctx) {
|
||||
result = dns_resolver_createfetch(
|
||||
rctx->view->resolver, dns_fixedname_name(&rctx->name),
|
||||
rctx->type, NULL, NULL, NULL, NULL, 0, fopts, 0, NULL,
|
||||
rctx->client->task, fetch_done, rctx, rctx->rdataset,
|
||||
rctx->client->loop, fetch_done, rctx, rctx->rdataset,
|
||||
rctx->sigrdataset, &rctx->fetch);
|
||||
|
||||
return (result);
|
||||
@@ -521,8 +505,8 @@ view_find(resctx_t *rctx, dns_db_t **dbp, dns_dbnode_t **nodep,
|
||||
}
|
||||
|
||||
static void
|
||||
client_resfind(resctx_t *rctx, dns_fetchevent_t *event) {
|
||||
isc_mem_t *mctx;
|
||||
client_resfind(resctx_t *rctx, dns_fetchresponse_t *resp) {
|
||||
isc_mem_t *mctx = NULL;
|
||||
isc_result_t tresult, result = ISC_R_SUCCESS;
|
||||
isc_result_t vresult = ISC_R_SUCCESS;
|
||||
bool want_restart;
|
||||
@@ -552,7 +536,7 @@ client_resfind(resctx_t *rctx, dns_fetchevent_t *event) {
|
||||
rctx->restarts++;
|
||||
want_restart = false;
|
||||
|
||||
if (event == NULL) {
|
||||
if (resp == NULL) {
|
||||
fname = dns_fixedname_initname(&foundname);
|
||||
INSIST(!dns_rdataset_isassociated(rctx->rdataset));
|
||||
INSIST(rctx->sigrdataset == NULL ||
|
||||
@@ -582,16 +566,17 @@ client_resfind(resctx_t *rctx, dns_fetchevent_t *event) {
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
INSIST(event != NULL);
|
||||
INSIST(event->fetch == rctx->fetch);
|
||||
INSIST(resp != NULL);
|
||||
INSIST(resp->fetch == rctx->fetch);
|
||||
dns_resolver_destroyfetch(&rctx->fetch);
|
||||
db = event->db;
|
||||
node = event->node;
|
||||
result = event->result;
|
||||
vresult = event->vresult;
|
||||
fname = event->foundname;
|
||||
INSIST(event->rdataset == rctx->rdataset);
|
||||
INSIST(event->sigrdataset == rctx->sigrdataset);
|
||||
db = resp->db;
|
||||
node = resp->node;
|
||||
result = resp->result;
|
||||
vresult = resp->vresult;
|
||||
fname = resp->foundname;
|
||||
INSIST(resp->rdataset == rctx->rdataset);
|
||||
INSIST(resp->sigrdataset == rctx->sigrdataset);
|
||||
isc_mem_putanddetach(&resp->mctx, resp, sizeof(*resp));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -821,9 +806,6 @@ client_resfind(resctx_t *rctx, dns_fetchevent_t *event) {
|
||||
if (db != NULL) {
|
||||
dns_db_detach(&db);
|
||||
}
|
||||
if (event != NULL) {
|
||||
isc_event_free(ISC_EVENT_PTR(&event));
|
||||
}
|
||||
|
||||
/*
|
||||
* Limit the number of restarts.
|
||||
|
Reference in New Issue
Block a user