--------------------- PatchSet 6048 Date: 2007/10/31 04:51:37 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Code Cleanup Members: include/util.h:1.10.8.17->1.10.8.18 lib/IPAddress.cc:1.1.2.72->1.1.2.73 src/ACLARP.cc:1.9.4.12->1.9.4.13 src/ACLIP.cc:1.8.2.53->1.8.2.54 src/ICMPv4.cc:1.1.2.4->1.1.2.5 src/ICMPv4.h:1.1.2.4->1.1.2.5 Index: squid3/include/util.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/include/util.h,v retrieving revision 1.10.8.17 retrieving revision 1.10.8.18 diff -u -r1.10.8.17 -r1.10.8.18 --- squid3/include/util.h 21 Sep 2007 12:34:14 -0000 1.10.8.17 +++ squid3/include/util.h 31 Oct 2007 04:51:37 -0000 1.10.8.18 @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.10.8.17 2007/09/21 12:34:14 amosjeffries Exp $ + * $Id: util.h,v 1.10.8.18 2007/10/31 04:51:37 amosjeffries Exp $ * * AUTHOR: Harvest Derived * @@ -144,6 +144,13 @@ SQUIDCEXTERN double drand48(void); #endif +#ifndef xmax +#define xmax(a,b) ((a) < (b) ? (b) : (a)) +#endif +#ifndef xmin +#define xmin(a,b) ((a) < (b) ? (a) : (b)) +#endif + typedef struct { size_t count; size_t bytes; Index: squid3/lib/IPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/IPAddress.cc,v retrieving revision 1.1.2.72 retrieving revision 1.1.2.73 diff -u -r1.1.2.72 -r1.1.2.73 --- squid3/lib/IPAddress.cc 30 Sep 2007 18:59:04 -0000 1.1.2.72 +++ squid3/lib/IPAddress.cc 31 Oct 2007 04:51:38 -0000 1.1.2.73 @@ -1,5 +1,5 @@ /* - * $Id: IPAddress.cc,v 1.1.2.72 2007/09/30 18:59:04 serassio Exp $ + * $Id: IPAddress.cc,v 1.1.2.73 2007/10/31 04:51:38 amosjeffries Exp $ * * DEBUG: section 14 IP Storage and Handling * AUTHOR: Amos Jeffries @@ -935,7 +935,7 @@ * NtoA Given a buffer writes a readable ascii version of the IPA and/or port stored * * Buffer must be of a size large enough to hold the converted address. - * This size if provided in the form of a defined variable MAX_IPSTRLEN + * This size is provided in the form of a global defined variable MAX_IPSTRLEN * Should a buffer shorter be provided the string result will be truncated * at the length of the available buffer. * @@ -952,9 +952,9 @@ /* thats okay, our default is known */ if( IsAnyAddr() ) { #if USE_IPV6 - memcpy(buf,"::\0",3); + memcpy(buf,"::\0", xmin(3,blen)); #else - memcpy(buf,"0.0.0.0\0",8); + memcpy(buf,"0.0.0.0\0", xmin(8,blen)); #endif return buf; } @@ -964,9 +964,9 @@ /* Pure-IPv6 CANNOT be displayed in IPv4 format. */ /* However IPv4 CAN. */ if( force == AF_INET && !IsIPv4() ) { - if( IsIPv6() ) - memcpy(buf, "{!IPv4}", 7); - + if( IsIPv6() ) { + memcpy(buf, "{!IPv4}\0", xmin(8,blen)); + } return buf; } @@ -989,7 +989,7 @@ force << "). accepted={" << AF_UNSPEC << "," << AF_INET << "," << AF_INET6 << "}"); fprintf(stderr,"WARNING: Corrupt IP Address details OR required to display in unknown format (%d). accepted={%d,%d,%d} ", force, AF_UNSPEC, AF_INET, AF_INET6); - memcpy(buf,"dead:beef::",12); + memcpy(buf,"dead:beef::\0", xmin(13,blen)); assert(false); } Index: squid3/src/ACLARP.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ACLARP.cc,v retrieving revision 1.9.4.12 retrieving revision 1.9.4.13 diff -u -r1.9.4.12 -r1.9.4.13 --- squid3/src/ACLARP.cc 2 Aug 2007 11:48:32 -0000 1.9.4.12 +++ squid3/src/ACLARP.cc 31 Oct 2007 04:51:38 -0000 1.9.4.13 @@ -1,6 +1,6 @@ /* - * $Id: ACLARP.cc,v 1.9.4.12 2007/08/02 11:48:32 amosjeffries Exp $ + * $Id: ACLARP.cc,v 1.9.4.13 2007/10/31 04:51:38 amosjeffries Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -244,11 +244,11 @@ { char ntoabuf[MAX_IPSTRLEN]; -#if defined(_SQUID_LINUX_) - struct arpreq arpReq; - IPAddress ipAddr; + IPAddress ipAddr = c; + +#if defined(_SQUID_LINUX_) unsigned char ifbuffer[sizeof(struct ifreq) * 64]; @@ -272,7 +272,6 @@ /* * Set up structures for ARP lookup with blank interface name */ - ipAddr = c; memset(&arpReq, '\0', sizeof(arpReq)); ipAddr.GetSockAddr(arpReq.arp_pa); @@ -334,13 +333,10 @@ debugs(28, 4, "Looking up ARP address for " << c << " on " << ifr->ifr_name); /* Set up structures for ARP lookup */ - ipAddr.SetEmpty(); - - ipAddr = c; memset(&arpReq, '\0', sizeof(arpReq)); - arpReq.arp_pa = ipAddr; + ipAddr.GetSockAddr(arpReq.arp_pa); strncpy(arpReq.arp_dev, ifr->ifr_name, sizeof(arpReq.arp_dev) - 1); @@ -397,17 +393,11 @@ #elif defined(_SQUID_SOLARIS_) - struct arpreq arpReq; - - IPAddress ipAddr; - SplayNode **Top = dataptr; /* * Set up structures for ARP lookup with blank interface name */ - - ipAddr = c; memset(&arpReq, '\0', sizeof(arpReq)); @@ -445,10 +435,6 @@ #elif defined(_SQUID_FREEBSD_) || defined(_SQUID_NETBSD_) || defined(_SQUID_OPENBSD_) - struct arpreq arpReq; - - IPAddress ipAddr; - SplayNode **Top = dataptr; int mib[6]; @@ -467,8 +453,6 @@ * Set up structures for ARP lookup with blank interface name */ - ipAddr = c; - memset(&arpReq, '\0', sizeof(arpReq)); ipAddr.GetSockAddr(arpReq.arp_pa); @@ -560,8 +544,6 @@ SplayNode **Top = dataptr; - struct arpreq arpReq; - memset(&arpReq, '\0', sizeof(arpReq)); /* Get size of Windows ARP table */ Index: squid3/src/ACLIP.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ACLIP.cc,v retrieving revision 1.8.2.53 retrieving revision 1.8.2.54 diff -u -r1.8.2.53 -r1.8.2.54 --- squid3/src/ACLIP.cc 6 Oct 2007 04:50:37 -0000 1.8.2.53 +++ squid3/src/ACLIP.cc 31 Oct 2007 04:51:38 -0000 1.8.2.54 @@ -1,5 +1,5 @@ /* - * $Id: ACLIP.cc,v 1.8.2.53 2007/10/06 04:50:37 amosjeffries Exp $ + * $Id: ACLIP.cc,v 1.8.2.54 2007/10/31 04:51:38 amosjeffries Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -84,7 +84,6 @@ char *b3 = NULL; int rlen = 0; - memset(buf, 0, len); addr1.NtoA(b1, len - rlen ); rlen = strlen(buf); b2 = buf + rlen; @@ -226,9 +225,9 @@ acl_ip_data * acl_ip_data::FactoryParse(const char *t) { - LOCAL_ARRAY(char, l_addr1, 256); - LOCAL_ARRAY(char, l_addr2, 256); - LOCAL_ARRAY(char, l_mask, 256); + LOCAL_ARRAY(char, addr1, 256); + LOCAL_ARRAY(char, addr2, 256); + LOCAL_ARRAY(char, mask, 256); acl_ip_data *r = NULL; acl_ip_data **Q = NULL; IPAddress temp; @@ -255,43 +254,43 @@ #endif // IPv4 - if (sscanf(t, SCAN_ACL1_4, l_addr1, l_addr2, l_mask) == 3) { + if (sscanf(t, SCAN_ACL1_4, addr1, addr2, mask) == 3) { iptype=AF_INET; - } else if (sscanf(t, SCAN_ACL2_4,l_addr1, l_addr2, &c) >= 2) { - l_mask[0] = '\0'; + } else if (sscanf(t, SCAN_ACL2_4, addr1, addr2, &c) >= 2) { + mask[0] = '\0'; iptype=AF_INET; - } else if (sscanf(t, SCAN_ACL3_4, l_addr1, l_mask) == 2) { - l_addr2[0] = '\0'; + } else if (sscanf(t, SCAN_ACL3_4, addr1, mask) == 2) { + addr2[0] = '\0'; iptype=AF_INET; - } else if (sscanf(t, SCAN_ACL4_4, l_addr1,&c) == 2) { - l_addr2[0] = '\0'; - l_mask[0] = '\0'; + } else if (sscanf(t, SCAN_ACL4_4, addr1,&c) == 2) { + addr2[0] = '\0'; + mask[0] = '\0'; iptype=AF_INET; // IPv6 - } else if (sscanf(t, SCAN_ACL1_6, l_addr1, l_addr2, l_mask) == 3) { + } else if (sscanf(t, SCAN_ACL1_6, addr1, addr2, mask) == 3) { iptype=AF_INET6; - } else if (sscanf(t, SCAN_ACL2_6, l_addr1, l_addr2, &c) >= 2) { - l_mask[0] = '\0'; + } else if (sscanf(t, SCAN_ACL2_6, addr1, addr2, &c) >= 2) { + mask[0] = '\0'; iptype=AF_INET6; - } else if (sscanf(t, SCAN_ACL3_6, l_addr1, l_mask) == 2) { - l_addr2[0] = '\0'; + } else if (sscanf(t, SCAN_ACL3_6, addr1, mask) == 2) { + addr2[0] = '\0'; iptype=AF_INET6; - } else if (sscanf(t, SCAN_ACL4_6, l_addr1, l_mask) == 2) { - l_addr2[0] = '\0'; + } else if (sscanf(t, SCAN_ACL4_6, addr1, mask) == 2) { + addr2[0] = '\0'; iptype=AF_INET6; // Neither - } else if (sscanf(t, "%[^/]/%s", l_addr1, l_mask) == 2) { - l_addr2[0] = '\0'; - } else if (sscanf(t, "%s", l_addr1) == 1) { + } else if (sscanf(t, "%[^/]/%s", addr1, mask) == 2) { + addr2[0] = '\0'; + } else if (sscanf(t, "%s", addr1) == 1) { /* * Note, must use plain xgetaddrinfo() here because at startup * ipcache hasn't been initialized * TODO: offload this to one of the IPAddress lookups. */ - debugs(28, 5, "aclIpParseIpData: Lookup Host/IP " << l_addr1); + debugs(28, 5, "aclIpParseIpData: Lookup Host/IP " << addr1); struct addrinfo *hp = NULL, *x = NULL; struct addrinfo hints; IPAddress *prev_addr = NULL; @@ -306,9 +305,11 @@ hints.ai_flags |= AI_V4MAPPED | AI_ALL; #endif - int errcode = xgetaddrinfo(l_addr1,NULL,&hints,&hp); + int errcode = xgetaddrinfo(addr1,NULL,&hints,&hp); if (hp == NULL) { - debugs(28, 0, "aclIpParseIpData: Bad host/IP: '" << l_addr1 << "' in '" << t << "', flags=" << hints.ai_flags << " : (" << errcode << ") " << xgai_strerror(errcode) ); + debugs(28, 0, "aclIpParseIpData: Bad host/IP: '" << addr1 << + "' in '" << t << "', flags=" << hints.ai_flags << + " : (" << errcode << ") " << xgai_strerror(errcode) ); self_destruct(); return NULL; } @@ -339,7 +340,7 @@ Q = &r->next; - debugs(28, 3, "" << l_addr1 << " --> " << r->addr1 ); + debugs(28, 3, "" << addr1 << " --> " << r->addr1 ); } if (*Q != NULL) { @@ -362,26 +363,26 @@ #endif /* Decode addr1 */ - if (!*l_addr1) { + if (!*addr1) { debugs(28, 0, "aclIpParseIpData: unknown first address in '" << t << "'"); delete q; self_destruct(); return NULL; } - else q->addr1 = l_addr1; + else q->addr1 = addr1; /* Decode addr2 */ - if (*l_addr2 && !(q->addr2=l_addr2) ) { + if (*addr2 && !(q->addr2=addr2) ) { debugs(28, 0, "aclIpParseIpData: unknown second address in '" << t << "'"); delete q; self_destruct(); return NULL; } - else q->addr2 = l_addr2; + else q->addr2 = addr2; /* Decode mask (NULL or empty means a exact host mask) */ - if (!DecodeMask(l_mask, q->mask, iptype)) { - debugs(28, 0, "aclParseIpData: unknown netmask '" << l_mask << "' in '" << t << "'"); + if (!DecodeMask(mask, q->mask, iptype)) { + debugs(28, 0, "aclParseIpData: unknown netmask '" << mask << "' in '" << t << "'"); delete q; self_destruct(); return NULL; @@ -448,8 +449,7 @@ ClientAddress.addr2.SetEmpty(); ClientAddress.mask.SetEmpty(); - acl_ip_data *ClientAddressPointer = &ClientAddress; - data = data->splay(ClientAddressPointer, aclIpAddrNetworkCompare); + data = data->splay(&ClientAddress, aclIpAddrNetworkCompare); debugs(28, 3, "aclIpMatchIp: '" << clientip << "' " << (splayLastResult ? "NOT found" : "found")); return !splayLastResult; } Index: squid3/src/ICMPv4.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICMPv4.cc,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid3/src/ICMPv4.cc 16 Oct 2007 13:35:08 -0000 1.1.2.4 +++ squid3/src/ICMPv4.cc 31 Oct 2007 04:51:38 -0000 1.1.2.5 @@ -1,5 +1,5 @@ /* - * $Id: ICMPv4.cc,v 1.1.2.4 2007/10/16 13:35:08 amosjeffries Exp $ + * $Id: ICMPv4.cc,v 1.1.2.5 2007/10/31 04:51:38 amosjeffries Exp $ * * DEBUG: section 42 ICMP Pinger program * AUTHOR: Duane Wessels, Amos Jeffries @@ -42,70 +42,6 @@ #include "ICMPv4.h" #include "ICMPPinger.h" -/* Native Windows port doesn't have netinet support, so we emulate it. - At this time, Cygwin lacks icmp support in its include files, so we need - to use the native Windows port definitions. - */ - -#ifdef _SQUID_WIN32_ - -#include "fde.h" - -#ifdef _SQUID_MSWIN_ - -#include -#include - -#endif - -#define ICMP_ECHO 8 -#define ICMP_ECHOREPLY 0 - -typedef struct iphdr -{ - -u_int8_t ip_vhl: - 4; /* Length of the header in dwords */ - -u_int8_t version: - 4; /* Version of IP */ - u_int8_t tos; /* Type of service */ - u_int16_t total_len; /* Length of the packet in dwords */ - u_int16_t ident; /* unique identifier */ - u_int16_t flags; /* Flags */ - u_int8_t ip_ttl; /* Time to live */ - u_int8_t proto; /* Protocol number (TCP, UDP etc) */ - u_int16_t checksum; /* IP checksum */ - u_int32_t source_ip; - u_int32_t dest_ip; -} -iphdr; - -/* ICMP header */ -typedef struct icmphdr -{ - u_int8_t icmp_type; /* ICMP packet type */ - u_int8_t icmp_code; /* Type sub code */ - u_int16_t icmp_cksum; - u_int16_t icmp_id; - u_int16_t icmp_seq; - u_int32_t timestamp; /* not part of ICMP, but we need it */ -} -icmphdr; - -#endif /* _SQUID_MSWIN_ */ - - -#ifndef _SQUID_LINUX_ -#ifndef _SQUID_CYGWIN_ -#ifndef _SQUID_MSWIN_ -#define icmphdr icmp -#define iphdr ip -#endif -#endif -#endif - - const char *icmpPktStr[] = { "Echo Reply", Index: squid3/src/ICMPv4.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICMPv4.h,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid3/src/ICMPv4.h 16 Oct 2007 13:35:08 -0000 1.1.2.4 +++ squid3/src/ICMPv4.h 31 Oct 2007 04:51:38 -0000 1.1.2.5 @@ -1,5 +1,5 @@ /* - * $Id: ICMPv4.h,v 1.1.2.4 2007/10/16 13:35:08 amosjeffries Exp $ + * $Id: ICMPv4.h,v 1.1.2.5 2007/10/31 04:51:38 amosjeffries Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels, Amos Jeffries @@ -137,14 +137,14 @@ #define ICMP_ECHOREPLY 0 #endif -// TODO: which OS needs this ?? -#ifndef _SQUID_LINUX_ -#ifndef _SQUID_CYGWIN_ -#ifndef _SQUID_MSWIN_ +/* some OS apparently define icmp instead of icmphdr */ +#if !defined(icmphdr) && defined(icmp) #define icmphdr icmp -#define iphdr ip -#endif #endif + +/* some OS apparently define ip instead of iphdr */ +#if !defined(iphdr) && defined(ip) +#define iphdr ip #endif /**