]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4222. [func] Bias IPv6 servers when selecting the next server to
authorMark Andrews <marka@isc.org>
Mon, 28 Sep 2015 08:57:19 +0000 (18:57 +1000)
committerMark Andrews <marka@isc.org>
Mon, 28 Sep 2015 08:57:19 +0000 (18:57 +1000)
                        query. [RT #40836]

CHANGES
bin/named/config.c
bin/named/server.c
doc/arm/Bv9ARM-book.xml
doc/misc/options
lib/dns/include/dns/view.h
lib/dns/resolver.c
lib/dns/view.c
lib/isccfg/namedconf.c

diff --git a/CHANGES b/CHANGES
index 320d4c8ede95c6496b0fe6ae0a0bdfa5dda0ee93..66a58e87c079509ed31b0102bd032193e5aff9b3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+4222.  [func]          Bias IPv6 servers when selecting the next server to
+                       query. [RT #40836]
+
 4221.  [bug]           Resource leak on DNS_R_NXDOMAIN in fctx_create.
                        [RT #40583]
 
index 728659360eaa2265347a76997f42ff6e289a89de..fbc6c18acb351631b1791a475420dda15f2a6c46 100644 (file)
@@ -184,6 +184,7 @@ options {\n\
        allow-new-zones no;\n\
        fetches-per-server 0;\n\
        require-server-cookie no;\n\
+       v6-bias 50;\n\
 "
 #ifdef HAVE_GEOIP
 "\
index 734d11e48abaaf9da2b0dca39a0cf196c1bf2c8a..2dbafe89395da10f57ebfbeb7b90244080f7b45e 100644 (file)
@@ -3542,6 +3542,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist,
        INSIST(result == ISC_R_SUCCESS);
        view->requireservercookie = cfg_obj_asboolean(obj);
 
+       obj = NULL;
+       result = ns_config_get(maps, "v6-bias", &obj);
+       INSIST(result == ISC_R_SUCCESS);
+       view->v6bias = cfg_obj_asuint32(obj) * 1000;
+
        obj = NULL;
        result = ns_config_get(maps, "max-clients-per-query", &obj);
        INSIST(result == ISC_R_SUCCESS);
index 04b386ea5cc4e0ee2ca5fd57d91788dc5925c26e..393317f75b48732412380c9567b6645f1b9d7824 100644 (file)
@@ -5035,6 +5035,7 @@ badresp:1,adberr:0,findfail:0,valfail:0]
       <optional> min-ns-dots <replaceable>number</replaceable> </optional>
       <optional> qname-wait-recurse <replaceable>yes_or_no</replaceable> </optional>
     ; </optional>
+    <optional>v6-bias <replaceable>number</replaceable> ; </optional>
 };
 </programlisting>
 
@@ -9590,6 +9591,17 @@ avoid-v6-udp-ports { 40000; range 50000 60000; };
                </para>
              </listitem>
            </varlistentry>
+
+           <varlistentry>
+             <term><command>v6-bias</command></term>
+             <listitem>
+               <para>
+                 When determining the next nameserver to try
+                 preference IPv6 nameservers by this many milliseconds.
+                 The default is <literal>50</literal> milliseconds.
+               </para>
+             </listitem>
+           </varlistentry>
          </variablelist>
 
        </sect3>
index f87992a4949a9e0a0e1b4bbbb9f0627e8b44fe34..fa5a610a572b4cd6c937274fbd412998bf770bb0 100644 (file)
@@ -314,6 +314,7 @@ options {
         use-queryport-pool <boolean>; // obsolete
         use-v4-udp-ports { <portrange>; ... };
         use-v6-udp-ports { <portrange>; ... };
+        v6-bias <integer>;
         version ( <quoted_string> | none );
         zero-no-soa-ttl <boolean>;
         zero-no-soa-ttl-cache <boolean>;
@@ -587,6 +588,7 @@ view <string> [ <class> ] {
         update-check-ksk <boolean>;
         use-alt-transfer-source <boolean>;
         use-queryport-pool <boolean>; // obsolete
+        v6-bias <integer>;
         zero-no-soa-ttl <boolean>;
         zero-no-soa-ttl-cache <boolean>;
         zone <string> [ <class> ] {
index 04126e95a2dae8471c1e8ae559027a85a75186f4..51b41ae41781bee5a0f8bde858bc165640b668f2 100644 (file)
@@ -216,6 +216,7 @@ struct dns_view {
        void                            (*cfg_destroy)(void **);
 
        unsigned char                   secret[32];     /* Client secret */
+       unsigned int                    v6bias;
 };
 
 #define DNS_VIEW_MAGIC                 ISC_MAGIC('V','i','e','w')
index 78310f4cc4834f6e3ffb2a18c2de32c3d0880512..4050905a8af7849ba8bbba335de903b8dea35672 100644 (file)
@@ -2933,18 +2933,32 @@ add_bad(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, isc_result_t reason,
  * Sort addrinfo list by RTT.
  */
 static void
-sort_adbfind(dns_adbfind_t *find) {
+sort_adbfind(dns_adbfind_t *find, unsigned int bias) {
        dns_adbaddrinfo_t *best, *curr;
        dns_adbaddrinfolist_t sorted;
+       int family;
 
        /* Lame N^2 bubble sort. */
        ISC_LIST_INIT(sorted);
        while (!ISC_LIST_EMPTY(find->list)) {
                best = ISC_LIST_HEAD(find->list);
+               family = isc_sockaddr_pf(&best->sockaddr);
                curr = ISC_LIST_NEXT(best, publink);
                while (curr != NULL) {
-                       if (curr->srtt < best->srtt)
-                               best = curr;
+                       if (isc_sockaddr_pf(&curr->sockaddr) == family) {
+                               if (curr->srtt < best->srtt)
+                                       best = curr;
+                       } else if (family == AF_INET6) {
+                               if (curr->srtt + bias < best->srtt) {
+                                       best = curr;
+                                       family = AF_INET;
+                               }
+                       } else {
+                               if (curr->srtt < best->srtt + bias) {
+                                       best = curr;
+                                       family = AF_INET6;
+                               }
+                       }
                        curr = ISC_LIST_NEXT(curr, publink);
                }
                ISC_LIST_UNLINK(find->list, best, publink);
@@ -2957,16 +2971,17 @@ sort_adbfind(dns_adbfind_t *find) {
  * Sort a list of finds by server RTT.
  */
 static void
-sort_finds(dns_adbfindlist_t *findlist) {
+sort_finds(dns_adbfindlist_t *findlist, unsigned int bias) {
        dns_adbfind_t *best, *curr;
        dns_adbfindlist_t sorted;
        dns_adbaddrinfo_t *addrinfo, *bestaddrinfo;
+       int family;
 
        /* Sort each find's addrinfo list by SRTT. */
        for (curr = ISC_LIST_HEAD(*findlist);
             curr != NULL;
             curr = ISC_LIST_NEXT(curr, publink))
-               sort_adbfind(curr);
+               sort_adbfind(curr, bias);
 
        /* Lame N^2 bubble sort. */
        ISC_LIST_INIT(sorted);
@@ -2974,13 +2989,30 @@ sort_finds(dns_adbfindlist_t *findlist) {
                best = ISC_LIST_HEAD(*findlist);
                bestaddrinfo = ISC_LIST_HEAD(best->list);
                INSIST(bestaddrinfo != NULL);
+               family = isc_sockaddr_pf(&bestaddrinfo->sockaddr);
                curr = ISC_LIST_NEXT(best, publink);
                while (curr != NULL) {
                        addrinfo = ISC_LIST_HEAD(curr->list);
                        INSIST(addrinfo != NULL);
-                       if (addrinfo->srtt < bestaddrinfo->srtt) {
-                               best = curr;
-                               bestaddrinfo = addrinfo;
+                       if (isc_sockaddr_pf(&addrinfo->sockaddr) == family) {
+                               if (addrinfo->srtt < bestaddrinfo->srtt) {
+                                       best = curr;
+                                       bestaddrinfo = addrinfo;
+                               }
+                       } else if (family == AF_INET6) {
+                               if (addrinfo->srtt + bias <
+                                   bestaddrinfo->srtt) {
+                                       best = curr;
+                                       bestaddrinfo = addrinfo;
+                                       family = AF_INET;
+                               }
+                       } else {
+                               if (addrinfo->srtt <
+                                    bestaddrinfo->srtt + bias) {
+                                       best = curr;
+                                       bestaddrinfo = addrinfo;
+                                       family = AF_INET6;
+                               }
                        }
                        curr = ISC_LIST_NEXT(curr, publink);
                }
@@ -3394,8 +3426,8 @@ fctx_getaddresses(fetchctx_t *fctx, isc_boolean_t badcache) {
                 * We've found some addresses.  We might still be looking
                 * for more addresses.
                 */
-               sort_finds(&fctx->finds);
-               sort_finds(&fctx->altfinds);
+               sort_finds(&fctx->finds, res->view->v6bias);
+               sort_finds(&fctx->altfinds, 0);
                result = ISC_R_SUCCESS;
        }
 
index 6220c7d32157858ad724704fc5cb4afc4cc17667..6d47aebc71f7b0c0d80a2f6f80c39f729a3cfd1f 100644 (file)
@@ -240,6 +240,7 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
        view->cfg_destroy = NULL;
        view->fail_ttl = 0;
        view->failcache = NULL;
+       view->v6bias = 0;
        dns_badcache_init(view->mctx, DNS_VIEW_FAILCACHESIZE, &view->failcache);
 
        if (isc_bind9) {
index d402327c269b7d6f328a1439bd003f3916a6b235..ce2db8c5ace41c8d657a658581fef56cae3ef4a7 100644 (file)
@@ -1578,6 +1578,18 @@ view_clauses[] = {
        { "fetch-quota-params", &cfg_type_fetchquota, 0 },
        { "fetches-per-server", &cfg_type_fetchesper, 0 },
        { "fetches-per-zone", &cfg_type_fetchesper, 0 },
+#ifdef ALLOW_FILTER_AAAA
+       { "filter-aaaa", &cfg_type_bracketed_aml, 0 },
+       { "filter-aaaa-on-v4", &cfg_type_filter_aaaa, 0 },
+       { "filter-aaaa-on-v6", &cfg_type_filter_aaaa, 0 },
+#else
+       { "filter-aaaa", &cfg_type_bracketed_aml,
+          CFG_CLAUSEFLAG_NOTCONFIGURED },
+       { "filter-aaaa-on-v4", &cfg_type_filter_aaaa,
+          CFG_CLAUSEFLAG_NOTCONFIGURED },
+       { "filter-aaaa-on-v6", &cfg_type_filter_aaaa,
+          CFG_CLAUSEFLAG_NOTCONFIGURED },
+#endif
        { "ixfr-from-differences", &cfg_type_ixfrdifftype, 0 },
        { "lame-ttl", &cfg_type_ttlval, 0 },
        { "nocookie-udp-size", &cfg_type_uint32, 0 },
@@ -1608,11 +1620,13 @@ view_clauses[] = {
        { "queryport-pool-ports", &cfg_type_uint32, CFG_CLAUSEFLAG_OBSOLETE },
        { "queryport-pool-updateinterval", &cfg_type_uint32,
          CFG_CLAUSEFLAG_OBSOLETE },
+       { "rate-limit", &cfg_type_rrl, 0 },
        { "recursion", &cfg_type_boolean, 0 },
        { "request-sit", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
        { "request-nsid", &cfg_type_boolean, 0 },
        { "require-server-cookie", &cfg_type_boolean, 0 },
        { "resolver-query-timeout", &cfg_type_uint32, 0 },
+       { "response-policy", &cfg_type_rpz, 0 },
        { "rfc2308-type1", &cfg_type_boolean, CFG_CLAUSEFLAG_NYI },
        { "root-delegation-only",  &cfg_type_optional_exclude, 0 },
        { "rrset-order", &cfg_type_rrsetorder, 0 },
@@ -1623,21 +1637,8 @@ view_clauses[] = {
        { "topology", &cfg_type_bracketed_aml, CFG_CLAUSEFLAG_NOTIMP },
        { "transfer-format", &cfg_type_transferformat, 0 },
        { "use-queryport-pool", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE },
+       { "v6-bias", &cfg_type_uint32, 0 },
        { "zero-no-soa-ttl-cache", &cfg_type_boolean, 0 },
-#ifdef ALLOW_FILTER_AAAA
-       { "filter-aaaa", &cfg_type_bracketed_aml, 0 },
-       { "filter-aaaa-on-v4", &cfg_type_filter_aaaa, 0 },
-       { "filter-aaaa-on-v6", &cfg_type_filter_aaaa, 0 },
-#else
-       { "filter-aaaa", &cfg_type_bracketed_aml,
-          CFG_CLAUSEFLAG_NOTCONFIGURED },
-       { "filter-aaaa-on-v4", &cfg_type_filter_aaaa,
-          CFG_CLAUSEFLAG_NOTCONFIGURED },
-       { "filter-aaaa-on-v6", &cfg_type_filter_aaaa,
-          CFG_CLAUSEFLAG_NOTCONFIGURED },
-#endif
-       { "response-policy", &cfg_type_rpz, 0 },
-       { "rate-limit", &cfg_type_rrl, 0 },
        { NULL, NULL, 0 }
 };
 
@@ -1815,8 +1816,11 @@ view_clausesets[] = {
        zone_clauses,
        NULL
 };
+
 static cfg_type_t cfg_type_viewopts = {
-       "view", cfg_parse_map, cfg_print_map, cfg_doc_map, &cfg_rep_map, view_clausesets };
+       "view", cfg_parse_map, cfg_print_map, cfg_doc_map, &cfg_rep_map,
+       view_clausesets
+};
 
 /*% The "zone" statement syntax. */