]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 2994: pt 2: Open ports as IP4-only when IPv6 disabled
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 1 Aug 2010 04:33:31 +0000 (16:33 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 1 Aug 2010 04:33:31 +0000 (16:33 +1200)
src/forward.cc

index fcc5d009f4b462e6967816aef6a81cdfa20187d7..41461410caea3f87a0c6ca6fc0b5af3f6397d917 100644 (file)
@@ -48,6 +48,7 @@
 #include "Store.h"
 #include "icmp/net_db.h"
 #include "ip/Intercept.h"
+#include "ip/tools.h"
 
 static PSC fwdStartCompleteWrapper;
 static PF fwdServerClosedWrapper;
@@ -871,6 +872,24 @@ FwdState::connectStart()
 
     outgoing = getOutgoingAddr(request, fs->_peer);
 
+    // if IPv6 is disabled try to force IPv4-only outgoing.
+    if (!Ip::EnableIpv6 && !outgoing.SetIPv4()) {
+        debugs(50, 4, "fwdConnectStart: " << xstrerror());
+        ErrorState *anErr = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE, request);
+        anErr->xerrno = errno;
+        fail(anErr);
+        self = NULL;   // refcounted
+        return;
+    }
+
+    // if IPv6 is split-stack, prefer IPv4
+    if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK) {
+        // NP: This is not a great choice of default,
+        // but with the current Internet being IPv4-majority has a higher success rate.
+        // if setting to IPv4 fails we dont care, that just means to use IPv6 outgoing.
+        outgoing.SetIPv4();
+    }
+
     tos = getOutgoingTOS(request);
 
     debugs(17, 3, "fwdConnectStart: got outgoing addr " << outgoing << ", tos " << tos);