From: Amos Jeffries Date: Sun, 1 Aug 2010 04:33:31 +0000 (+1200) Subject: Bug 2994: pt 2: Open ports as IP4-only when IPv6 disabled X-Git-Tag: take1~432 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=407b9bb1bbf85f02230e794544113bc0afbd51ea;p=thirdparty%2Fsquid.git Bug 2994: pt 2: Open ports as IP4-only when IPv6 disabled --- diff --git a/src/forward.cc b/src/forward.cc index fcc5d009f4..41461410ca 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -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);