]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Added option for disabling stale-answer-client-timeout
authorDiego Fronza <diego@isc.org>
Fri, 18 Dec 2020 19:24:56 +0000 (16:24 -0300)
committerDiego Fronza <diego@isc.org>
Mon, 25 Jan 2021 13:47:14 +0000 (10:47 -0300)
This commit allows to specify "disabled" or "off" in
stale-answer-client-timeout statement. The logic to support this
behavior will be added in the subsequent commits.

This commit also ensures an upper bound to stale-answer-client-timeout
which equals to one second less than 'resolver-query-timeout'.

bin/named/server.c
lib/isccfg/namedconf.c

index 6888333087c6417e499bd39e93185589b905eb32..19a0693fc5ca8aff3478dc48d13d6efc3e25ae26 100644 (file)
@@ -4488,7 +4488,19 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
        obj = NULL;
        result = named_config_get(maps, "stale-answer-client-timeout", &obj);
        INSIST(result == ISC_R_SUCCESS);
-       view->staleanswerclienttimeout = cfg_obj_asuint32(obj);
+       if (cfg_obj_isstring(obj)) {
+               /*
+                * The only string values available for this option
+                * are "disabled" and "off".
+                * We use (uint32_t) -1 to represent disabled since
+                * a value of zero means that stale data can be used
+                * to promptly answer the query, while an attempt to
+                * refresh the RRset will still be made in background.
+                */
+               view->staleanswerclienttimeout = (uint32_t)-1;
+       } else {
+               view->staleanswerclienttimeout = cfg_obj_asuint32(obj);
+       }
 
        obj = NULL;
        result = named_config_get(maps, "stale-refresh-time", &obj);
@@ -4779,6 +4791,27 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
        query_timeout = cfg_obj_asuint32(obj);
        dns_resolver_settimeout(view->resolver, query_timeout);
 
+       /*
+        * Adjust stale-answer-client-timeout upper bound
+        * to be resolver-query-timeout - 1s.
+        * This assignment is safe as dns_resolver_settimeout()
+        * ensures that resolver->querytimeout value will be in the
+        * [MINIMUM_QUERY_TIMEOUT, MAXIMUM_QUERY_TIMEOUT] range and
+        * MINIMUM_QUERY_TIMEOUT is > 1000 (in ms).
+        */
+       if (view->staleanswerclienttimeout != (uint32_t)-1 &&
+           view->staleanswerclienttimeout >
+                   (dns_resolver_gettimeout(view->resolver) - 1000))
+       {
+               view->staleanswerclienttimeout =
+                       dns_resolver_gettimeout(view->resolver) - 1000;
+               isc_log_write(
+                       named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
+                       NAMED_LOGMODULE_SERVER, ISC_LOG_WARNING,
+                       "stale-answer-client-timeout adjusted to %" PRIu32,
+                       view->staleanswerclienttimeout);
+       }
+
        /* Specify whether to use 0-TTL for negative response for SOA query */
        dns_resolver_setzeronosoattl(view->resolver, zero_no_soattl);
 
index 6b7c6fbabefaf4ea240751f0d84545d65029c8fa..1ca22dd8d2076ca3d1addbd52e115082e7fa0cf7 100644 (file)
@@ -1899,6 +1899,28 @@ static cfg_type_t cfg_type_dns64 = { "dns64",        cfg_parse_netprefix_map,
                                     cfg_print_map, cfg_doc_map,
                                     &cfg_rep_map,  dns64_clausesets };
 
+static const char *staleanswerclienttimeout_enums[] = { "disabled", "off",
+                                                       NULL };
+static isc_result_t
+parse_staleanswerclienttimeout(cfg_parser_t *pctx, const cfg_type_t *type,
+                              cfg_obj_t **ret) {
+       return (cfg_parse_enum_or_other(pctx, type, &cfg_type_uint32, ret));
+}
+
+static void
+doc_staleanswerclienttimeout(cfg_printer_t *pctx, const cfg_type_t *type) {
+       cfg_doc_enum_or_other(pctx, type, &cfg_type_uint32);
+}
+
+static cfg_type_t cfg_type_staleanswerclienttimeout = {
+       "staleanswerclienttimeout",
+       parse_staleanswerclienttimeout,
+       cfg_print_ustring,
+       doc_staleanswerclienttimeout,
+       &cfg_rep_string,
+       staleanswerclienttimeout_enums
+};
+
 /*%
  * Clauses that can be found within the 'view' statement,
  * with defaults in the 'options' statement.
@@ -2027,7 +2049,8 @@ static cfg_clausedef_t view_clauses[] = {
        { "servfail-ttl", &cfg_type_duration, 0 },
        { "sortlist", &cfg_type_bracketed_aml, 0 },
        { "stale-answer-enable", &cfg_type_boolean, 0 },
-       { "stale-answer-client-timeout", &cfg_type_uint32, 0 },
+       { "stale-answer-client-timeout", &cfg_type_staleanswerclienttimeout,
+         0 },
        { "stale-answer-ttl", &cfg_type_duration, 0 },
        { "stale-cache-enable", &cfg_type_boolean, 0 },
        { "stale-refresh-time", &cfg_type_duration, 0 },