--------------------- PatchSet 4566 Date: 2007/05/16 16:04:56 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Rollout IPAddress into a lot of areas. Mainly ICP related. Make IPAddress assert on failure to pull out IPv4 content (for testing). Members: lib/IPAddress.cc:1.1.2.35->1.1.2.36 src/ACLSourceDomain.cc:1.3.12.7->1.3.12.8 src/AccessLogEntry.h:1.3.10.6->1.3.10.7 src/ICP.h:1.6.8.5->1.6.8.6 src/access_log.cc:1.23.4.11->1.23.4.12 src/client_db.cc:1.5.4.9->1.5.4.10 src/client_side.cc:1.68.2.23->1.68.2.24 src/globals.h:1.17.2.7->1.17.2.8 src/icp_v2.cc:1.17.8.14->1.17.8.15 src/icp_v3.cc:1.5.8.6->1.5.8.7 src/neighbors.cc:1.23.4.18->1.23.4.19 src/peer_select.cc:1.9.4.10->1.9.4.11 src/protos.h:1.48.4.18->1.48.4.19 src/structs.h:1.66.2.15->1.66.2.16 Index: squid3/lib/IPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/IPAddress.cc,v retrieving revision 1.1.2.35 retrieving revision 1.1.2.36 diff -u -r1.1.2.35 -r1.1.2.36 --- squid3/lib/IPAddress.cc 10 May 2007 12:57:38 -0000 1.1.2.35 +++ squid3/lib/IPAddress.cc 16 May 2007 16:04:56 -0000 1.1.2.36 @@ -1,6 +1,6 @@ /* - * $Id: IPAddress.cc,v 1.1.2.35 2007/05/10 12:57:38 amosjeffries Exp $ + * $Id: IPAddress.cc,v 1.1.2.36 2007/05/16 16:04:56 amosjeffries Exp $ * * DEBUG: section 14 IP Storage and Handling * AUTHOR: Amos Jeffries @@ -811,7 +811,9 @@ Map6to4( m_SocketAddr.sin6_addr, buf.sin_addr); } else { - memset(&buf, 0, sizeof(struct sockaddr_in)); + debugs(14,1, HERE << "IPAddress::GetSockAddr : Cannot convert non-IPv4 to IPv4."); + memset(&buf,0xFFFFFFFF,sizeof(struct sockadr_in)); + assert(false); } #else memcpy(&buf, &m_SocketAddr, sizeof(struct sockaddr_in)); @@ -916,9 +918,9 @@ case IPv6: // non-compatible IPv6 Pure Address default: - debugs(14,1, HERE << "IPAddress::GetInAddr : Cannot convert non-IP to IPv4."); - + debugs(14,1, HERE << "IPAddress::GetInAddr : Cannot convert non-IPv4 to IPv4."); memset(&buf,0xFFFFFFFF,sizeof(struct in_addr)); + assert(false); return false; } } Index: squid3/src/ACLSourceDomain.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ACLSourceDomain.cc,v retrieving revision 1.3.12.7 retrieving revision 1.3.12.8 diff -u -r1.3.12.7 -r1.3.12.8 --- squid3/src/ACLSourceDomain.cc 30 Apr 2007 13:27:36 -0000 1.3.12.7 +++ squid3/src/ACLSourceDomain.cc 16 May 2007 16:04:56 -0000 1.3.12.8 @@ -1,5 +1,5 @@ /* - * $Id: ACLSourceDomain.cc,v 1.3.12.7 2007/04/30 13:27:36 amosjeffries Exp $ + * $Id: ACLSourceDomain.cc,v 1.3.12.8 2007/05/16 16:04:56 amosjeffries Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -76,7 +76,6 @@ ACLSourceDomainStrategy::match (ACLData * &data, ACLChecklist *checklist) { const char *fqdn = NULL; -// /* FIXME INET6 : drop temp conversion */ struct IN_ADDR tmp; checklist->src_addr.GetInAddr(tmp); fqdn = fqdncache_gethostbyaddr(checklist->src_addr, FQDN_LOOKUP_IF_MISS); if (fqdn) { Index: squid3/src/AccessLogEntry.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/AccessLogEntry.h,v retrieving revision 1.3.10.6 retrieving revision 1.3.10.7 diff -u -r1.3.10.6 -r1.3.10.7 --- squid3/src/AccessLogEntry.h 5 Jan 2007 16:58:23 -0000 1.3.10.6 +++ squid3/src/AccessLogEntry.h 16 May 2007 16:04:56 -0000 1.3.10.7 @@ -1,6 +1,6 @@ /* - * $Id: AccessLogEntry.h,v 1.3.10.6 2007/01/05 16:58:23 hno Exp $ + * $Id: AccessLogEntry.h,v 1.3.10.7 2007/05/16 16:04:56 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -37,6 +37,7 @@ #include "HttpVersion.h" #include "HierarchyLogEntry.h" +#include "IPAddress.h" /* forward decls */ @@ -79,7 +80,8 @@ { public: - CacheDetails() : size(0), + CacheDetails() : caddr(), + size(0), highOffset(0), objectSize(0), code (LOG_TAG_NONE), @@ -91,10 +93,10 @@ ,ssluser(NULL) #endif { - memset(&caddr, '\0', sizeof(caddr)); + ; } - struct IN_ADDR caddr; + IPAddress caddr; size_t size; off_t highOffset; size_t objectSize; Index: squid3/src/ICP.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICP.h,v retrieving revision 1.6.8.5 retrieving revision 1.6.8.6 diff -u -r1.6.8.5 -r1.6.8.6 --- squid3/src/ICP.h 22 Apr 2007 08:04:36 -0000 1.6.8.5 +++ squid3/src/ICP.h 16 May 2007 16:04:57 -0000 1.6.8.6 @@ -1,6 +1,6 @@ /* - * $Id: ICP.h,v 1.6.8.5 2007/04/22 08:04:36 amosjeffries Exp $ + * $Id: ICP.h,v 1.6.8.6 2007/05/16 16:04:57 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -36,11 +36,10 @@ #include "StoreClient.h" -/* This struct is the wire-level header. - * DO NOT add ore move fields on pain of breakage. +/** This struct is the wire-level header. + * DO NOT add more move fields on pain of breakage. * DO NOT add virtual methods. */ - struct _icp_common_t { unsigned char opcode; /* opcode */ @@ -55,7 +54,7 @@ _icp_common_t(); _icp_common_t(char *buf, unsigned int len); - void handleReply(char *buf, struct sockaddr_in *from); + void handleReply(char *buf, IPAddress &from); static _icp_common_t *createMessage(icp_opcode opcode, int flags, const char *url, int reqnum, int pad); icp_opcode getOpCode() const; #endif @@ -83,7 +82,7 @@ HttpRequest *request; int fd; - struct sockaddr_in from; + IPAddress from; char *url; }; @@ -93,8 +92,7 @@ struct _icpUdpData { - - struct sockaddr_in address; + IPAddress address; void *msg; size_t len; icpUdpData *next; @@ -109,23 +107,21 @@ }; -HttpRequest * - -icpGetRequest(char *url, int reqnum, int fd, struct sockaddr_in *from); +HttpRequest* icpGetRequest(char *url, int reqnum, int fd, IPAddress &from); -int icpAccessAllowed(struct sockaddr_in *from, HttpRequest * icp_request); +int icpAccessAllowed(IPAddress &from, HttpRequest * icp_request); -SQUIDCEXTERN void icpCreateAndSend(icp_opcode, int flags, char const *url, int reqnum, int pad, int fd, const struct sockaddr_in *from); +SQUIDCEXTERN void icpCreateAndSend(icp_opcode, int flags, char const *url, int reqnum, int pad, int fd, const IPAddress &from); extern icp_opcode icpGetCommonOpcode(); -SQUIDCEXTERN int icpUdpSend(int, const struct sockaddr_in *, icp_common_t *, log_type, int); +SQUIDCEXTERN int icpUdpSend(int, const IPAddress &, icp_common_t *, log_type, int); SQUIDCEXTERN log_type icpLogFromICPCode(icp_opcode opcode); -void icpDenyAccess(struct sockaddr_in *from, char *url, int reqnum, int fd); +void icpDenyAccess(IPAddress &from, char *url, int reqnum, int fd); SQUIDCEXTERN PF icpHandleUdp; SQUIDCEXTERN PF icpUdpSendQueue; -SQUIDCEXTERN void icpHandleIcpV3(int, struct sockaddr_in, char *, int); +SQUIDCEXTERN void icpHandleIcpV3(int, IPAddress &, char *, int); SQUIDCEXTERN int icpCheckUdpHit(StoreEntry *, HttpRequest * request); SQUIDCEXTERN void icpConnectionsOpen(void); SQUIDCEXTERN void icpConnectionShutdown(void); Index: squid3/src/access_log.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/access_log.cc,v retrieving revision 1.23.4.11 retrieving revision 1.23.4.12 diff -u -r1.23.4.11 -r1.23.4.12 --- squid3/src/access_log.cc 30 Apr 2007 13:27:36 -0000 1.23.4.11 +++ squid3/src/access_log.cc 16 May 2007 16:04:57 -0000 1.23.4.12 @@ -1,6 +1,6 @@ /* - * $Id: access_log.cc,v 1.23.4.11 2007/04/30 13:27:36 amosjeffries Exp $ + * $Id: access_log.cc,v 1.23.4.12 2007/05/16 16:04:57 amosjeffries Exp $ * * DEBUG: section 46 Access Log * AUTHOR: Duane Wessels @@ -541,16 +541,18 @@ break; case LFT_CLIENT_IP_ADDRESS: - out = inet_ntoa(al->cache.caddr); + if (!out) { + al->cache.caddr.NtoA(tmp,MAX_IPSTRLEN); + out = tmp; + } break; case LFT_CLIENT_FQDN: -{ -/* FIXME INET6 : drop temp conversion */ IPAddress tmp(al->cache.caddr); - out = fqdncache_gethostbyaddr(tmp, FQDN_LOOKUP_IF_MISS); -} - if (!out) - out = inet_ntoa(al->cache.caddr); + out = fqdncache_gethostbyaddr(al->cache.caddr, FQDN_LOOKUP_IF_MISS); + if (!out) { + al->cache.caddr.NtoA(tmp,MAX_IPSTRLEN); + out = tmp; + } break; @@ -1256,14 +1258,15 @@ { const char *client = NULL; const char *user = NULL; + char buf[MAX_IPSTRLEN]; if (Config.onoff.log_fqdn) { -/* FIXME INET6 : drop temp conversion */ IPAddress tmp_addr(al->cache.caddr); - client = fqdncache_gethostbyaddr(tmp_addr, FQDN_LOOKUP_IF_MISS); + client = fqdncache_gethostbyaddr(al->cache.caddr, FQDN_LOOKUP_IF_MISS); } if (client == NULL) { - client = inet_ntoa(al->cache.caddr); + al->cache.caddr.NtoA(buf,MAX_IPSTRLEN); + client = buf; } user = accessLogFormatName(al->cache.authuser); @@ -1332,14 +1335,15 @@ { const char *client = NULL; char *user1 = NULL, *user2 = NULL; + char buf[MAX_IPSTRLEN]; if (Config.onoff.log_fqdn) { -/* FIXME INET6 : drop temp conversion */ IPAddress tmp_addr(al->cache.caddr); - client = fqdncache_gethostbyaddr(tmp_addr, 0); + client = fqdncache_gethostbyaddr(al->cache.caddr, 0); } if (client == NULL) { - client = inet_ntoa(al->cache.caddr); + al->cache.caddr.NtoA(buf,MAX_IPSTRLEN); + client = buf; } user1 = accessLogFormatName(al->cache.authuser); Index: squid3/src/client_db.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/client_db.cc,v retrieving revision 1.5.4.9 retrieving revision 1.5.4.10 diff -u -r1.5.4.9 -r1.5.4.10 --- squid3/src/client_db.cc 30 Apr 2007 13:27:36 -0000 1.5.4.9 +++ squid3/src/client_db.cc 16 May 2007 16:04:57 -0000 1.5.4.10 @@ -1,6 +1,6 @@ /* - * $Id: client_db.cc,v 1.5.4.9 2007/04/30 13:27:36 amosjeffries Exp $ + * $Id: client_db.cc,v 1.5.4.10 2007/05/16 16:04:57 amosjeffries Exp $ * * DEBUG: section 0 Client Database * AUTHOR: Duane Wessels @@ -42,7 +42,7 @@ static hash_table *client_table = NULL; -static ClientInfo *clientdbAdd(struct IN_ADDR addr); +static ClientInfo *clientdbAdd(const IPAddress &addr); static FREE clientdbFreeItem; static void clientdbStartGC(void); static void clientdbScheduledGC(void *); @@ -56,12 +56,14 @@ static ClientInfo * -clientdbAdd(struct IN_ADDR addr) +clientdbAdd(const IPAddress &addr) { ClientInfo *c; + char *buf = new char[MAX_IPSTRLEN]; c = (ClientInfo *)memAllocate(MEM_CLIENT_INFO); - c->hash.key = xstrdup(inet_ntoa(addr)); - c->addr = addr; + c->hash.key = addr.NtoA(buf,MAX_IPSTRLEN); +// FIXME INET6 : drop temp conversion should be: c->addr = addr; + addr.GetInAddr(c->addr); hash_join(client_table, &c->hash); statCounter.client_http.clients++; @@ -94,15 +96,15 @@ void -clientdbUpdate(struct IN_ADDR addr, log_type ltype, protocol_t p, size_t size) +clientdbUpdate(const IPAddress &addr, log_type ltype, protocol_t p, size_t size) { - char *key; + char key[MAX_IPSTRLEN]; ClientInfo *c; if (!Config.onoff.client_db) return; - key = inet_ntoa(addr); + addr.NtoA(key,MAX_IPSTRLEN); c = (ClientInfo *) hash_lookup(client_table, key); @@ -133,7 +135,7 @@ c->last_seen = squid_curtime; } -/* +/** * clientdbEstablished() * This function tracks the number of currently established connections * for a client IP address. When a connection is accepted, call this @@ -141,7 +143,7 @@ * -1. To get the current value, simply call with delta = 0. */ int -clientdbEstablished(IPAddress &addr, int delta) +clientdbEstablished(const IPAddress &addr, int delta) { char key[MAX_IPSTRLEN]; ClientInfo *c; @@ -153,10 +155,8 @@ c = (ClientInfo *) hash_lookup(client_table, key); - if (c == NULL) - { - /* FIXME INET6 : drop temporary conversion */ struct IN_ADDR tmp; addr.GetInAddr(tmp); - c = clientdbAdd(tmp); + if (c == NULL) { + c = clientdbAdd(addr); } if (c == NULL) @@ -170,9 +170,9 @@ #define CUTOFF_SECONDS 3600 int -clientdbCutoffDenied(struct IN_ADDR addr) +clientdbCutoffDenied(const IPAddress &addr) { - char *key; + char key[MAX_IPSTRLEN]; int NR; int ND; double p; @@ -181,7 +181,7 @@ if (!Config.onoff.client_db) return 0; - key = inet_ntoa(addr); + addr.NtoA(key,MAX_IPSTRLEN); c = (ClientInfo *) hash_lookup(client_table, key); @@ -249,7 +249,7 @@ while ((c = (ClientInfo *) hash_next(client_table))) { storeAppendPrintf(sentry, "Address: %s\n", hashKeyStr(&c->hash)); -/* FIXME INET6 : dropp temp conversion*/ IPAddress tmpipa(c->addr); +/* FIXME INET6 : drop temp conversion*/ IPAddress tmpipa(c->addr); storeAppendPrintf(sentry, "Name: %s\n", fqdnFromAddr(tmpipa)); storeAppendPrintf(sentry, "Currently established connections: %d\n", c->n_established); Index: squid3/src/client_side.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/client_side.cc,v retrieving revision 1.68.2.23 retrieving revision 1.68.2.24 diff -u -r1.68.2.23 -r1.68.2.24 --- squid3/src/client_side.cc 15 May 2007 22:56:56 -0000 1.68.2.23 +++ squid3/src/client_side.cc 16 May 2007 16:04:57 -0000 1.68.2.24 @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.68.2.23 2007/05/15 22:56:56 amosjeffries Exp $ + * $Id: client_side.cc,v 1.68.2.24 2007/05/16 16:04:57 amosjeffries Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -526,7 +526,10 @@ updateCounters(); if (getConn() != NULL) - clientdbUpdate(getConn()->peer.sin_addr, logType, PROTO_HTTP, out.size); +{ +/* FIXME INET6 : drop temp conversion */ IPAddress tmp(getConn()->peer); + clientdbUpdate(tmp, logType, PROTO_HTTP, out.size); +} } delete checklist; Index: squid3/src/globals.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/globals.h,v retrieving revision 1.17.2.7 retrieving revision 1.17.2.8 diff -u -r1.17.2.7 -r1.17.2.8 --- squid3/src/globals.h 22 Apr 2007 08:06:14 -0000 1.17.2.7 +++ squid3/src/globals.h 16 May 2007 16:04:57 -0000 1.17.2.8 @@ -1,6 +1,6 @@ /* - * $Id: globals.h,v 1.17.2.7 2007/04/22 08:06:14 amosjeffries Exp $ + * $Id: globals.h,v 1.17.2.8 2007/05/16 16:04:57 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -118,7 +118,7 @@ extern struct IN_ADDR no_addr; - extern struct IN_ADDR theOutICPAddr; + extern IPAddress theOutICPAddr; extern struct IN_ADDR theOutSNMPAddr; Index: squid3/src/icp_v2.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/icp_v2.cc,v retrieving revision 1.17.8.14 retrieving revision 1.17.8.15 diff -u -r1.17.8.14 -r1.17.8.15 --- squid3/src/icp_v2.cc 10 May 2007 12:57:45 -0000 1.17.8.14 +++ squid3/src/icp_v2.cc 16 May 2007 16:04:57 -0000 1.17.8.15 @@ -1,6 +1,6 @@ /* - * $Id: icp_v2.cc,v 1.17.8.14 2007/05/10 12:57:45 amosjeffries Exp $ + * $Id: icp_v2.cc,v 1.17.8.15 2007/05/16 16:04:57 amosjeffries Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -45,9 +45,9 @@ #include "SquidTime.h" #include "SwapDir.h" -static void icpLogIcp(struct IN_ADDR, log_type, int, const char *, int); +static void icpLogIcp(const IPAddress &, log_type, int, const char *, int); -static void icpHandleIcpV2(int, struct sockaddr_in, char *, int); +static void icpHandleIcpV2(int, IPAddress &, char *, int); static void icpCount(void *, int, size_t, int); /* @@ -150,7 +150,7 @@ codeToSend = ICP_MISS; } - icpCreateAndSend(codeToSend, flags, url, header.reqnum, src_rtt, fd, &from); + icpCreateAndSend(codeToSend, flags, url, header.reqnum, src_rtt, fd, from); delete this; } @@ -158,7 +158,7 @@ static void -icpLogIcp(struct IN_ADDR caddr, log_type logcode, int len, const char *url, int delay) +icpLogIcp(const IPAddress &caddr, log_type logcode, int len, const char *url, int delay) { AccessLogEntry al; @@ -198,7 +198,8 @@ while ((q = IcpQueueHead) != NULL) { delay = tvSubUsec(q->queue_time, current_time); /* increment delay to prevent looping */ - x = icpUdpSend(fd, &q->address, (icp_common_t *) q->msg, q->logcode, ++delay); +/* FIXME INET6 : drop temp conversion */ IPAddress tmp(q->address); + x = icpUdpSend(fd, tmp, (icp_common_t *) q->msg, q->logcode, ++delay); IcpQueueHead = q->next; safe_free(q); @@ -240,7 +241,7 @@ headerp->pad = htonl(pad); - headerp->shostid = theOutICPAddr.s_addr; + theOutICPAddr.GetInAddr( *((struct in_addr*)&headerp->shostid) ); urloffset = buf + sizeof(icp_common_t); @@ -254,8 +255,7 @@ int icpUdpSend(int fd, - - const struct sockaddr_in *to, + const IPAddress &to, icp_common_t * msg, log_type logcode, int delay) @@ -264,23 +264,22 @@ int x; int len; len = (int) ntohs(msg->length); -/* FIXME INET6 : drop temp conversion boundary */ IPAddress tmp(*to); debugs(12, 5, "icpUdpSend: FD " << fd << " sending " << - icp_opcode_str[msg->opcode] << ", " << len << " bytes to " << tmp); + icp_opcode_str[msg->opcode] << ", " << len << " bytes to " << to); - x = comm_udp_sendto(fd, tmp, msg, len); + x = comm_udp_sendto(fd, to, msg, len); if (x >= 0) { /* successfully written */ - icpLogIcp(to->sin_addr, logcode, len, (char *) (msg + 1), delay); + icpLogIcp(to, logcode, len, (char *) (msg + 1), delay); icpCount(msg, SENT, (size_t) len, delay); safe_free(msg); } else if (0 == delay) { /* send failed, but queue it */ queue = (icpUdpData *) xcalloc(1, sizeof(icpUdpData)); - queue->address = *to; + queue->address = to; queue->msg = msg; queue->len = (int) ntohs(msg->length); queue->queue_time = current_time; @@ -368,7 +367,7 @@ void -icpCreateAndSend(icp_opcode opcode, int flags, char const *url, int reqnum, int pad, int fd, const struct sockaddr_in *from) +icpCreateAndSend(icp_opcode opcode, int flags, char const *url, int reqnum, int pad, int fd, const IPAddress &from) { icp_common_t *reply = _icp_common_t::createMessage(opcode, flags, url, reqnum, pad); icpUdpSend(fd, from, reply, icpLogFromICPCode(opcode), 0); @@ -376,17 +375,17 @@ void -icpDenyAccess(struct sockaddr_in *from, char *url, int reqnum, int fd) +icpDenyAccess(IPAddress &from, char *url, int reqnum, int fd) { - debugs(12, 2, "icpDenyAccess: Access Denied for " << inet_ntoa(from->sin_addr) << " by " << AclMatchedName << "."); + debugs(12, 2, "icpDenyAccess: Access Denied for " << from << " by " << AclMatchedName << "."); - if (clientdbCutoffDenied(from->sin_addr)) + if (clientdbCutoffDenied(from)) { /* * count this DENIED query in the clientdb, even though * we're not sending an ICP reply... */ - clientdbUpdate(from->sin_addr, LOG_UDP_DENIED, PROTO_ICP, 0); + clientdbUpdate(from, LOG_UDP_DENIED, PROTO_ICP, 0); } else { icpCreateAndSend(ICP_DENIED, 0, url, reqnum, 0, fd, from); @@ -395,11 +394,11 @@ int -icpAccessAllowed(struct sockaddr_in *from, HttpRequest * icp_request) +icpAccessAllowed(IPAddress &from, HttpRequest * icp_request) { ACLChecklist checklist; - checklist.src_addr = from->sin_addr; - checklist.my_addr = no_addr; + checklist.src_addr = from; + checklist.my_addr.SetNoAddr(); checklist.request = HTTPMSGLOCK(icp_request); checklist.accessList = cbdataReference(Config.accessList.icp); /* cbdataReferenceDone() happens in either fastCheck() or ~ACLCheckList */ @@ -418,7 +417,7 @@ HttpRequest * -icpGetRequest(char *url, int reqnum, int fd, struct sockaddr_in * from) +icpGetRequest(char *url, int reqnum, int fd, IPAddress &from) { if (strpbrk(url, w_space)) { @@ -438,23 +437,23 @@ static void -doV2Query(int fd, struct sockaddr_in from, char *buf, icp_common_t header) +doV2Query(int fd, IPAddress &from, char *buf, icp_common_t header) { int rtt = 0; int src_rtt = 0; u_int32_t flags = 0; /* We have a valid packet */ char *url = buf + sizeof(icp_common_t) + sizeof(u_int32_t); - HttpRequest *icp_request = icpGetRequest(url, header.reqnum, fd, &from); + HttpRequest *icp_request = icpGetRequest(url, header.reqnum, fd, from); if (!icp_request) return; HTTPMSGLOCK(icp_request); - if (!icpAccessAllowed(&from, icp_request)) + if (!icpAccessAllowed(from, icp_request)) { - icpDenyAccess(&from, url, header.reqnum, fd); + icpDenyAccess(from, url, header.reqnum, fd); HTTPMSGUNLOCK(icp_request); return; } @@ -491,17 +490,17 @@ void -_icp_common_t::handleReply(char *buf, struct sockaddr_in *from) +_icp_common_t::handleReply(char *buf, IPAddress &from) { if (neighbors_do_private_keys && reqnum == 0) { - debugs(12, 0, "icpHandleIcpV2: Neighbor " << inet_ntoa(from->sin_addr) << " returned reqnum = 0"); + debugs(12, 0, "icpHandleIcpV2: Neighbor " << from << " returned reqnum = 0"); debugs(12, 0, "icpHandleIcpV2: Disabling use of private keys"); neighbors_do_private_keys = 0; } char *url = buf + sizeof(icp_common_t); - debugs(12, 3, "icpHandleIcpV2: " << icp_opcode_str[opcode] << " from " << inet_ntoa(from->sin_addr) << " for '" << url << "'"); + debugs(12, 3, "icpHandleIcpV2: " << icp_opcode_str[opcode] << " from " << from << " for '" << url << "'"); const cache_key *key = icpGetCacheKey(url, (int) reqnum); /* call neighborsUdpAck even if ping_status != PING_WAITING */ @@ -510,7 +509,7 @@ static void -icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len) +icpHandleIcpV2(int fd, IPAddress &from, char *buf, int len) { if (len <= 0) { @@ -550,7 +549,7 @@ case ICP_DENIED: case ICP_MISS_NOFETCH: - header.handleReply(buf, &from); + header.handleReply(buf, from); break; case ICP_INVALID: @@ -559,7 +558,7 @@ break; default: - debugs(12, 0, "icpHandleIcpV2: UNKNOWN OPCODE: " << header.opcode << " from " << inet_ntoa(from.sin_addr)); + debugs(12, 0, "icpHandleIcpV2: UNKNOWN OPCODE: " << header.opcode << " from " << from); break; } @@ -570,7 +569,7 @@ icpPktDump(icp_common_t * pkt) { - struct IN_ADDR a; + struct in_addr a; debugs(12, 9, "opcode: " << std::setw(3) << pkt->opcode << " " << icp_opcode_str[pkt->opcode]); debugs(12, 9, "version: "<< std::left << std::setw(8) << pkt->version); @@ -641,11 +640,10 @@ icp_version = (int) buf[1]; /* cheat! */ -/* FIXME INET6 : drop temp conversion boundary */ struct sockaddr_in from_tmp; from.GetSockAddr(from_tmp); if (icp_version == ICP_VERSION_2) - icpHandleIcpV2(sock, from_tmp, buf, len); + icpHandleIcpV2(sock, from, buf, len); else if (icp_version == ICP_VERSION_3) - icpHandleIcpV3(sock, from_tmp, buf, len); + icpHandleIcpV3(sock, from, buf, len); else debugs(12, 1, "WARNING: Unused ICP version " << icp_version << " received from " << from); @@ -721,18 +719,18 @@ theOutIcpConnection = theInIcpConnection; } - memset(&theOutICPAddr, '\0', sizeof(struct IN_ADDR)); + theOutICPAddr.SetEmpty(); +/* FIXME INET6 : discover whether ICP can use IPv6 here or not. */ len = sizeof(struct sockaddr_in); memset(&xaddr, '\0', len); x = getsockname(theOutIcpConnection, - (struct sockaddr *) &xaddr, &len); if (x < 0) debugs(50, 1, "theOutIcpConnection FD " << theOutIcpConnection << ": getsockname: " << xstrerror()); else - theOutICPAddr = xaddr.sin_addr; + theOutICPAddr = xaddr; } /* Index: squid3/src/icp_v3.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/icp_v3.cc,v retrieving revision 1.5.8.6 retrieving revision 1.5.8.7 diff -u -r1.5.8.6 -r1.5.8.7 --- squid3/src/icp_v3.cc 29 Apr 2007 03:01:38 -0000 1.5.8.6 +++ squid3/src/icp_v3.cc 16 May 2007 16:04:57 -0000 1.5.8.7 @@ -1,6 +1,6 @@ /* - * $Id: icp_v3.cc,v 1.5.8.6 2007/04/29 03:01:38 amosjeffries Exp $ + * $Id: icp_v3.cc,v 1.5.8.7 2007/05/16 16:04:57 amosjeffries Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -52,18 +52,18 @@ static void -doV3Query(int fd, struct sockaddr_in from, char *buf, icp_common_t header) +doV3Query(int fd, IPAddress &from, char *buf, icp_common_t header) { /* We have a valid packet */ char *url = buf + sizeof(icp_common_t) + sizeof(u_int32_t); - HttpRequest *icp_request = icpGetRequest (url, header.reqnum, fd, &from); + HttpRequest *icp_request = icpGetRequest (url, header.reqnum, fd, from); if (!icp_request) return; - if (!icpAccessAllowed(&from, icp_request)) + if (!icpAccessAllowed(from, icp_request)) { - icpDenyAccess (&from, url, header.reqnum, fd); + icpDenyAccess (from, url, header.reqnum, fd); delete icp_request; return; } @@ -97,7 +97,7 @@ else codeToSend = icpGetCommonOpcode(); - icpCreateAndSend (codeToSend, 0, url, header.reqnum, 0, fd, &from); + icpCreateAndSend (codeToSend, 0, url, header.reqnum, 0, fd, from); delete this; } @@ -105,7 +105,7 @@ /* Currently Harvest cached-2.x uses ICP_VERSION_3 */ void -icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len) +icpHandleIcpV3(int fd, IPAddress&from, char *buf, int len) { if (len <= 0) { @@ -128,7 +128,7 @@ { case ICP_QUERY: - doV3Query(fd, from,buf, header); + doV3Query(fd, from, buf, header); break; case ICP_HIT: @@ -144,7 +144,7 @@ case ICP_DENIED: case ICP_MISS_NOFETCH: - header.handleReply(buf, &from); + header.handleReply(buf, from); break; case ICP_INVALID: @@ -153,7 +153,7 @@ break; default: - debugs(12, 0, "icpHandleIcpV3: UNKNOWN OPCODE: " << header.opcode << " from " << inet_ntoa(from.sin_addr)); + debugs(12, 0, "icpHandleIcpV3: UNKNOWN OPCODE: " << header.opcode << " from " << from); break; } } Index: squid3/src/neighbors.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/neighbors.cc,v retrieving revision 1.23.4.18 retrieving revision 1.23.4.19 diff -u -r1.23.4.18 -r1.23.4.19 --- squid3/src/neighbors.cc 10 May 2007 12:57:46 -0000 1.23.4.18 +++ squid3/src/neighbors.cc 16 May 2007 16:04:57 -0000 1.23.4.19 @@ -1,6 +1,6 @@ /* - * $Id: neighbors.cc,v 1.23.4.18 2007/05/10 12:57:46 amosjeffries Exp $ + * $Id: neighbors.cc,v 1.23.4.19 2007/05/16 16:04:57 amosjeffries Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -45,6 +45,7 @@ #include "PeerSelectState.h" #include "SquidTime.h" #include "Store.h" +#include "IPAddress.h" /* count mcast group peers every 15 minutes */ #define MCAST_COUNT_RATE 900 @@ -66,7 +67,7 @@ static void peerCountMcastPeersSchedule(peer * p, time_t when); static IRCB peerCountHandleIcpReply; -static void neighborIgnoreNonPeer(const struct sockaddr_in *, icp_opcode); +static void neighborIgnoreNonPeer(const IPAddress &, icp_opcode); static OBJH neighborDumpPeers; static OBJH neighborDumpNonPeers; static void dump_peers(StoreEntry * sentry, peer * peers); @@ -94,20 +95,17 @@ peer * - -whichPeer(const struct sockaddr_in * from) +whichPeer(const IPAddress &from) { int j; - u_short port = ntohs(from->sin_port); - struct IN_ADDR ip = from->sin_addr; peer *p = NULL; - debugs(15, 3, "whichPeer: from " << inet_ntoa(ip) << " port " << port); + debugs(15, 3, "whichPeer: from " << from); for (p = Config.peers; p; p = p->next) { for (j = 0; j < p->n_addresses; j++) { - if (ip.s_addr == p->addresses[j].s_addr && port == p->icp.port) { + if (from == p->addresses[j] && from.GetPort() == p->icp.port) { return p; } } @@ -640,7 +638,7 @@ echo_hdr.reqnum = reqnum; query = _icp_common_t::createMessage(ICP_DECHO, 0, url, reqnum, 0); icpUdpSend(theOutIcpConnection, - &p->in_addr, + p->in_addr, query, LOG_ICP_QUERY, 0); @@ -654,7 +652,7 @@ query = _icp_common_t::createMessage(ICP_QUERY, flags, url, reqnum, 0); icpUdpSend(theOutIcpConnection, - &p->in_addr, + p->in_addr, query, LOG_ICP_QUERY, 0); @@ -967,17 +965,16 @@ static peer *non_peers = NULL; static void - -neighborIgnoreNonPeer(const struct sockaddr_in *from, icp_opcode opcode) +neighborIgnoreNonPeer(const IPAddress &from, icp_opcode opcode) { peer *np; for (np = non_peers; np; np = np->next) { - if (np->in_addr.sin_addr.s_addr != from->sin_addr.s_addr) + if (np->in_addr != from) continue; - if (np->in_addr.sin_port != from->sin_port) + if (np->in_addr.GetPort() != from.GetPort()) continue; break; @@ -986,11 +983,11 @@ if (np == NULL) { np = (peer *)xcalloc(1, sizeof(peer)); - np->in_addr.sin_addr = from->sin_addr; - np->in_addr.sin_port = from->sin_port; - np->icp.port = ntohl(from->sin_port); + np->in_addr = from; + np->icp.port = from.GetPort(); np->type = PEER_NONE; - np->host = xstrdup(inet_ntoa(from->sin_addr)); + np->host = new char[MAX_IPSTRLEN]; + from.NtoA(np->host,MAX_IPSTRLEN); np->next = non_peers; non_peers = np; } @@ -1030,7 +1027,7 @@ */ void -neighborsUdpAck(const cache_key * key, icp_common_t * header, const struct sockaddr_in *from) +neighborsUdpAck(const cache_key * key, icp_common_t * header, const IPAddress &from) { peer *p = NULL; StoreEntry *entry; @@ -1139,7 +1136,7 @@ #endif } else { - debugs(15, 1, "Unsolicited SECHO from " << inet_ntoa(from->sin_addr)); + debugs(15, 1, "Unsolicited SECHO from " << from); } } else if (opcode == ICP_DENIED) { @@ -1260,7 +1257,6 @@ { peer *p = (peer *)data; - struct sockaddr_in *ap; int j; if (p->n_addresses == 0) { @@ -1286,16 +1282,13 @@ for (j = 0; j < (int) ia->count && j < PEER_MAX_ADDRESSES; j++) { p->addresses[j] = ia->in_addrs[j]; - debugs(15, 2, "--> IP address #" << j << ": " << inet_ntoa(p->addresses[j])); + debugs(15, 2, "--> IP address #" << j << ": " << p->addresses[j]); p->n_addresses++; } - ap = &p->in_addr; - - memset(ap, '\0', sizeof(struct sockaddr_in)); - ap->sin_family = AF_INET; - ap->sin_addr = p->addresses[0]; - ap->sin_port = htons(p->icp.port); + p->in_addr.SetEmpty(); + p->in_addr = p->addresses[0]; + p->in_addr.SetPort(p->icp.port); if (p->type == PEER_MULTICAST) peerCountMcastPeersSchedule(p, 10); @@ -1456,7 +1449,9 @@ LOCAL_ARRAY(char, url, MAX_URL); assert(p->type == PEER_MULTICAST); p->mcast.flags.count_event_pending = 0; - snprintf(url, MAX_URL, "http://%s/", inet_ntoa(p->in_addr.sin_addr)); + snprintf(url, MAX_URL, "http://"); + p->in_addr.ToURL(url+7, MAX_URL -8 ); + strcat(url, "/"); fake = storeCreateEntry(url, url, request_flags(), METHOD_GET); HttpRequest *req = HttpRequest::CreateFromUrl(url); psstate = new ps_state; @@ -1475,7 +1470,7 @@ reqnum = icpSetCacheKey((const cache_key *)fake->key); query = _icp_common_t::createMessage(ICP_QUERY, 0, url, reqnum, 0); icpUdpSend(theOutIcpConnection, - &p->in_addr, + p->in_addr, query, LOG_ICP_QUERY, 0); @@ -1635,7 +1630,7 @@ dump_peers(StoreEntry * sentry, peer * peers) { peer *e = NULL; - + char ntoabuf[MAX_IPSTRLEN]; struct _domain_ping *d = NULL; icp_opcode op; int i; @@ -1657,7 +1652,7 @@ for (i = 0; i < e->n_addresses; i++) { storeAppendPrintf(sentry, "Address[%d] : %s\n", i, - inet_ntoa(e->addresses[i])); + e->addresses[i].NtoA(ntoabuf,MAX_IPSTRLEN) ); } storeAppendPrintf(sentry, "Status : %s\n", @@ -1756,8 +1751,7 @@ if (NULL != e) mem = e->mem_obj; -/* FIXME INET6 : drop temp conversion */ struct sockaddr_in tmp_from; from.GetSockAddr(tmp_from); - if ((p = whichPeer(&tmp_from))) + if ((p = whichPeer(from))) neighborAliveHtcp(p, mem, htcp); /* Does the entry exist? */ Index: squid3/src/peer_select.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/peer_select.cc,v retrieving revision 1.9.4.10 retrieving revision 1.9.4.11 diff -u -r1.9.4.10 -r1.9.4.11 --- squid3/src/peer_select.cc 10 May 2007 12:57:46 -0000 1.9.4.10 +++ squid3/src/peer_select.cc 16 May 2007 16:04:58 -0000 1.9.4.11 @@ -1,6 +1,6 @@ /* - * $Id: peer_select.cc,v 1.9.4.10 2007/05/10 12:57:46 amosjeffries Exp $ + * $Id: peer_select.cc,v 1.9.4.11 2007/05/16 16:04:58 amosjeffries Exp $ * * DEBUG: section 44 Peer Selection Algorithm * AUTHOR: Duane Wessels @@ -272,7 +272,8 @@ if (myhops && myhops <= Config.minDirectHops) return 1; - p = whichPeer(&psstate->closest_parent_miss); +/* FIXME INET6 : drop temp conversion */ IPAddress tmp(psstate->closest_parent_miss); + p = whichPeer(tmp); if (p == NULL) return 0; @@ -467,10 +468,12 @@ } else #endif if (ps->closest_parent_miss.sin_addr.s_addr != any_addr.s_addr) { - p = whichPeer(&ps->closest_parent_miss); +/* FIXME INET6 : drop temp conversion */ IPAddress tmp(ps->closest_parent_miss); + p = whichPeer(tmp); code = CLOSEST_PARENT_MISS; } else if (ps->first_parent_miss.sin_addr.s_addr != any_addr.s_addr) { - p = whichPeer(&ps->first_parent_miss); +/* FIXME INET6 : drop temp conversion */ IPAddress tmp(ps->first_parent_miss); + p = whichPeer(tmp); code = FIRST_PARENT_MISS; } if (p && code != HIER_NONE) { @@ -613,7 +616,8 @@ netdbUpdatePeer(ps->request, p, rtt, hops); if (rtt && (ps->ping.p_rtt == 0 || rtt < ps->ping.p_rtt)) { - ps->closest_parent_miss = p->in_addr; +// FIXME INET6: drop temp conversion: should be: ps->closest_parent_miss = p->in_addr; + p->in_addr.GetSockAddr(ps->closest_parent_miss); ps->ping.p_rtt = rtt; } } @@ -634,7 +638,8 @@ if (ps->first_parent_miss.sin_addr.s_addr == any_addr.s_addr || rtt < ps->ping.w_rtt) { - ps->first_parent_miss = p->in_addr; +// FIXME INET6: drop temp conversion: should be: ps->first_parent_miss = p->in_addr; + p->in_addr.GetSockAddr(ps->first_parent_miss); ps->ping.w_rtt = rtt; } } @@ -719,7 +724,8 @@ netdbUpdatePeer(ps->request, p, rtt, hops); if (rtt && (ps->ping.p_rtt == 0 || rtt < ps->ping.p_rtt)) { - ps->closest_parent_miss = p->in_addr; +// FIXME INET6: drop temp conversion: should be: ps->closest_parent_miss = p->in_addr; + p->in_addr.GetSockAddr(ps->closest_parent_miss); ps->ping.p_rtt = rtt; } } @@ -740,7 +746,8 @@ if (ps->first_parent_miss.sin_addr.s_addr == any_addr.s_addr || rtt < ps->ping.w_rtt) { - ps->first_parent_miss = p->in_addr; +// FIXME INET6: drop temp conversion: should be: ps->first_parent_miss = p->in_addr; + p->in_addr.GetSockAddr(ps->first_parent_miss); ps->ping.w_rtt = rtt; } } Index: squid3/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/protos.h,v retrieving revision 1.48.4.18 retrieving revision 1.48.4.19 diff -u -r1.48.4.18 -r1.48.4.19 --- squid3/src/protos.h 15 May 2007 13:42:42 -0000 1.48.4.18 +++ squid3/src/protos.h 16 May 2007 16:04:58 -0000 1.48.4.19 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.48.4.18 2007/05/15 13:42:42 amosjeffries Exp $ + * $Id: protos.h,v 1.48.4.19 2007/05/16 16:04:58 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -85,13 +85,13 @@ SQUIDCEXTERN void clientdbInit(void); extern void clientdbRegisterWithCacheManager(CacheManager & manager); -SQUIDCEXTERN void clientdbUpdate(struct IN_ADDR, log_type, protocol_t, size_t); +SQUIDCEXTERN void clientdbUpdate(const IPAddress &, log_type, protocol_t, size_t); -SQUIDCEXTERN int clientdbCutoffDenied(struct IN_ADDR); +SQUIDCEXTERN int clientdbCutoffDenied(const IPAddress &); SQUIDCEXTERN void clientdbDump(StoreEntry *); SQUIDCEXTERN void clientdbFreeMemory(void); -SQUIDCEXTERN int clientdbEstablished(IPAddress &, int); +SQUIDCEXTERN int clientdbEstablished(const IPAddress &, int); SQUIDCEXTERN void clientOpenListenSockets(void); SQUIDCEXTERN void clientHttpConnectionsClose(void); SQUIDCEXTERN void httpRequestFree(void *); @@ -367,7 +367,7 @@ int *timeout); SQUIDCEXTERN void neighborAddAcl(const char *, const char *); -SQUIDCEXTERN void neighborsUdpAck(const cache_key *, icp_common_t *, const struct sockaddr_in *); +SQUIDCEXTERN void neighborsUdpAck(const cache_key *, icp_common_t *, const IPAddress &); SQUIDCEXTERN void neighborAdd(const char *, const char *, int, int, int, int, int); SQUIDCEXTERN void neighbors_init(void); extern void neighborsRegisterWithCacheManager(CacheManager & manager); @@ -391,7 +391,7 @@ SQUIDCEXTERN void dump_peer_options(StoreEntry *, peer *); SQUIDCEXTERN int peerHTTPOkay(const peer *, HttpRequest *); -SQUIDCEXTERN peer *whichPeer(const struct sockaddr_in *from); +SQUIDCEXTERN peer *whichPeer(const IPAddress &from); SQUIDCEXTERN void netdbInit(void); extern void netdbRegisterWitHCacheManager(CacheManager & manager); Index: squid3/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/structs.h,v retrieving revision 1.66.2.15 retrieving revision 1.66.2.16 diff -u -r1.66.2.15 -r1.66.2.16 --- squid3/src/structs.h 8 May 2007 13:55:38 -0000 1.66.2.15 +++ squid3/src/structs.h 16 May 2007 16:04:58 -0000 1.66.2.16 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.66.2.15 2007/05/08 13:55:38 amosjeffries Exp $ + * $Id: structs.h,v 1.66.2.16 2007/05/16 16:04:58 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -979,7 +979,7 @@ char *host; peer_t type; - struct sockaddr_in in_addr; + IPAddress in_addr; struct { @@ -1118,7 +1118,7 @@ int tcp_up; /* 0 if a connect() fails */ - struct IN_ADDR addresses[10]; + IPAddress addresses[10]; int n_addresses; int rr_count; int rr_lastcount;