]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
replace per-protocol keepalive functions with a common one
authorEvan Hunt <each@isc.org>
Thu, 15 Jul 2021 04:12:37 +0000 (21:12 -0700)
committerEvan Hunt <each@isc.org>
Fri, 27 Aug 2021 17:02:10 +0000 (10:02 -0700)
this commit removes isc__nm_tcpdns_keepalive() and
isc__nm_tlsdns_keepalive(); keepalive for these protocols and
for TCP will now be set directly from isc_nmhandle_keepalive().

protocols that have an underlying TCP socket (i.e., TLS stream
and HTTP), now have protocol-specific routines, called by
isc_nmhandle_keeaplive(), to set the keepalive value on the
underlying socket.

lib/isc/netmgr/http.c
lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/tcpdns.c
lib/isc/netmgr/tlsdns.c
lib/isc/netmgr/tlsstream.c

index 58c2058cc62f22495fc65935e30244274d296e09..6a8a4128c22a566e9e47060599bbea314ff6f83a 100644 (file)
@@ -3064,6 +3064,23 @@ isc__nm_http_settimeout(isc_nmhandle_t *handle, uint32_t timeout) {
        }
 }
 
+void
+isc__nmhandle_http_keepalive(isc_nmhandle_t *handle, bool value) {
+       isc_nmsocket_t *sock = NULL;
+
+       REQUIRE(VALID_NMHANDLE(handle));
+       REQUIRE(VALID_NMSOCK(handle->sock));
+       REQUIRE(handle->sock->type == isc_nm_httpsocket);
+
+       sock = handle->sock;
+       if (sock->h2.session != NULL && sock->h2.session->handle) {
+               INSIST(VALID_HTTP2_SESSION(sock->h2.session));
+               INSIST(VALID_NMHANDLE(sock->h2.session->handle));
+
+               isc_nmhandle_keepalive(sock->h2.session->handle, value);
+       }
+}
+
 /*
  * DoH GET Query String Scanner-less Recursive Descent Parser/Verifier
  *
index 1902c3df73de64192a2fa2993616df55c6f7743b..60d6b83c519a8f90733256e6e7b4900e4d228a4d 100644 (file)
@@ -1517,15 +1517,6 @@ isc__nm_tcpdns_cancelread(isc_nmhandle_t *handle);
  * Stop reading on a connected TCPDNS handle.
  */
 
-void
-isc__nm_tcpdns_keepalive(isc_nmhandle_t *handle, bool value);
-/*%<
- * Enable/disable keepalive on this connection by setting it to 'value'.
- *
- * When keepalive is active, we switch to using the keepalive timeout
- * to determine when to close a connection, rather than the idle timeout.
- */
-
 void
 isc__nm_tlsdns_send(isc_nmhandle_t *handle, isc_region_t *region,
                    isc_nm_cb_t cb, void *cbarg);
@@ -1564,15 +1555,6 @@ isc__nm_tlsdns_cancelread(isc_nmhandle_t *handle);
  * Stop reading on a connected TLSDNS handle.
  */
 
-void
-isc__nm_tlsdns_keepalive(isc_nmhandle_t *handle, bool value);
-/*%<
- * Enable/disable keepalive on this connection by setting it to 'value'.
- *
- * When keepalive is active, we switch to using the keepalive timeout
- * to determine when to close a connection, rather than the idle timeout.
- */
-
 void
 isc__nm_async_tlsdnscycle(isc__networker_t *worker, isc__netievent_t *ev0);
 void
@@ -1647,6 +1629,12 @@ isc__nm_tls_cleartimeout(isc_nmhandle_t *handle);
  * around.
  */
 
+void
+isc__nmhandle_tls_keepalive(isc_nmhandle_t *handle, bool value);
+/*%<
+ * Set the keepalive value on the underlying TCP handle.
+ */
+
 void
 isc__nm_http_stoplistening(isc_nmsocket_t *sock);
 
@@ -1660,6 +1648,12 @@ isc__nm_http_cleartimeout(isc_nmhandle_t *handle);
  * around.
  */
 
+void
+isc__nmhandle_http_keepalive(isc_nmhandle_t *handle, bool value);
+/*%<
+ * Set the keepalive value on the underlying session handle
+ */
+
 void
 isc__nm_http_initsocket(isc_nmsocket_t *sock);
 
