]> 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)
committerOndřej Surý <ondrej@isc.org>
Thu, 1 Oct 2020 14:44:43 +0000 (16:44 +0200)
this will allow recv event handlers to distinguish between cases
in which the region is NULL because of error, shutdown, or cancelation.

(cherry picked from commit 75c985c07f2208d434977b27fe3eb41a433924d7)

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 f20861b4e2a70a13c1f22daff5ea756885958fb7..d41a96b47528763f718f8f9567c9be03f6214920 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 7fc3d0f1260774a56f9e77b25d994c3768ddef44..dc6f3fe087329cbd67e713aa1f3edbd92b238ba5 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 15e3ced2fa1b6d20f7a00166418a372473923df5..e47b140aa909818bcd12b90ae46bd7c24ba64032 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 3adba64583d6d85b7d834929f90441e954f4f556..c84399869face5369fd4e69a37cc69fb394ba6df 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 b756755644f2684f3351a828737a8a80ff6b94b8..7d34239c6861dcd080a384e422cb06058aa617a0 100644 (file)
@@ -1615,7 +1615,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;
@@ -1639,6 +1640,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 591ccb8270458b42755d3ef6c86cdb7148cb0158..f73d6a3c975aef9a058ab111eca6916e81618645 100644 (file)
@@ -469,7 +469,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.