From b2ceb1ada827254a7f79c37d8e53627c7ec7fa27 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Mon, 10 Oct 2011 20:12:56 -0600 Subject: [PATCH] Add directive dns_v4_first to make IPv4 connections before IPv6 is tried. Default off, to prefer the faster protocol. The use-case for this is networks which are IPv6-enabled but stuck behind slow tunnels and whose upstream is not supporting full transit services over IP. --- src/cf.data.pre | 19 +++++++++++++++++++ src/dns_internal.cc | 15 ++++++++++++--- src/structs.h | 3 +++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/cf.data.pre b/src/cf.data.pre index 5377fc9c3a..a09251da4e 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -6451,6 +6451,25 @@ DOC_START *) May negatively impact connection delay times. DOC_END +NAME: dns_v4_first +TYPE: onoff +DEFAULT: off +LOC: Config.dns.v4_first +IFDEF: !USE_DNSSERVERS +DOC_START + With the IPv6 Internet being as fast or faster than IPv4 Internet + for most networks Squid prefers to contact websites over IPv6. + + This option reverses the order of preference to make Squid contact + dual-stack websites over IPv4 first. Squid will still perform both + IPv6 and IPv4 DNS lookups before connecting. + + WARNING: + This option will restrict the situations under which IPv6 + connectivity is used (and tested). Hiding network problems + which would otherwise be detected and warned about. +DOC_END + NAME: ipcache_size COMMENT: (number of entries) TYPE: int diff --git a/src/dns_internal.cc b/src/dns_internal.cc index 0e13c64387..52087de661 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -1117,14 +1117,23 @@ idnsGrokReply(const char *buf, size_t sz) debugs(78, 6, HERE << "Merging DNS results " << q->name << " AAAA has " << q->initial_AAAA.count << " RR, A has " << n << " RR"); + if (Config.dns.v4_first) { + memcpy( tmp, message->answer, (sizeof(rfc1035_rr)*n) ); + tmp += n; + /* free the RR object without freeing its child strings (they are now taken by the copy above) */ + safe_free(message->answer); + } + memcpy(tmp, q->initial_AAAA.answers, (sizeof(rfc1035_rr)*(q->initial_AAAA.count)) ); tmp += q->initial_AAAA.count; /* free the RR object without freeing its child strings (they are now taken by the copy above) */ safe_free(q->initial_AAAA.answers); - memcpy( tmp, message->answer, (sizeof(rfc1035_rr)*n) ); - /* free the RR object without freeing its child strings (they are now taken by the copy above) */ - safe_free(message->answer); + if (!Config.dns.v4_first) { + memcpy( tmp, message->answer, (sizeof(rfc1035_rr)*n) ); + /* free the RR object without freeing its child strings (they are now taken by the copy above) */ + safe_free(message->answer); + } n += q->initial_AAAA.count; q->initial_AAAA.count = 0; diff --git a/src/structs.h b/src/structs.h index c32e13ad23..4a5b38f4cf 100644 --- a/src/structs.h +++ b/src/structs.h @@ -628,6 +628,9 @@ struct SquidConfig { #endif int client_ip_max_connections; + struct { + int v4_first; ///< Place IPv4 first in the order of DNS results. + } dns; }; SQUIDCEXTERN SquidConfig Config; -- 2.47.2