]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add directive dns_v4_first to make IPv4 connections before IPv6 is tried.
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 11 Oct 2011 02:12:56 +0000 (20:12 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 11 Oct 2011 02:12:56 +0000 (20:12 -0600)
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
src/dns_internal.cc
src/structs.h

index 5377fc9c3a674c48d44f0df89e5c0d54100fc76f..a09251da4e77a474ade3332783c9eff77494f3f3 100644 (file)
@@ -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
index 0e13c64387905bc3f02c241f43418a6abe73dc11..52087de6615751bf210ebdb5388bc1116715215c 100644 (file)
@@ -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;
index c32e13ad23ecd3f03474860456e9cfd4af2f2e47..4a5b38f4cfce724a1016f7c41c73fccd0580dc3f 100644 (file)
@@ -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;