From 7867b8b57d60d93da3f5f15f0a049fba5fbff35a Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Mon, 2 Nov 2020 18:33:20 -0800 Subject: [PATCH] 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. --- lib/isc/include/isc/netmgr.h | 12 ++++++++++++ lib/isc/netmgr/netmgr.c | 16 ++++++++++++++++ lib/isc/netmgr/tcpdns.c | 2 +- lib/isc/netmgr/tlsdns.c | 2 +- lib/ns/client.c | 1 + 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/isc/include/isc/netmgr.h b/lib/isc/include/isc/netmgr.h index 2a1a2dc86c..f9433754bd 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 975e8cc427..45b768d069 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 a26d0fc44b..a612bbbd31 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 c4bba552f8..7e2f83e526 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 1a12fb9c87..34d94d15e7 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: