mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 14:07:59 +00:00
Merge branch 'ondrej-remove-multiple-application-contexts' into 'main'
Remove isc_appctx_t use in dns_client See merge request isc-projects/bind9!6041
This commit is contained in:
commit
ddf051df65
3
CHANGES
3
CHANGES
@ -1,3 +1,6 @@
|
||||
5840. [cleanup] Remove multiple application context use in dns_client
|
||||
unit. [GL !6041]
|
||||
|
||||
5839. [func] Add support for remote TLS certificates
|
||||
verification, both to BIND and dig, making it possible
|
||||
to implement Strict and Mutual TLS authentication,
|
||||
|
@ -1718,12 +1718,10 @@ main(int argc, char *argv[]) {
|
||||
dns_rdataset_t *rdataset;
|
||||
dns_namelist_t namelist;
|
||||
unsigned int resopt;
|
||||
isc_appctx_t *actx = NULL;
|
||||
isc_nm_t *netmgr = NULL;
|
||||
isc_taskmgr_t *taskmgr = NULL;
|
||||
isc_timermgr_t *timermgr = NULL;
|
||||
dns_master_style_t *style = NULL;
|
||||
struct sigaction sa;
|
||||
|
||||
progname = argv[0];
|
||||
preparse_args(argc, argv);
|
||||
@ -1738,8 +1736,6 @@ main(int argc, char *argv[]) {
|
||||
fatal("dst_lib_init failed: %d", result);
|
||||
}
|
||||
|
||||
CHECK(isc_appctx_create(mctx, &actx));
|
||||
|
||||
isc_managers_create(mctx, 1, 0, &netmgr, &taskmgr, &timermgr);
|
||||
|
||||
parse_args(argc, argv);
|
||||
@ -1748,18 +1744,9 @@ main(int argc, char *argv[]) {
|
||||
|
||||
setup_logging(stderr);
|
||||
|
||||
CHECK(isc_app_ctxstart(actx));
|
||||
|
||||
/* Unblock SIGINT if it's been blocked by isc_app_ctxstart() */
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = SIG_DFL;
|
||||
if (sigfillset(&sa.sa_mask) != 0 || sigaction(SIGINT, &sa, NULL) < 0) {
|
||||
fatal("Couldn't set up signal handler");
|
||||
}
|
||||
|
||||
/* Create client */
|
||||
result = dns_client_create(mctx, actx, taskmgr, netmgr, timermgr, 0,
|
||||
&client, srcaddr4, srcaddr6);
|
||||
result = dns_client_create(mctx, taskmgr, netmgr, timermgr, 0, &client,
|
||||
srcaddr4, srcaddr6);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
delv_log(ISC_LOG_ERROR, "dns_client_create: %s",
|
||||
isc_result_totext(result));
|
||||
@ -1844,9 +1831,6 @@ cleanup:
|
||||
|
||||
isc_managers_destroy(&netmgr, &taskmgr, &timermgr);
|
||||
|
||||
if (actx != NULL) {
|
||||
isc_appctx_destroy(&actx);
|
||||
}
|
||||
if (lctx != NULL) {
|
||||
isc_log_destroy(&lctx);
|
||||
}
|
||||
|
@ -56,7 +56,6 @@
|
||||
*/
|
||||
|
||||
isc_mem_t *ctxs_mctx = NULL;
|
||||
isc_appctx_t *ctxs_actx = NULL;
|
||||
isc_nm_t *ctxs_netmgr = NULL;
|
||||
isc_taskmgr_t *ctxs_taskmgr = NULL;
|
||||
isc_timermgr_t *ctxs_timermgr = NULL;
|
||||
@ -65,40 +64,15 @@ static void
|
||||
ctxs_destroy(void) {
|
||||
isc_managers_destroy(&ctxs_netmgr, &ctxs_taskmgr, &ctxs_timermgr);
|
||||
|
||||
if (ctxs_actx != NULL) {
|
||||
isc_appctx_destroy(&ctxs_actx);
|
||||
}
|
||||
|
||||
if (ctxs_mctx != NULL) {
|
||||
isc_mem_destroy(&ctxs_mctx);
|
||||
}
|
||||
isc_mem_destroy(&ctxs_mctx);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
static void
|
||||
ctxs_init(void) {
|
||||
isc_result_t result;
|
||||
|
||||
isc_mem_create(&ctxs_mctx);
|
||||
|
||||
result = isc_appctx_create(ctxs_mctx, &ctxs_actx);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
isc_managers_create(ctxs_mctx, 1, 0, &ctxs_netmgr, &ctxs_taskmgr,
|
||||
&ctxs_timermgr);
|
||||
|
||||
result = isc_app_ctxstart(ctxs_actx);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
fail:
|
||||
ctxs_destroy();
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
static char *algname = NULL;
|
||||
@ -392,10 +366,7 @@ main(int argc, char *argv[]) {
|
||||
altserveraddr = cp + 1;
|
||||
}
|
||||
|
||||
result = ctxs_init();
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
ctxs_init();
|
||||
|
||||
result = dst_lib_init(ctxs_mctx, NULL);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
@ -404,9 +375,9 @@ main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
clientopt = 0;
|
||||
result = dns_client_create(ctxs_mctx, ctxs_actx, ctxs_taskmgr,
|
||||
ctxs_netmgr, ctxs_timermgr, clientopt,
|
||||
&client, addr4, addr6);
|
||||
result = dns_client_create(ctxs_mctx, ctxs_taskmgr, ctxs_netmgr,
|
||||
ctxs_timermgr, clientopt, &client, addr4,
|
||||
addr6);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fprintf(stderr, "dns_client_create failed: %u, %s\n", result,
|
||||
isc_result_totext(result));
|
||||
@ -490,10 +461,7 @@ main(int argc, char *argv[]) {
|
||||
dns_client_freeresanswer(client, &namelist);
|
||||
|
||||
/* Cleanup */
|
||||
cleanup:
|
||||
if (client != NULL) {
|
||||
dns_client_detach(&client);
|
||||
}
|
||||
dns_client_detach(&client);
|
||||
|
||||
ctxs_destroy();
|
||||
dst_lib_destroy();
|
||||
|
@ -84,7 +84,9 @@ struct dns_client {
|
||||
unsigned int attributes;
|
||||
isc_mutex_t lock;
|
||||
isc_mem_t *mctx;
|
||||
isc_appctx_t *actx;
|
||||
bool readydone;
|
||||
isc_mutex_t readylock;
|
||||
isc_condition_t ready;
|
||||
isc_taskmgr_t *taskmgr;
|
||||
isc_task_t *task;
|
||||
isc_nm_t *nm;
|
||||
@ -261,8 +263,8 @@ createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_taskmgr_t *taskmgr,
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
||||
isc_nm_t *nm, isc_timermgr_t *timermgr, unsigned int options,
|
||||
dns_client_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, isc_nm_t *nm,
|
||||
isc_timermgr_t *timermgr, unsigned int options,
|
||||
dns_client_t **clientp, const isc_sockaddr_t *localaddr4,
|
||||
const isc_sockaddr_t *localaddr6) {
|
||||
isc_result_t result;
|
||||
@ -281,11 +283,16 @@ dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
||||
|
||||
client = isc_mem_get(mctx, sizeof(*client));
|
||||
*client = (dns_client_t){
|
||||
.actx = actx, .taskmgr = taskmgr, .timermgr = timermgr, .nm = nm
|
||||
.taskmgr = taskmgr,
|
||||
.timermgr = timermgr,
|
||||
.nm = nm,
|
||||
};
|
||||
|
||||
isc_mutex_init(&client->lock);
|
||||
|
||||
isc_mutex_init(&client->readylock);
|
||||
isc_condition_init(&client->ready);
|
||||
|
||||
result = isc_task_create(client->taskmgr, 0, &client->task);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup_lock;
|
||||
@ -395,6 +402,9 @@ destroyclient(dns_client_t *client) {
|
||||
|
||||
isc_task_detach(&client->task);
|
||||
|
||||
isc_condition_destroy(&client->ready);
|
||||
isc_mutex_destroy(&client->readylock);
|
||||
|
||||
isc_mutex_destroy(&client->lock);
|
||||
client->magic = 0;
|
||||
|
||||
@ -930,23 +940,12 @@ client_resfind(resctx_t *rctx, dns_fetchevent_t *event) {
|
||||
UNLOCK(&rctx->lock);
|
||||
}
|
||||
|
||||
static void
|
||||
suspend(isc_task_t *task, isc_event_t *event) {
|
||||
isc_appctx_t *actx = event->ev_arg;
|
||||
|
||||
UNUSED(task);
|
||||
|
||||
isc_app_ctxsuspend(actx);
|
||||
isc_event_free(&event);
|
||||
}
|
||||
|
||||
static void
|
||||
resolve_done(isc_task_t *task, isc_event_t *event) {
|
||||
resarg_t *resarg = event->ev_arg;
|
||||
dns_clientresevent_t *rev = (dns_clientresevent_t *)event;
|
||||
dns_name_t *name = NULL;
|
||||
dns_client_t *client = resarg->client;
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(task);
|
||||
|
||||
@ -967,16 +966,12 @@ resolve_done(isc_task_t *task, isc_event_t *event) {
|
||||
UNLOCK(&resarg->lock);
|
||||
|
||||
/*
|
||||
* We may or may not be running. isc__appctx_onrun will
|
||||
* fail if we are currently running otherwise we post a
|
||||
* action to call isc_app_ctxsuspend when we do start
|
||||
* running.
|
||||
* Signal that the entire process is done.
|
||||
*/
|
||||
result = isc_app_ctxonrun(resarg->actx, client->mctx, task,
|
||||
suspend, resarg->actx);
|
||||
if (result == ISC_R_ALREADYRUNNING) {
|
||||
isc_app_ctxsuspend(resarg->actx);
|
||||
}
|
||||
LOCK(&client->readylock);
|
||||
client->readydone = true;
|
||||
SIGNAL(&client->ready);
|
||||
UNLOCK(&client->readylock);
|
||||
} else {
|
||||
/*
|
||||
* We have already exited from the loop (due to some
|
||||
@ -998,13 +993,11 @@ dns_client_resolve(dns_client_t *client, const dns_name_t *name,
|
||||
resarg_t *resarg = NULL;
|
||||
|
||||
REQUIRE(DNS_CLIENT_VALID(client));
|
||||
REQUIRE(client->actx != NULL);
|
||||
REQUIRE(namelist != NULL && ISC_LIST_EMPTY(*namelist));
|
||||
|
||||
resarg = isc_mem_get(client->mctx, sizeof(*resarg));
|
||||
|
||||
*resarg = (resarg_t){
|
||||
.actx = client->actx,
|
||||
.client = client,
|
||||
.result = DNS_R_SERVFAIL,
|
||||
.namelist = namelist,
|
||||
@ -1022,10 +1015,13 @@ dns_client_resolve(dns_client_t *client, const dns_name_t *name,
|
||||
}
|
||||
|
||||
/*
|
||||
* Start internal event loop. It blocks until the entire process
|
||||
* is completed.
|
||||
* Block until the entire process is completed.
|
||||
*/
|
||||
result = isc_app_ctxrun(client->actx);
|
||||
LOCK(&client->readylock);
|
||||
if (!client->readydone) {
|
||||
WAIT(&client->ready, &client->readylock);
|
||||
}
|
||||
UNLOCK(&client->readylock);
|
||||
|
||||
LOCK(&resarg->lock);
|
||||
if (result == ISC_R_SUCCESS || result == ISC_R_SUSPEND) {
|
||||
|
@ -89,8 +89,8 @@ typedef struct dns_clientresevent {
|
||||
} dns_clientresevent_t; /* too long? */
|
||||
|
||||
isc_result_t
|
||||
dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
||||
isc_nm_t *nm, isc_timermgr_t *timermgr, unsigned int options,
|
||||
dns_client_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, isc_nm_t *nm,
|
||||
isc_timermgr_t *timermgr, unsigned int options,
|
||||
dns_client_t **clientp, const isc_sockaddr_t *localaddr4,
|
||||
const isc_sockaddr_t *localaddr6);
|
||||
/*%<
|
||||
@ -109,8 +109,6 @@ dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
||||
*
|
||||
*\li 'mctx' is a valid memory context.
|
||||
*
|
||||
*\li 'actx' is a valid application context.
|
||||
*
|
||||
*\li 'taskmgr' is a valid task manager.
|
||||
*
|
||||
*\li 'nm' is a valid network manager.
|
||||
|
Loading…
x
Reference in New Issue
Block a user