]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
change the signature of recv callbacks to include a result code
authorEvan Hunt <each@isc.org>
Thu, 16 Apr 2020 02:26:49 +0000 (19:26 -0700)
committerEvan Hunt <each@isc.org>
Fri, 19 Jun 2020 19:33:26 +0000 (12:33 -0700)
this will allow recv event handlers to distinguish between cases
in which the region is NULL because of error, shutdown, or cancelation.

lib/isc/include/isc/netmgr.h
lib/isc/netmgr/tcp.c
lib/isc/netmgr/tcpdns.c
lib/isc/netmgr/udp.c
lib/ns/client.c
lib/ns/include/ns/client.h

index 0e2db629ea5d3668ed49c351180143c880421f52..4cb5b1228965de259e7ad980d1f593bc031612ae 100644 (file)
@@ -122,26 +122,27 @@ isc_nmhandle_netmgr(isc_nmhandle_t *handle);
  * Return a pointer to the netmgr object for the given handle.
  */
 
-typedef void (*isc_nm_recv_cb_t)(isc_nmhandle_t *handle, isc_region_t *region,
-                                void *cbarg);
+typedef void (*isc_nm_recv_cb_t)(isc_nmhandle_t *handle, isc_result_t eresult,
+                                isc_region_t *region, void *cbarg);
 /*%<
  * Callback function to be used when receiving a packet.
  *
  * 'handle' the handle that can be used to send back the answer.
- * 'region' contains the received data. It will be freed after
- *          return by caller.
+ * 'eresult' the result of the event.
+ * 'region' contains the received data, if any. It will be freed
+ *          after return by caller.
  * 'cbarg'  the callback argument passed to isc_nm_listenudp(),
  *          isc_nm_listentcpdns(), or isc_nm_read().
  */
 
-typedef void (*isc_nm_cb_t)(isc_nmhandle_t *handle, isc_result_t result,
+typedef void (*isc_nm_cb_t)(isc_nmhandle_t *handle, isc_result_t eresult,
                            void *cbarg);
 /*%<
  * Callback function for other network completion events (send, connect,
  * accept).
  *
  * 'handle' the handle on which the event took place.
- * 'result' the result of the event.
+ * 'eresult' the result of the event.
  * 'cbarg'  the callback argument passed to isc_nm_send(),
  *          isc_nm_tcp_connect(), or isc_nm_listentcp()
  */
index 48c03148207368ce0c3a804e04e4b6b21b5bfc06..f38f31070bf874aa6d71e082461898b9cbccbb7e 100644 (file)
@@ -582,7 +582,8 @@ readtimeout_cb(uv_timer_t *handle) {
                isc_quota_detach(&sock->quota);
        }
        if (sock->rcb.recv != NULL) {
-               sock->rcb.recv(sock->tcphandle, NULL, sock->rcbarg);
+               sock->rcb.recv(sock->tcphandle, ISC_R_TIMEDOUT, NULL,
+                              sock->rcbarg);
        }
 }
 
