]> 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>
Sun, 9 Oct 2011 05:44:22 +0000 (23:44 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 9 Oct 2011 05:44:22 +0000 (23:44 -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 11d333e4ffd9482e1da63902d15385b8855173f3..079607ce00ccfb0b68450b648f899e0ef4998f32 100644 (file)
@@ -7243,6 +7243,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 b2841871ba138e2678b605394cb1ee335062b2a0..65a10cba873eb0c40512828482f7e22a9acf6e1a 100644 (file)
@@ -1217,14 +1217,23 @@ idnsGrokReply(const char *buf, size_t sz, int from_ns)
 
         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 7f90ecd5910addf6ebe807ed1da7ab011f94b93b..884786d421afc8d21bee4e531eb6bed71b2853fc 100644 (file)
@@ -644,6 +644,7 @@ struct SquidConfig {
     int client_ip_max_connections;
 
     struct {
+        int v4_first;       ///< Place IPv4 first in the order of DNS results.
         ssize_t packet_max; ///< maximum size EDNS advertised for DNS replies.
     } dns;
 };