From: Amos Jeffries Date: Mon, 17 Aug 2009 03:11:44 +0000 (+1200) Subject: Undo revno 9911. Not quite doable yet. X-Git-Tag: SQUID_3_2_0_1~784 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b5587d15c53ea6b249ae7a341c22966998b1d888;p=thirdparty%2Fsquid.git Undo revno 9911. Not quite doable yet. --- diff --git a/src/ip/IpAddress.cc b/src/ip/IpAddress.cc index bfb0a11c78..997e49b4e6 100644 --- a/src/ip/IpAddress.cc +++ b/src/ip/IpAddress.cc @@ -36,7 +36,6 @@ #include "config.h" #include "ip/IpAddress.h" -#include "Debug.h" #include "util.h" @@ -57,6 +56,15 @@ #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,c) // drop. +#else +#warning "IpAddress built with Debugs!!" +# include "../src/Debug.h" +#endif + #if !USE_IPV6 // So there are some places where I will drop to using Macros too. // At least I can restrict them to this file so they don't corrupt the app with C code. @@ -170,6 +178,9 @@ 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; } @@ -533,6 +544,9 @@ 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; }; @@ -553,6 +567,12 @@ 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) { @@ -563,6 +583,9 @@ IpAddress::IpAddress(struct sockaddr_in6 const &s) IpAddress& IpAddress::operator =(struct sockaddr_in6 const &s) { memcpy(&m_SocketAddr, &s, sizeof(struct sockaddr_in6)); + + /* maintain address family properly */ + check4Mapped(); return *this; }; @@ -579,9 +602,16 @@ IpAddress& IpAddress::operator =(struct in_addr const &s) #if USE_IPV6 Map4to6((const in_addr)s, m_SocketAddr.sin6_addr); m_SocketAddr.sin6_family = AF_INET6; + #else + memcpy(&m_SocketAddr.sin_addr, &s, sizeof(struct in_addr)); + #endif + + /* maintain stored family type properly */ + check4Mapped(); + return *this; }; @@ -595,8 +625,13 @@ IpAddress::IpAddress(struct in6_addr const &s) 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; }; diff --git a/src/ip/IpAddress.h b/src/ip/IpAddress.h index df6ee8dd56..635cdad402 100644 --- a/src/ip/IpAddress.h +++ b/src/ip/IpAddress.h @@ -390,6 +390,8 @@ 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;