Avoid running get_matching_view() asynchronously on an error path

Also create a new ns_client_async_reset() static function to decrease
code duplication.
This commit is contained in:
Aram Sargsyan 2024-06-03 10:49:46 +00:00 committed by Nicki Křížek
parent a2b61c0a65
commit 54ddd848fe
No known key found for this signature in database
GPG key ID: 01623B9B652A20A7
2 changed files with 28 additions and 35 deletions

View file

@ -10234,6 +10234,15 @@ get_matching_view(isc_netaddr_t *srcaddr, isc_netaddr_t *destaddr,
return (*viewmatchresult);
}
/* Also no offloading when there is no view at all to match against. */
view = get_matching_view_next(NULL, message->rdclass);
if (view == NULL) {
*viewmatchresult = ISC_R_NOTFOUND;
return (*viewmatchresult);
}
dns_message_resetsig(message);
matching_view_ctx_t *mvctx = isc_mem_get(message->mctx, sizeof(*mvctx));
*mvctx = (matching_view_ctx_t){
.srcaddr = srcaddr,
@ -10250,15 +10259,6 @@ get_matching_view(isc_netaddr_t *srcaddr, isc_netaddr_t *destaddr,
isc_loop_attach(loop, &mvctx->loop);
dns_message_attach(message, &mvctx->message);
dns_message_resetsig(message);
view = get_matching_view_next(NULL, message->rdclass);
if (view == NULL) {
*mvctx->viewmatchresult = ISC_R_NOTFOUND;
isc_async_run(loop, get_matching_view_done, mvctx);
return (DNS_R_WAIT);
}
/*
* If the message has a SIG0 signature which we are going to
* check, and the client is not exempt from the SIG(0) quota,

View file

@ -1683,6 +1683,16 @@ process_opt(ns_client_t *client, dns_rdataset_t *opt) {
return (result);
}
static void
ns_client_async_reset(ns_client_t *client) {
if (client->async) {
client->async = false;
if (client->handle != NULL) {
isc_nmhandle_unref(client->handle);
}
}
}
void
ns__client_reset_cb(void *client0) {
ns_client_t *client = client0;
@ -1709,12 +1719,7 @@ ns__client_reset_cb(void *client0) {
client->keytag_len = 0;
}
if (client->async) {
client->async = false;
if (client->handle != NULL) {
isc_nmhandle_unref(client->handle);
}
}
ns_client_async_reset(client);
client->state = NS_CLIENTSTATE_READY;
@ -1749,12 +1754,7 @@ ns__client_put_cb(void *client0) {
dns_message_puttemprdataset(client->message, &client->opt);
}
if (client->async) {
client->async = false;
if (client->handle != NULL) {
isc_nmhandle_unref(client->handle);
}
}
ns_client_async_reset(client);
dns_message_detach(&client->message);
@ -1786,19 +1786,22 @@ ns_client_setup_view(ns_client_t *client, isc_netaddr_t *netaddr) {
ns_client_request_continue, client, &client->sigresult,
&client->viewmatchresult, &client->view);
/* Async mode. */
if (result == DNS_R_WAIT) {
INSIST(client->async == true);
return (DNS_R_WAIT);
}
/*
* matchingview() is allowed to return anything other than DNS_R_WAIT
* only in non-async mode, in which case 'result' must be equal to
* matchingview() returning anything other than DNS_R_WAIT means it's
* not running in async mode, in which case 'result' must be equal to
* 'client->viewmatchresult'.
*/
INSIST(client->async == false);
INSIST(result == client->viewmatchresult);
/* Non-async mode. */
ns_client_async_reset(client);
return (result);
}
@ -2480,17 +2483,7 @@ ns_client_request_continue(void *arg) {
}
cleanup:
/*
* If we are running async then 'unref' the handle and reset the async
* flag, so that the destructor doesn't try to 'unref' the handle too.
*/
if (client->async) {
client->async = false;
if (client->handle != NULL) {
isc_nmhandle_unref(client->handle);
}
}
ns_client_async_reset(client);
}
isc_result_t