From: Evan Hunt Date: Tue, 3 Nov 2020 02:33:20 +0000 (-0800) Subject: enable keepalive when the keepalive EDNS option is seen X-Git-Tag: v9.17.18~16^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7867b8b57d60d93da3f5f15f0a049fba5fbff35a;p=thirdparty%2Fbind9.git enable keepalive when the keepalive EDNS option is seen 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. --- diff --git a/lib/isc/include/isc/netmgr.h b/lib/isc/include/isc/netmgr.h index 2a1a2dc86cf..f9433754bd4 100644 --- a/lib/isc/include/isc/netmgr.h +++ b/lib/isc/include/isc/netmgr.h @@ -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); /*%< diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 975e8cc4271..45b768d069f 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -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)); diff --git a/lib/isc/netmgr/tcpdns.c b/lib/isc/netmgr/tcpdns.c index a26d0fc44b3..a612bbbd31e 100644 --- a/lib/isc/netmgr/tcpdns.c +++ b/lib/isc/netmgr/tcpdns.c @@ -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; diff --git a/lib/isc/netmgr/tlsdns.c b/lib/isc/netmgr/tlsdns.c index c4bba552f8b..7e2f83e526a 100644 --- a/lib/isc/netmgr/tlsdns.c +++ b/lib/isc/netmgr/tlsdns.c @@ -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; diff --git a/lib/ns/client.c b/lib/ns/client.c index 1a12fb9c875..34d94d15e78 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -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: