Move isc_socket_cancel() calls into dispatch

We now use dns_dispatch_cancel() for this purpose. NOTE: The caller
still has to track whether there are pending send or connect events in
the dispatch or dispatch entry; later this should be moved into the
dispatch module as well.

Also removed some public dns_dispatch_*() API calls that are no longer
used outside dispatch itself.
This commit is contained in:
Evan Hunt 2021-01-04 23:51:07 -08:00
parent 2523be1cbe
commit e76a7f764e
4 changed files with 62 additions and 62 deletions

View file

@ -302,6 +302,10 @@ qid_destroy(isc_mem_t *mctx, dns_qid_t **qidp);
static isc_result_t
open_socket(isc_socketmgr_t *mgr, const isc_sockaddr_t *local,
unsigned int options, isc_socket_t **sockp);
static isc_socket_t *
getentrysocket(dns_dispentry_t *resp);
static isc_socket_t *
getsocket(dns_dispatch_t *disp);
#define LVL(x) ISC_LOG_DEBUG(x)
@ -2612,7 +2616,7 @@ dns_dispatch_send(dns_dispentry_t *resp, bool tcp, isc_task_t *task,
ISC_EVENT_INIT(sendevent, sizeof(isc_socketevent_t), 0, NULL,
ISC_SOCKEVENT_SENDDONE, action, arg, NULL, NULL, NULL);
sock = dns_dispatch_getentrysocket(resp);
sock = getentrysocket(resp);
if (dscp == -1) {
sendevent->attributes &= ~ISC_SOCKEVENTATTR_DSCP;
@ -2633,6 +2637,37 @@ dns_dispatch_send(dns_dispentry_t *resp, bool tcp, isc_task_t *task,
return (result);
}
void
dns_dispatch_cancel(dns_dispatch_t *disp, dns_dispentry_t *resp, bool sending,
bool connecting) {
isc_socket_t *sock = NULL;
REQUIRE(disp != NULL || resp != NULL);
if (resp != NULL) {
REQUIRE(VALID_RESPONSE(resp));
sock = getentrysocket(resp);
} else if (disp != NULL) {
REQUIRE(VALID_DISPATCH(disp));
sock = getsocket(disp);
} else {
INSIST(0);
ISC_UNREACHABLE();
}
if (sock == NULL) {
return;
}
if (connecting) {
isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_CONNECT);
}
if (sending) {
isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_SEND);
}
}
/*
* disp must be locked.
*/
@ -2682,15 +2717,15 @@ unlock:
UNLOCK(&qid->lock);
}
isc_socket_t *
dns_dispatch_getsocket(dns_dispatch_t *disp) {
static isc_socket_t *
getsocket(dns_dispatch_t *disp) {
REQUIRE(VALID_DISPATCH(disp));
return (disp->socket);
}
isc_socket_t *
dns_dispatch_getentrysocket(dns_dispentry_t *resp) {
static isc_socket_t *
getentrysocket(dns_dispentry_t *resp) {
REQUIRE(VALID_RESPONSE(resp));
if (resp->disp->socktype == isc_sockettype_tcp) {

View file

@ -276,6 +276,18 @@ dns_dispatch_connect(dns_dispatch_t *disp, dns_dispentry_t *resp,
*\li 'disp' is NULL and 'resp' is valid.
*/
void
dns_dispatch_cancel(dns_dispatch_t *disp, dns_dispentry_t *resp, bool sending,
bool connecting);
/*%<
* Cancel pending sends (if 'sending' is true) and connects (if
* 'connecting' is true) in 'resp' or 'disp'.
*
* Requires:
*\li 'resp' is NULL and 'disp' is valid, or
*\li 'disp' is NULL and 'resp' is valid.
*/
isc_result_t
dns_dispatch_send(dns_dispentry_t *resp, bool tcp, isc_task_t *task,
isc_socketevent_t *sendevent, isc_region_t *r,
@ -365,21 +377,6 @@ dns_dispatch_removeresponse(dns_dispentry_t ** resp,
* argument to dns_dispatch_addresponse() when allocating '*resp'.
*/
isc_socket_t *
dns_dispatch_getentrysocket(dns_dispentry_t *resp);
isc_socket_t *
dns_dispatch_getsocket(dns_dispatch_t *disp);
/*%<
* Return the socket associated with dispatcher or dispatch entry.
*
* Requires:
*\li disp is valid.
*
* Returns:
*\li The socket the dispatcher is using.
*/
isc_result_t
dns_dispatch_getlocaladdress(dns_dispatch_t *disp, isc_sockaddr_t *addrp);
/*%<

View file

@ -577,7 +577,6 @@ dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
dns_request_t **requestp) {
dns_request_t *request = NULL;
isc_task_t *tclone = NULL;
isc_socket_t *sock = NULL;
isc_result_t result;
isc_mem_t *mctx;
dns_messageid_t id;
@ -674,9 +673,6 @@ again:
goto cleanup;
}
sock = dns_dispatch_getentrysocket(request->dispentry);
INSIST(sock != NULL);
isc_buffer_allocate(mctx, &request->query, r.length + (tcp ? 2 : 0));
if (tcp) {
isc_buffer_putuint16(request->query, (uint16_t)r.length);
@ -766,7 +762,6 @@ dns_request_createvia(dns_requestmgr_t *requestmgr, dns_message_t *message,
dns_request_t **requestp) {
dns_request_t *request = NULL;
isc_task_t *tclone = NULL;
isc_socket_t *sock = NULL;
isc_result_t result;
isc_mem_t *mctx;
dns_messageid_t id;
@ -845,8 +840,6 @@ use_tcp:
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
sock = dns_dispatch_getentrysocket(request->dispentry);
INSIST(sock != NULL);
message->id = id;
if (settsigkey) {
@ -863,7 +856,6 @@ use_tcp:
dns_message_renderreset(message);
dns_dispatch_removeresponse(&request->dispentry, NULL);
dns_dispatch_detach(&request->dispatch);
sock = NULL;
options |= DNS_REQUESTOPT_TCP;
settsigkey = false;
goto use_tcp;
@ -1358,8 +1350,6 @@ req_destroy(dns_request_t *request) {
*/
static void
req_cancel(dns_request_t *request) {
isc_socket_t *sock = NULL;
REQUIRE(VALID_REQUEST(request));
req_log(ISC_LOG_DEBUG(3), "req_cancel: request %p", request);
@ -1373,18 +1363,10 @@ req_cancel(dns_request_t *request) {
isc_timer_detach(&request->timer);
}
if (DNS_REQUEST_CONNECTING(request) || DNS_REQUEST_SENDING(request)) {
if (request->dispentry != NULL) {
sock = dns_dispatch_getentrysocket(request->dispentry);
}
if (DNS_REQUEST_CONNECTING(request) && sock != NULL) {
isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_CONNECT);
}
if (DNS_REQUEST_SENDING(request) && sock != NULL) {
isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_SEND);
}
}
if (request->dispentry != NULL) {
dns_dispatch_cancel(NULL, request->dispentry,
DNS_REQUEST_SENDING(request),
DNS_REQUEST_CONNECTING(request));
dns_dispatch_removeresponse(&request->dispentry, NULL);
}
dns_dispatch_detach(&request->dispatch);

View file

@ -22,7 +22,6 @@
#include <isc/random.h>
#include <isc/refcount.h>
#include <isc/siphash.h>
#include <isc/socket.h>
#include <isc/stats.h>
#include <isc/string.h>
#include <isc/task.h>
@ -1249,7 +1248,6 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp,
unsigned int rtt, rttms;
unsigned int factor;
dns_adbfind_t *find = NULL;
isc_socket_t *sock = NULL;
dns_adbaddrinfo_t *addrinfo;
isc_stdtime_t now;
@ -1418,26 +1416,14 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp,
/*
* Check for any outstanding socket events. If they exist, cancel
* them and let the event handlers finish the cleanup. The resolver
* only needs to worry about managing the connect and send events;
* the dispatcher manages the recv events.
* them and let the event handlers finish the cleanup. (XXX:
* Currently the resolver, rather than dispatch, tracks whether
* it's sending or connecting; this will be moved into dispatch
* later.)
*/
if (query->dispentry != NULL) {
sock = dns_dispatch_getentrysocket(query->dispentry);
} else {
sock = dns_dispatch_getsocket(query->dispatch);
}
/* Cancel the connect. */
if (sock != NULL && RESQUERY_CONNECTING(query)) {
isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_CONNECT);
}
/* Cancel the pending send. */
if (sock != NULL && RESQUERY_SENDING(query)) {
isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_SEND);
}
dns_dispatch_cancel(query->dispatch, query->dispentry,
RESQUERY_SENDING(query),
RESQUERY_CONNECTING(query));
if (query->dispentry != NULL) {
dns_dispatch_removeresponse(&query->dispentry, deventp);
}