]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
More work on IPv4 fallback. Preserve IPv4 address status, and kill unused check4Mappe...
authorHenrik Nordstrom <henrik@henriknordstrom.net>
Fri, 14 May 2010 04:16:42 +0000 (06:16 +0200)
committerHenrik Nordstrom <henrik@henriknordstrom.net>
Fri, 14 May 2010 04:16:42 +0000 (06:16 +0200)
src/comm.cc
src/ip/IpAddress.cc
src/ip/IpAddress.h

index 16618c0ac2e25ddf8ee4854a9c3fbbf9cdeeed07..c407d598bd6ea3c19e66b0bf0d9d106e8b78dc12 100644 (file)
@@ -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
index 5455e0b24d6f5e9600c508ecaa5955dd6d8e72db..4529e757d35e1398af421d2ae38036407f063959 100644 (file)
@@ -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];
index 446effa48bd6d8d2dbaadd0d981dc1b0ab85dd4d..287411882359b1eec8609f2d87fc355e9745b74c 100644 (file)
@@ -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
 };