]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
enable keepalive when the keepalive EDNS option is seen
authorEvan Hunt <each@isc.org>
Tue, 3 Nov 2020 02:33:20 +0000 (18:33 -0800)
committerEvan Hunt <each@isc.org>
Fri, 27 Aug 2021 16:56:51 +0000 (09:56 -0700)
previously, receiving a keepalive option had no effect on how
long named would keep the connection open; there was a place to
configure the keepalive timeout but it was never used. this commit
corrects that.

this also fixes an error in isc__nm_{tcp,tls}dns_keepalive()
in which the sense of a REQUIRE test was reversed; previously this
error had not been noticed because the functions were not being
used.

lib/isc/include/isc/netmgr.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/tcpdns.c
lib/isc/netmgr/tlsdns.c
lib/ns/client.c

index 2a1a2dc86cf08f63ff113492cfa2600dbedc9941..f9433754bd4aca35e9a7a14b34b6457cf4efc0ef 100644 (file)
@@ -161,6 +161,18 @@ isc_nmhandle_cleartimeout(isc_nmhandle_t *handle);
  * both socket layers.
  */
 
+void
+isc_nmhandle_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.
+ *
+ * This applies only to TCP-based DNS connections (i.e., TCPDNS or
+ * TLSDNS). On other types of connection it has no effect.
+ */
+
 isc_sockaddr_t
 isc_nmhandle_peeraddr(isc_nmhandle_t *handle);
 /*%<
index 975e8cc4271ef40f03583dbe108ba01c4989b467..45b768d069f1005718fbe1f97c690788f931c8e5 100644 (file)
@@ -2365,6 +2365,22 @@ isc_nmhandle_settimeout(isc_nmhandle_t *handle, uint32_t timeout) {
        }
 }
 
+void
+isc_nmhandle_keepalive(isc_nmhandle_t *handle, bool value) {
+       REQUIRE(VALID_NMHANDLE(handle));
+
+       switch (handle->sock->type) {
+       case isc_nm_tcpdnssocket:
+               isc__nm_tcpdns_keepalive(handle, value);
+               break;
+       case isc_nm_tlsdnssocket:
+               isc__nm_tlsdns_keepalive(handle, value);
+               break;
+       default:
+               return;
+       }
+}
+
 void *
 isc_nmhandle_getextra(isc_nmhandle_t *handle) {
        REQUIRE(VALID_NMHANDLE(handle));
index a26d0fc44b3d9e523313533177aaf12645dae3c4..a612bbbd31e9e0b8fbf7081df02effe3bf5c21f2 100644 (file)
@@ -1442,7 +1442,7 @@ isc__nm_tcpdns_keepalive(isc_nmhandle_t *handle, bool value) {
 
        REQUIRE(VALID_NMHANDLE(handle));
        REQUIRE(VALID_NMSOCK(handle->sock));
-       REQUIRE(handle->sock->type != isc_nm_tcpdnssocket);
+       REQUIRE(handle->sock->type == isc_nm_tcpdnssocket);
 
        sock = handle->sock;
 
index c4bba552f8be1c1220b1e0a5e3145c9ba18898bf..7e2f83e526aaa6e3b14802a608a1e34a503b602d 100644 (file)
@@ -2012,7 +2012,7 @@ isc__nm_tlsdns_keepalive(isc_nmhandle_t *handle, bool value) {
 
        REQUIRE(VALID_NMHANDLE(handle));
        REQUIRE(VALID_NMSOCK(handle->sock));
-       REQUIRE(handle->sock->type != isc_nm_tlsdnssocket);
+       REQUIRE(handle->sock->type == isc_nm_tlsdnssocket);
 
        sock = handle->sock;
 
index 1a12fb9c875a4e005ef106f380e65c34b5b065cd..34d94d15e78aea2bbc91b07d83c48d4a2e86469d 100644 (file)
@@ -1508,6 +1508,7 @@ process_opt(ns_client_t *client, dns_rdataset_t *opt) {
                                }
                                client->attributes |=
                                        NS_CLIENTATTR_USEKEEPALIVE;
+                               isc_nmhandle_keepalive(client->handle, true);
                                isc_buffer_forward(&optbuf, optlen);
                                break;
                        case DNS_OPT_PAD: