From: Henrik Nordstrom Date: Fri, 14 May 2010 04:16:42 +0000 (+0200) Subject: More work on IPv4 fallback. Preserve IPv4 address status, and kill unused check4Mappe... X-Git-Tag: SQUID_3_1_4~25^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1f860e27bb392593df090ce521b81cc951de34b3;p=thirdparty%2Fsquid.git More work on IPv4 fallback. Preserve IPv4 address status, and kill unused check4Mapped method --- diff --git a/src/comm.cc b/src/comm.cc index 16618c0ac2..c407d598bd 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -718,7 +718,7 @@ comm_openex(int sock_type, #if USE_IPV6 /* under IPv6 there is the possibility IPv6 is present but disabled. */ /* try again as IPv4-native if possible */ - if ( sock < 0 && addr.IsIPv6() && addr.SetIPv4() ) { + if ( new_socket < 0 && addr.IsIPv6() && addr.SetIPv4() ) { /* attempt to open this IPv4-only. */ addr.FreeAddrInfo(AI); /* Setup the socket addrinfo details for use */ @@ -726,7 +726,7 @@ comm_openex(int sock_type, AI->ai_socktype = sock_type; AI->ai_protocol = proto; debugs(50, 3, "comm_openex: Attempt fallback open socket for: " << addr ); - new_socket = comm_openex(sock_type, proto, addr, flags, 0, note); + new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol); debugs(50, 2, HERE << "attempt open " << note << " socket on: " << addr); } #endif diff --git a/src/ip/IpAddress.cc b/src/ip/IpAddress.cc index 5455e0b24d..4529e757d3 100644 --- a/src/ip/IpAddress.cc +++ b/src/ip/IpAddress.cc @@ -168,9 +168,6 @@ const int IpAddress::ApplyMask(IpAddress const &mask_addr) p1[i] &= p2[i]; } - /* we have found a situation where mask forms or destroys a IPv4 map. */ - check4Mapped(); - return changes; } @@ -288,6 +285,9 @@ const struct in6_addr IpAddress::v4_localhost = {{{ 0x00, 0x00, 0x00, 0x00, 0x00 const struct in6_addr IpAddress::v4_anyaddr = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }} }; +const struct in6_addr IpAddress::v4_noaddr = {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }} +}; const struct in6_addr IpAddress::v6_noaddr = {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }} }; @@ -486,9 +486,6 @@ bool IpAddress::LookupHostIP(const char *s, bool nodns) operator=(*res); SetPort(port); - /* free the memory xgetaddrinfo() dynamically allocated. */ - xfreeaddrinfo(res); - res = NULL; return true; @@ -511,9 +508,6 @@ IpAddress& IpAddress::operator =(struct sockaddr_in const &s) memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in)); #endif - /* maintain stored family values properly */ - check4Mapped(); - return *this; }; @@ -534,12 +528,6 @@ IpAddress& IpAddress::operator =(const struct sockaddr_storage &s) return *this; }; -void IpAddress::check4Mapped() -{ - // obsolete. - // TODO use this NOW to set the sin6_family properly on exporting. not on import. -} - #if USE_IPV6 IpAddress::IpAddress(struct sockaddr_in6 const &s) { @@ -551,8 +539,6 @@ IpAddress& IpAddress::operator =(struct sockaddr_in6 const &s) { memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in6)); - /* maintain address family properly */ - check4Mapped(); return *this; }; @@ -575,10 +561,6 @@ IpAddress& IpAddress::operator =(struct in_addr const &s) memcpy(&m_SocketAddr.sin_addr, &s, sizeof(struct in_addr)); #endif - - /* maintain stored family type properly */ - check4Mapped(); - return *this; }; @@ -596,9 +578,6 @@ IpAddress& IpAddress::operator =(struct in6_addr const &s) memcpy(&m_SocketAddr.sin6_addr, &s, sizeof(struct in6_addr)); m_SocketAddr.sin6_family = AF_INET6; - /* maintain address family type properly */ - check4Mapped(); - return *this; }; @@ -1123,15 +1102,13 @@ void IpAddress::Map4to6(const struct in_addr &in, struct in6_addr &out) const if ( in.s_addr == 0x00000000) { /* ANYADDR */ - memset(&out, 0, sizeof(struct in6_addr)); + out = v4_anyaddr; } else if ( in.s_addr == 0xFFFFFFFF) { /* NOADDR */ - memset(&out, 255, sizeof(struct in6_addr)); + out = v4_noaddr; } else { /* general */ - memset(&out, 0, sizeof(struct in6_addr)); - out.s6_addr[10] = 0xFF; - out.s6_addr[11] = 0xFF; + out = v4_anyaddr; out.s6_addr[12] = ((uint8_t *)&in.s_addr)[0]; out.s6_addr[13] = ((uint8_t *)&in.s_addr)[1]; out.s6_addr[14] = ((uint8_t *)&in.s_addr)[2]; diff --git a/src/ip/IpAddress.h b/src/ip/IpAddress.h index 446effa48b..2874118823 100644 --- a/src/ip/IpAddress.h +++ b/src/ip/IpAddress.h @@ -390,8 +390,6 @@ private: bool GetReverseString4(char buf[MAX_IPSTRLEN], const struct in_addr &dat) const; - void check4Mapped(); - #if USE_IPV6 bool GetReverseString6(char buf[MAX_IPSTRLEN], const struct in6_addr &dat) const; @@ -426,6 +424,7 @@ private: static const unsigned int MAX_IP6_STRLEN = STRLEN_IP6R; static const struct in6_addr v4_localhost; static const struct in6_addr v4_anyaddr; + static const struct in6_addr v4_noaddr; static const struct in6_addr v6_noaddr; #endif };