index 45b768d069f1005718fbe1f97c690788f931c8e5..cd051ee5173d3042fc55b379928df2760492cc4e 100644 (file)
@@ -2367,16 +2367,33 @@ isc_nmhandle_settimeout(isc_nmhandle_t *handle, uint32_t timeout) {
 
 void
 isc_nmhandle_keepalive(isc_nmhandle_t *handle, bool value) {
+       isc_nmsocket_t *sock = NULL;
+
        REQUIRE(VALID_NMHANDLE(handle));
+       REQUIRE(VALID_NMSOCK(handle->sock));
 
-       switch (handle->sock->type) {
+       sock = handle->sock;
+
+       switch (sock->type) {
+       case isc_nm_tcpsocket:
        case isc_nm_tcpdnssocket:
-               isc__nm_tcpdns_keepalive(handle, value);
-               break;
        case isc_nm_tlsdnssocket:
-               isc__nm_tlsdns_keepalive(handle, value);
+               atomic_store(&sock->keepalive, value);
+               sock->read_timeout = value ? atomic_load(&sock->mgr->keepalive)
+                                          : atomic_load(&sock->mgr->idle);
                break;
+#if HAVE_LIBNGHTTP2
+       case isc_nm_tlssocket:
+               isc__nmhandle_tls_keepalive(handle, value);
+               break;
+       case isc_nm_httpsocket:
+               isc__nmhandle_http_keepalive(handle, value);
+               break;
+#endif /* HAVE_LIBNGHTTP2 */
        default:
+               /*
+                * For any other protocol, this is a no-op.
+                */
                return;
        }
 }
index a612bbbd31e9e0b8fbf7081df02effe3bf5c21f2..11a7111b3ae5adfbdd37fa19a8352dd5d1fce58a 100644 (file)
@@ -1435,16 +1435,3 @@ isc__nm_async_tcpdnscancel(isc__networker_t *worker, isc__netievent_t *ev0) {
 
        isc__nm_failed_read_cb(sock, ISC_R_EOF, false);
 }
-
-void
-isc__nm_tcpdns_keepalive(isc_nmhandle_t *handle, bool value) {
-       isc_nmsocket_t *sock = NULL;
-
-       REQUIRE(VALID_NMHANDLE(handle));
-       REQUIRE(VALID_NMSOCK(handle->sock));
-       REQUIRE(handle->sock->type == isc_nm_tcpdnssocket);
-
-       sock = handle->sock;
-
-       atomic_store(&sock->keepalive, value);
-}
index 7e2f83e526aaa6e3b14802a608a1e34a503b602d..72fe096f5cf6df787973987321fd21799a7f0443 100644 (file)
@@ -2005,16 +2005,3 @@ isc__nm_async_tlsdnscancel(isc__networker_t *worker, isc__netievent_t *ev0) {
 
        isc__nm_failed_read_cb(sock, ISC_R_EOF, false);
 }
-
-void
-isc__nm_tlsdns_keepalive(isc_nmhandle_t *handle, bool value) {
-       isc_nmsocket_t *sock = NULL;
-
-       REQUIRE(VALID_NMHANDLE(handle));
-       REQUIRE(VALID_NMSOCK(handle->sock));
-       REQUIRE(handle->sock->type == isc_nm_tlsdnssocket);
-
-       sock = handle->sock;
-
-       atomic_store(&sock->keepalive, value);
-}
index 0ccf68b4ebc7ab3227e6c5e3cf9ecf95ead0d566..8321b74f3b1912a3e4632109de659df25b0b0f42 100644 (file)
@@ -1043,3 +1043,19 @@ isc__nm_tls_settimeout(isc_nmhandle_t *handle, uint32_t timeout) {
                isc_nmhandle_settimeout(sock->outerhandle, timeout);
        }
 }
+
+void
+isc__nmhandle_tls_keepalive(isc_nmhandle_t *handle, bool value) {
+       isc_nmsocket_t *sock = NULL;
+
+       REQUIRE(VALID_NMHANDLE(handle));
+       REQUIRE(VALID_NMSOCK(handle->sock));
+       REQUIRE(handle->sock->type == isc_nm_tlssocket);
+
+       sock = handle->sock;
+       if (sock->outerhandle != NULL) {
+               INSIST(VALID_NMHANDLE(sock->outerhandle));
+
+               isc_nmhandle_keepalive(sock->outerhandle, value);
+       }
+}