--------------------- PatchSet 4132 Date: 2007/03/31 02:39:00 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Fxixed error chckign for mapped addresses under IPv6 Set debug level at 36 (unused level amidst other DNS levels). Members: lib/IPAddress.cc:1.1.2.11->1.1.2.12 Index: squid3/lib/IPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/IPAddress.cc,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -u -r1.1.2.11 -r1.1.2.12 --- squid3/lib/IPAddress.cc 30 Mar 2007 12:40:50 -0000 1.1.2.11 +++ squid3/lib/IPAddress.cc 31 Mar 2007 02:39:00 -0000 1.1.2.12 @@ -1,5 +1,5 @@ /* - * $Id: IPAddress.cc,v 1.1.2.11 2007/03/30 12:40:50 amosjeffries Exp $ + * $Id: IPAddress.cc,v 1.1.2.12 2007/03/31 02:39:00 amosjeffries Exp $ */ #include "IPAddress.h" @@ -16,6 +16,13 @@ #error "INET6 defined but has been deprecated! Try running bootstrap and configure again." #endif +/* We want to use the debug routines when running as module of squid. */ +/* otherwise fallback to printf if those are not available. */ +#ifndef SQUID_DEBUG +# define debugs(a,b) printf +#else +# include "../Debug.h" +#endif /* enum IPAddressType { @@ -107,7 +114,7 @@ bool IPAddress::IsAnyAddr() const { #ifdef USE_IPV6 - return (0 == memcmp(&(m_SocketAddr.sin6_addr), &in6addr_any, sizeof(in6addr_any)) ); + return (0 == memcmp(&m_SocketAddr.sin6_addr, &"\0x00000000\0x00000000\0x00000000\0x00000000", sizeof(m_SocketAddr.sin6_addr) ) ); #else return (INADDR_ANY == m_SocketAddr.sin_addr.s_addr); #endif @@ -231,7 +238,7 @@ } #endif - fprintf(stderr,"ERROR: IPAddress::GetReverseString : Address stored cannot be converted to type requested.\n"); + debugs(36,1)("ERROR: IPAddress::GetReverseString : Address stored cannot be converted to type requested.\n"); buf[0] = '\0'; return false; } @@ -252,7 +259,7 @@ struct hostent *hp = NULL; if ((hp = gethostbyname(s)) == NULL) { - fprintf(stderr, "IPAddress:::operator= : Given Bad IP '%s'\n", s); + debugs(36,1)("IPAddress:::operator= : Given Bad IP '%s'\n", s); return false; } @@ -264,7 +271,7 @@ #endif else { - fprintf(stderr, "IPAddress::operator=(hostent*) : Discarding IP address '%s'.\n",s); + debugs(36,1)("IPAddress::operator=(hostent*) : Discarding IP address '%s'.\n",s); return false; } return true; @@ -292,7 +299,15 @@ void IPAddress::check4Mapped() { /* check for ::ffff:x.x.x.x IPv4-mapped addresses */ - if( 0 == memcmp(&m_SocketAddr.sin6_addr, &"\0x00000000\0x00000000\0x00000000\0xFFFF", (96 + 16) ) ) + if( 0 == memcmp(&m_SocketAddr.sin6_addr, &"\0x00000000\0x00000000\0x00000000\0xFFFF", sizeof(struct in6_addr)-sizeof(struct in_addr) ) ) + { + m_Type = (IPAddressType)(m_Type | IPv4); + } + if( 0 == memcmp(&m_SocketAddr.sin6_addr, &"\0x00000000\0x00000000\0x00000000\0x00000000", sizeof(struct in6_addr) ) ) + { + m_Type = (IPAddressType)(m_Type | IPv4); + } + if( 0 == memcmp(&m_SocketAddr.sin6_addr, &"\0xFFFFFFFF\0xFFFFFFFF\0xFFFFFFFF\0xFFFFFFFF", sizeof(struct in6_addr) ) ) { m_Type = (IPAddressType)(m_Type | IPv4); } @@ -382,7 +397,7 @@ #ifdef USE_IPV6 /* this */ operator=(*ipv6); #else - fprintf(stderr, "IPAddress::operator= : Discarded IPv6 Address. Protocol disabled (temporary).\n"); + debugs(36,1)("IPAddress::operator= : Discarded IPv6 Address. Protocol disabled.\n"); // TODO see if there is another address in the list that might be usable ?? return false; @@ -474,9 +489,10 @@ // Ensure we have a buffer. if(buf == NULL) { - fprintf(stderr,"IPAddress::NtoA : Buffer received has no allocated space.\n"); + debugs(36,1)("IPAddress::NtoA : Buffer received has no allocated space.\n"); return NULL; } + memset(buf,0,blen); if(m_Type & IPv6 ) inet_ntop(AF_INET6, &m_SocketAddr.sin6_addr, buf, blen); @@ -493,7 +509,7 @@ // Ensure we have a buffer. if(buf == NULL) { - fprintf(stderr,"IPAddress::ToURL : Buffer received has no allocated space.\n"); + debugs(36,1)("IPAddress::ToURL : Buffer received has no allocated space.\n"); return NULL; } @@ -522,7 +538,7 @@ if(m_SocketAddr.sin6_port > 0 && p < buf+blen-6) { /* 6 is max length of expected ':port' (short int) */ - snprintf(p,6,":%d", ntohs(m_SocketAddr.sin6_port) ); + snprintf(p,6,":%d", GetPort() ); } // force a null-terminated string @@ -563,21 +579,21 @@ if( in.s_addr == 0x00000000) { memset(&out, 0, sizeof(struct in6_addr)); - return; } - if( in.s_addr == 0xFFFFFFFF) + else if( in.s_addr == 0xFFFFFFFF) { out.s6_addr32[0] = 0xFFFFFFFF; out.s6_addr32[1] = 0xFFFFFFFF; out.s6_addr32[2] = 0xFFFFFFFF; out.s6_addr32[3] = 0xFFFFFFFF; - return; } /* FIXME TODO : handle special case of localhost (IPv4 127.0.0.1, IPv6 ::1 ) */ - - memset(&out, 0, sizeof(struct in6_addr)); - out.s6_addr32[3] = in.s_addr; - out.s6_addr16[5] = (unsigned short)0xFFFF; + else + { + memset(&out, 0, sizeof(struct in6_addr)); + out.s6_addr32[3] = in.s_addr; + out.s6_addr16[5] = (unsigned short)0xFFFF; + } } void IPAddress::Map6to4(const struct in6_addr &in, struct in_addr &out) const { @@ -611,7 +627,7 @@ case IPv6: // non-compatible IPv6 Pure Address default: - fprintf(stderr,"IPAddress::GetInAddr : Cannot convert non-IP to IPv4.\n"); + debugs(36,1)("IPAddress::GetInAddr : Cannot convert non-IP to IPv4.\n"); memset(&buf,0xFFFFFFFF,sizeof(struct in_addr)); return false; }