@@ -716,7 +717,8 @@ read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
                                        .length = nread };
 
                if (sock->rcb.recv != NULL) {
-                       sock->rcb.recv(sock->tcphandle, &region, sock->rcbarg);
+                       sock->rcb.recv(sock->tcphandle, ISC_R_SUCCESS, &region,
+                                      sock->rcbarg);
                }
 
                sock->read_timeout = (atomic_load(&sock->keepalive)
@@ -741,7 +743,7 @@ read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
         */
        if (sock->rcb.recv != NULL) {
                isc__nm_incstats(sock->mgr, sock->statsindex[STATID_RECVFAIL]);
-               sock->rcb.recv(sock->tcphandle, NULL, sock->rcbarg);
+               sock->rcb.recv(sock->tcphandle, ISC_R_EOF, NULL, sock->rcbarg);
        }
 
        /*
@@ -1076,7 +1078,8 @@ isc__nm_tcp_shutdown(isc_nmsocket_t *sock) {
        if (sock->type == isc_nm_tcpsocket && sock->tcphandle != NULL &&
            sock->rcb.recv != NULL)
        {
-               sock->rcb.recv(sock->tcphandle, NULL, sock->rcbarg);
+               sock->rcb.recv(sock->tcphandle, ISC_R_CANCELED, NULL,
+                              sock->rcbarg);
        }
 }
 
index c7d23e96a99cff01ab78256766ac468dda893324..19a31870f2de64d35ebe4672828778934f2963ee 100644 (file)
@@ -38,7 +38,8 @@
  */
 
 static void
-dnslisten_readcb(isc_nmhandle_t *handle, isc_region_t *region, void *arg);
+dnslisten_readcb(isc_nmhandle_t *handle, isc_result_t eresult,
+                isc_region_t *region, void *arg);
 
 static void
 resume_processing(void *arg);
@@ -187,7 +188,7 @@ processbuffer(isc_nmsocket_t *dnssock, isc_nmhandle_t **handlep) {
 
                if (listener != NULL && listener->rcb.recv != NULL) {
                        listener->rcb.recv(
-                               dnshandle,
+                               dnshandle, ISC_R_SUCCESS,
                                &(isc_region_t){ .base = dnssock->buf + 2,
                                                 .length = len },
                                listener->rcbarg);
@@ -212,7 +213,8 @@ processbuffer(isc_nmsocket_t *dnssock, isc_nmhandle_t **handlep) {
  * a complete DNS packet and, if so - call the callback
  */
 static void
-dnslisten_readcb(isc_nmhandle_t *handle, isc_region_t *region, void *arg) {
+dnslisten_readcb(isc_nmhandle_t *handle, isc_result_t eresult,
+                isc_region_t *region, void *arg) {
        isc_nmsocket_t *dnssock = (isc_nmsocket_t *)arg;
        unsigned char *base = NULL;
        bool done = false;
@@ -222,9 +224,10 @@ dnslisten_readcb(isc_nmhandle_t *handle, isc_region_t *region, void *arg) {
        REQUIRE(VALID_NMHANDLE(handle));
        REQUIRE(dnssock->tid == isc_nm_tid());
 
-       if (region == NULL) {
+       if (region == NULL || eresult != ISC_R_SUCCESS) {
                /* Connection closed */
                isc_nmhandle_unref(handle);
+               dnssock->result = eresult;
                if (dnssock->self != NULL) {
                        isc__nmsocket_detach(&dnssock->self);
                }
index d37c1c47653cbdb68a3cb1c98a668f6972e74ca3..b2b8166afb64b79a08f518a4cd5de8f75efdba1b 100644 (file)
@@ -364,7 +364,7 @@ udp_recv_cb(uv_udp_t *handle, ssize_t nrecv, const uv_buf_t *buf,
        region.length = nrecv;
 
        INSIST(sock->rcb.recv != NULL);
-       sock->rcb.recv(nmhandle, &region, sock->rcbarg);
+       sock->rcb.recv(nmhandle, ISC_R_SUCCESS, &region, sock->rcbarg);
        if (free_buf) {
                isc__nm_free_uvbuf(sock, buf);
        }
index 1c8df4b0fb0f5133d5b83072c5c8edeca148c186..00badb4ac5649f77d7cb39395a1a036a0cf1b529 100644 (file)
@@ -1620,7 +1620,8 @@ ns__client_put_cb(void *client0) {
  * or tcpmsg (TCP case).
  */
 void
-ns__client_request(isc_nmhandle_t *handle, isc_region_t *region, void *arg) {
+ns__client_request(isc_nmhandle_t *handle, isc_result_t eresult,
+                  isc_region_t *region, void *arg) {
        ns_client_t *client;
        bool newclient = false;
        ns_clientmgr_t *mgr;
@@ -1644,6 +1645,8 @@ ns__client_request(isc_nmhandle_t *handle, isc_region_t *region, void *arg) {
 #endif /* ifdef HAVE_DNSTAP */
        ifp = (ns_interface_t *)arg;
 
+       UNUSED(eresult);
+
        mgr = ifp->clientmgr;
        if (mgr == NULL) {
                /* The interface was shut down in the meantime, just bail */
index 74c435b0c61d0f213983a6135c791178b6870f51..bc6ec751e978df28de101157688c2b53a76ac290 100644 (file)
@@ -468,7 +468,8 @@ ns_client_addopt(ns_client_t *client, dns_message_t *message,
  */
 
 void
-ns__client_request(isc_nmhandle_t *handle, isc_region_t *region, void *arg);
+ns__client_request(isc_nmhandle_t *handle, isc_result_t eresult,
+                  isc_region_t *region, void *arg);
 
 /*%<
  * Handle client requests.