--------------------- PatchSet 4094 Date: 2007/03/11 09:56:29 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: More IPAddress rollout to ACLIp, now it compiles clean- and fully again Members: src/ACLIP.cc:1.8.2.12->1.8.2.13 src/ACLIP.h:1.6.2.3->1.6.2.4 src/ACLMyIP.cc:1.5->1.5.6.1 src/ACLSourceIP.cc:1.5->1.5.6.1 src/Debug.h:1.7.8.1->1.7.8.2 src/IPAddress.cc:1.1.2.8->1.1.2.9 src/IPAddress.h:1.1.2.8->1.1.2.9 Index: squid3/src/ACLIP.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ACLIP.cc,v retrieving revision 1.8.2.12 retrieving revision 1.8.2.13 diff -u -r1.8.2.12 -r1.8.2.13 --- squid3/src/ACLIP.cc 9 Mar 2007 11:46:27 -0000 1.8.2.12 +++ squid3/src/ACLIP.cc 11 Mar 2007 09:56:29 -0000 1.8.2.13 @@ -1,5 +1,5 @@ /* - * $Id: ACLIP.cc,v 1.8.2.12 2007/03/09 11:46:27 amosjeffries Exp $ + * $Id: ACLIP.cc,v 1.8.2.13 2007/03/11 09:56:29 amosjeffries Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -212,7 +212,7 @@ /* dotted notation 2003:800::3 */ /* 255.255.255.0 */ - if (mask == asc) /* FIXME : parse asc via gethostbymane ?? internal or external ?? */ + if (mask == asc) return true; // else false. @@ -233,9 +233,9 @@ acl_ip_data * acl_ip_data::FactoryParse(const char *t) { - LOCAL_ARRAY(char, addr1, 256); - LOCAL_ARRAY(char, addr2, 256); - LOCAL_ARRAY(char, mask, 256); + LOCAL_ARRAY(char, l_addr1, 256); + LOCAL_ARRAY(char, l_addr2, 256); + LOCAL_ARRAY(char, l_mask, 256); acl_ip_data *r; acl_ip_data **Q; char **x; @@ -253,48 +253,49 @@ } // IPv4 - if (sscanf(t, SCAN_ACL1_4, addr1, addr2, mask) == 3) { + if (sscanf(t, SCAN_ACL1_4, l_addr1, l_addr2, l_mask) == 3) { (void) 0; iptype=IPv4; - } else if (sscanf(t, SCAN_ACL2_4, addr1, addr2, &c) >= 2) { - mask[0] = '\0'; + } else if (sscanf(t, SCAN_ACL2_4,l_addr1, l_addr2, &c) >= 2) { + l_mask[0] = '\0'; iptype=IPv4; - } else if (sscanf(t, SCAN_ACL3_4, addr1, mask) == 2) { - addr2[0] = '\0'; + } else if (sscanf(t, SCAN_ACL3_4, l_addr1, l_mask) == 2) { + l_addr2[0] = '\0'; iptype=IPv4; - } else if (sscanf(t, SCAN_ACL4_4, addr1, mask) == 2) { - addr2[0] = '\0'; + } else if (sscanf(t, SCAN_ACL4_4, l_addr1,l_mask) == 2) { + l_addr2[0] = '\0'; iptype=IPv4; // IPv6 - } else if (sscanf(t, SCAN_ACL1_6, addr1, addr2, mask) == 3) { + } else if (sscanf(t, SCAN_ACL1_6, l_addr1, l_addr2, l_mask) == 3) { (void) 0; iptype=IPv6; - } else if (sscanf(t, SCAN_ACL2_6, addr1, addr2, &c) >= 2) { - mask[0] = '\0'; + } else if (sscanf(t, SCAN_ACL2_6, l_addr1, l_addr2, &c) >= 2) { + l_mask[0] = '\0'; iptype=IPv6; - } else if (sscanf(t, SCAN_ACL3_6, addr1, mask) == 2) { - addr2[0] = '\0'; + } else if (sscanf(t, SCAN_ACL3_6, l_addr1, l_mask) == 2) { + l_addr2[0] = '\0'; iptype=IPv6; - } else if (sscanf(t, SCAN_ACL4_6, addr1, mask) == 2) { - addr2[0] = '\0'; + } else if (sscanf(t, SCAN_ACL4_6, l_addr1, l_mask) == 2) { + l_addr2[0] = '\0'; iptype=IPv6; // Neither - } else if (sscanf(t, "%s", addr1) == 1) { - addr2[0] = '\0'; - mask[0] = '\0'; + } else if (sscanf(t, "%s", l_addr1) == 1) { + l_addr2[0] = '\0'; + l_mask[0] = '\0'; } - if (!*addr2) { + if (!*l_addr2) { /* * Note, must use plain gethostbyname() here because at startup * ipcache hasn't been initialized */ + /* FIXME : wondering about making this lookup a public library function provided by IPAddress */ struct hostent *hp; - if ((hp = gethostbyname(addr1)) == NULL) { + if ((hp = gethostbyname(l_addr1)) == NULL) { debug(28, 0) ("aclParseIpData: Bad host/IP: '%s'\n", t); self_destruct(); } @@ -305,11 +306,26 @@ if ((r = *Q) == NULL) r = *Q = new acl_ip_data; - r->addr1 = x; + if(hp->h_addrtype == AF_INET) + { + IPAddress ipv4(*((in_addr*)x)); + r->addr1 = ipv4; + } + else if(hp->h_addrtype == AF_INET6) + { +#ifdef INET6 + IPAddress ipv6(*((in6_addr*)x)) + r->addr1 = ipv6; +#else + // Drop the IPv6 Address +#endif + } + else r->addr1.SetAnyAddr(); + r->addr2.SetAnyAddr(); - if (!DecodeMask(mask, r->mask, iptype)) { - debug(28, 0) ("aclParseIpData: unknown netmask '%s' in '%s'\n", mask, t); + if (!DecodeMask(l_mask, r->mask, iptype)) { + debug(28, 0) ("aclParseIpData: unknown netmask '%s' in '%s'\n", l_mask, t); delete r; *Q = NULL; self_destruct(); @@ -318,7 +334,7 @@ Q = &r->next; - debug(28, 3) ("%s --> %s\n", addr1, r->addr1.NtoA(tmpbuf,MAX_IPSTRLEN)); + debug(28, 3) ("%s --> %s\n", l_addr1, r->addr1.NtoA(tmpbuf,MAX_IPSTRLEN)); } if (*Q != NULL) { @@ -330,25 +346,27 @@ } /* Decode addr1 */ - if (!( &q->addr1 = addr1) ) { + if (!l_addr1) { debug(28, 0) ("aclParseIpData: unknown first address in '%s'\n", t); delete q; self_destruct(); return NULL; } + else q->addr1 = l_addr1; /* Decode addr2 */ - if (!( &q->addr2 = addr2) ) { + if (!l_addr2) { debug(28, 0) ("aclParseIpData: unknown second address in '%s'\n", t); delete q; self_destruct(); return NULL; } + else q->addr2 = l_addr2; /* Decode mask */ - if (!DecodeMask(mask, q->mask, iptype)) { - debug(28, 0) ("aclParseIpData: unknown netmask '%s' in '%s'\n", mask, t); + if (!DecodeMask(l_mask, q->mask, iptype)) { + debug(28, 0) ("aclParseIpData: unknown netmask '%s' in '%s'\n", l_mask, t); delete q; self_destruct(); return NULL; @@ -428,13 +446,14 @@ * address. Since we are scanning for a single IP mask and addr2 * MUST be set to empty. */ + char tmpbuf[MAX_IPSTRLEN]; ClientAddress.addr1 = clientip; ClientAddress.addr2.SetEmpty(); ClientAddress.mask.SetEmpty(); acl_ip_data *ClientAddressPointer = &ClientAddress; data = data->splay(ClientAddressPointer, aclIpAddrNetworkCompare); debug(28, 3) ("aclMatchIp: '%s' %s\n", - clientip.NtoA(), splayLastResult ? "NOT found" : "found"); + clientip.NtoA(tmpbuf,MAX_IPSTRLEN), splayLastResult ? "NOT found" : "found"); return !splayLastResult; } Index: squid3/src/ACLIP.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ACLIP.h,v retrieving revision 1.6.2.3 retrieving revision 1.6.2.4 diff -u -r1.6.2.3 -r1.6.2.4 --- squid3/src/ACLIP.h 9 Mar 2007 05:48:32 -0000 1.6.2.3 +++ squid3/src/ACLIP.h 11 Mar 2007 09:56:29 -0000 1.6.2.4 @@ -1,6 +1,6 @@ /* - * $Id: ACLIP.h,v 1.6.2.3 2007/03/09 05:48:32 amosjeffries Exp $ + * $Id: ACLIP.h,v 1.6.2.4 2007/03/11 09:56:29 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -60,7 +60,7 @@ private: - static bool DecodeMask(const char *asc, IPAddress *mask); + static bool DecodeMask(const char *asc, IPAddress &mask, IPAddressType string_format_type); }; MEMPROXY_CLASS_INLINE(acl_ip_data) Index: squid3/src/ACLMyIP.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ACLMyIP.cc,v retrieving revision 1.5 retrieving revision 1.5.6.1 diff -u -r1.5 -r1.5.6.1 --- squid3/src/ACLMyIP.cc 31 Aug 2004 02:14:26 -0000 1.5 +++ squid3/src/ACLMyIP.cc 11 Mar 2007 09:56:29 -0000 1.5.6.1 @@ -1,5 +1,5 @@ /* - * $Id: ACLMyIP.cc,v 1.5 2004/08/31 02:14:26 squidadm Exp $ + * $Id: ACLMyIP.cc,v 1.5.6.1 2007/03/11 09:56:29 amosjeffries Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -46,7 +46,8 @@ int ACLMyIP::match(ACLChecklist *checklist) { - return ACLIP::match (checklist->my_addr); + /* FIXME : remove temporary conversion */ IPAddress tmp(checklist->my_addr); + return ACLIP::match (tmp); } ACL::Prototype ACLMyIP::RegistryProtoype(&ACLMyIP::RegistryEntry(), "myip"); Index: squid3/src/ACLSourceIP.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ACLSourceIP.cc,v retrieving revision 1.5 retrieving revision 1.5.6.1 diff -u -r1.5 -r1.5.6.1 --- squid3/src/ACLSourceIP.cc 31 Aug 2004 02:14:26 -0000 1.5 +++ squid3/src/ACLSourceIP.cc 11 Mar 2007 09:56:29 -0000 1.5.6.1 @@ -1,5 +1,5 @@ /* - * $Id: ACLSourceIP.cc,v 1.5 2004/08/31 02:14:26 squidadm Exp $ + * $Id: ACLSourceIP.cc,v 1.5.6.1 2007/03/11 09:56:29 amosjeffries Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -46,7 +46,8 @@ int ACLSourceIP::match(ACLChecklist *checklist) { - return ACLIP::match(checklist->src_addr); + /* FIXME : drop temporary conversion */ IPAddress tmp(checklist->src_addr); + return ACLIP::match(tmp); } ACL::Prototype ACLSourceIP::RegistryProtoype(&ACLSourceIP::RegistryEntry_, "src"); Index: squid3/src/Debug.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Debug.h,v retrieving revision 1.7.8.1 retrieving revision 1.7.8.2 diff -u -r1.7.8.1 -r1.7.8.2 --- squid3/src/Debug.h 5 Jan 2007 16:58:40 -0000 1.7.8.1 +++ squid3/src/Debug.h 11 Mar 2007 09:56:29 -0000 1.7.8.2 @@ -1,6 +1,6 @@ /* - * $Id: Debug.h,v 1.7.8.1 2007/01/05 16:58:40 hno Exp $ + * $Id: Debug.h,v 1.7.8.2 2007/03/11 09:56:29 amosjeffries Exp $ * * DEBUG: section 0 Debug Routines * AUTHOR: Harvest Derived @@ -52,6 +52,10 @@ #define assert(EX) ((EX)?((void)0):xassert("EX", __FILE__, __LINE__)) #endif +#ifndef MAX_DEBUG_SECTIONS +#include "defines.h" +#endif + class Debug { Index: squid3/src/IPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/IPAddress.cc,v retrieving revision 1.1.2.8 retrieving revision 1.1.2.9 diff -u -r1.1.2.8 -r1.1.2.9 --- squid3/src/IPAddress.cc 9 Mar 2007 11:46:27 -0000 1.1.2.8 +++ squid3/src/IPAddress.cc 11 Mar 2007 09:56:29 -0000 1.1.2.9 @@ -1,5 +1,5 @@ /* - * $Id: IPAddress.cc,v 1.1.2.8 2007/03/09 11:46:27 amosjeffries Exp $ + * $Id: IPAddress.cc,v 1.1.2.9 2007/03/11 09:56:29 amosjeffries Exp $ */ #include "IPAddress.h" @@ -11,6 +11,7 @@ #include #include "util.h" +#include "Debug.h" /* enum IPAddressType { @@ -110,6 +111,10 @@ memset(&(m_SocketAddr.sin6_addr),0, sizeof(m_SocketAddr.sin6_addr)); m_Type = IPv64; } +void IPAddress::SetEmpty() +{ + memset(&(m_SocketAddr.sin6_addr),0, sizeof(m_SocketAddr.sin6_addr)); +} bool IPAddress::IsNoAddr() const { @@ -226,6 +231,27 @@ return *this; }; +IPAddress::IPAddress(const char*s) +{ + memset(this,0,sizeof(IPAddress)); + operator=(s); +} + +IPAddress& IPAddress::operator =(const char* s) +{ + struct hostent *hp; + +/* FIXME TODO : check that the input is actually an IP Address */ + + if ((hp = gethostbyname(s)) == NULL) { + debugs(28, 0, HERE << "IPAddress: Bad IP: '" << s << "'\n" ); +// FIXME enable this call somehow : self_destruct(); + } + + return operator=(hp->h_addr_list[0]); +} + + IPAddress::IPAddress(struct sockaddr_in const &s) { memset(this,0,sizeof(IPAddress)); /* Index: squid3/src/IPAddress.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/IPAddress.h,v retrieving revision 1.1.2.8 retrieving revision 1.1.2.9 diff -u -r1.1.2.8 -r1.1.2.9 --- squid3/src/IPAddress.h 9 Mar 2007 11:46:28 -0000 1.1.2.8 +++ squid3/src/IPAddress.h 11 Mar 2007 09:56:29 -0000 1.1.2.9 @@ -1,5 +1,5 @@ /* - * $Id: IPAddress.h,v 1.1.2.8 2007/03/09 11:46:28 amosjeffries Exp $ + * $Id: IPAddress.h,v 1.1.2.9 2007/03/11 09:56:29 amosjeffries Exp $ */ #ifndef _INC_IPADDRESS_H #define _INC_IPADDRESS_H @@ -40,6 +40,7 @@ IPAddress(); IPAddress(const IPAddress &); IPAddress(const hostent *); + IPAddress(const char*); IPAddress(const struct in_addr &); IPAddress(const struct sockaddr_in &); #ifdef INET6 @@ -48,9 +49,10 @@ #endif ~IPAddress(); - /* Assignment Operators */ + /** Assignment Operators **/ IPAddress& operator =(const IPAddress &s); IPAddress& operator =(const struct hostent *s); + IPAddress& operator =(const char *s); IPAddress& operator =(struct sockaddr_in const &s); IPAddress& operator =(struct in_addr const &s); #ifdef INET6