--------------------- PatchSet 4220 Date: 2007/04/10 12:48:12 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: backout old conversion code. Members: src/net_db.cc:1.13.4.6->1.13.4.7 Index: squid3/src/net_db.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/net_db.cc,v retrieving revision 1.13.4.6 retrieving revision 1.13.4.7 diff -u -r1.13.4.6 -r1.13.4.7 --- squid3/src/net_db.cc 5 Apr 2007 09:23:58 -0000 1.13.4.6 +++ squid3/src/net_db.cc 10 Apr 2007 12:48:12 -0000 1.13.4.7 @@ -1,6 +1,6 @@ /* - * $Id: net_db.cc,v 1.13.4.6 2007/04/05 09:23:58 amosjeffries Exp $ + * $Id: net_db.cc,v 1.13.4.7 2007/04/10 12:48:12 amosjeffries Exp $ * * DEBUG: section 38 Network Measurement Database * AUTHOR: Duane Wessels @@ -115,7 +115,7 @@ netdbHashInsert(netdbEntry * n, struct IN_ADDR addr) { - xstrncpy(n->network, inet_ntoa(networkFromInaddr(addr)), MAXIPSTRLEN); + networkFromInaddr(addr).NtoA(n->network, MAX_IPSTRLEN); n->hash.key = n->network; assert(hash_lookup(addr_table, n->network) == NULL); hash_join(addr_table, &n->hash); @@ -252,12 +252,14 @@ netdbLookupAddr(IPAddress addr) { netdbEntry *n; - char *key = inet_ntoa(networkFromInaddr(addr)); + char *key = new char [MAX_IPSTRLEN]; + networkFromInaddr(addr).NtoA(key,MAX_IPSTRLEN); n = (netdbEntry *) hash_lookup(addr_table, key); return n; } static netdbEntry * + netdbAdd(struct IN_ADDR addr) { netdbEntry *n; @@ -344,19 +346,26 @@ xfree(hostname); } -static struct IN_ADDR -networkFromInaddr(IPAddress in) +static IPAddress +networkFromInaddr(IPAddress &in) { - struct IN_ADDR a; - in.GetInAddr(a); + IPAddress out = in; - struct IN_ADDR b; -#ifdef INET6 - b = a; /* FIXME: How are networks sorted on IPv6 ? */ -#else +#ifdef USE_IPV6 + + /* in IPv6 the 'network' should be the routing section. */ + + if(!in.IsIPv4() && in.IsIPv6()) + { + out.ApplyMask(64, IPv6); + return out; + } +#endif - b.s_addr = ntohl(a.s_addr); #if USE_CLASSFUL + struct in_addr b; + + in.GetInAddr(b); if (IN_CLASSC(b.s_addr)) b.s_addr &= IN_CLASSC_NET; @@ -365,15 +374,14 @@ else if (IN_CLASSA(b.s_addr)) b.s_addr &= IN_CLASSA_NET; -#else - /* use /24 for everything */ - b.s_addr &= IN_CLASSC_NET; + out = b; #endif - b.s_addr = htonl(b.s_addr); -#endif - return b; + /* use /24 for everything under IPv4 */ + out.ApplyMask(24, IPv4); + + return out; } static int @@ -580,7 +588,7 @@ if (NULL == q) continue; - if (!SAFE_INET_ADDR(q, &addr)) + if (!safe_inet_addr(q, &addr)) continue; if (netdbLookupAddr(addr) != NULL) /* no dups! */ @@ -695,7 +703,7 @@ int oldbufofs = ex->buf_ofs; rec_sz = 0; - rec_sz += 1 + sizeof(addr); + rec_sz += 1 + sizeof(addr.s_addr); rec_sz += 1 + sizeof(int); rec_sz += 1 + sizeof(int); debug(38, 3) ("netdbExchangeHandleReply: %d read bytes\n", (int) recievedData.length); @@ -775,7 +783,7 @@ while (size >= rec_sz) { debug(38, 5) ("netdbExchangeHandleReply: in parsing loop, size = %d\n", size); - addr = any_addr; + addr.s_addr = any_addr.s_addr; hops = rtt = 0.0; for (o = 0; o < rec_sz;) { @@ -783,8 +791,8 @@ case NETDB_EX_NETWORK: o++; - xmemcpy(&addr, p + o, sizeof(addr)); - o += sizeof(addr); + xmemcpy(&addr, p + o, sizeof(addr.s_addr)); + o += sizeof(addr.s_addr); break; case NETDB_EX_RTT: @@ -808,7 +816,7 @@ } } - if (!ADDR_IS_ANYADDR(addr) && rtt > 0) + if (addr.s_addr != any_addr.s_addr && rtt > 0) netdbExchangeUpdatePeer(addr, ex->p, rtt, hops); assert(o == rec_sz); @@ -939,14 +947,14 @@ void -netdbHandlePingReply(const struct SOCKADDR_IN *from, int hops, int rtt) +netdbHandlePingReply(const struct sockaddr_in *from, int hops, int rtt) { #if USE_ICMP netdbEntry *n; int N; - debug(38, 3) ("netdbHandlePingReply: from %s\n", SA_NTOA(*from)); + debug(38, 3) ("netdbHandlePingReply: from %s\n", inet_ntoa(from->sin_addr)); - if ((n = netdbLookupAddr(ADDR_FROM_SA(*from))) == NULL) + if ((n = netdbLookupAddr(from->sin_addr)) == NULL) return; N = ++n->pings_recv; @@ -1161,7 +1169,7 @@ netdbEntry *n; net_db_peer *p; debug(38, 5) ("netdbExchangeUpdatePeer: '%s', %0.1f hops, %0.1f rtt\n", - INET_NTOA(addr), hops, rtt); + inet_ntoa(addr), hops, rtt); n = netdbLookupAddr(addr); if (n == NULL) @@ -1224,7 +1232,7 @@ reply->setHeaders(version, HTTP_OK, "OK", NULL, -1, squid_curtime, -2); s->replaceHttpReply(reply); rec_sz = 0; - rec_sz += 1 + sizeof(addr); + rec_sz += 1 + sizeof(addr.s_addr); rec_sz += 1 + sizeof(int); rec_sz += 1 + sizeof(int); buf = (char *)memAllocate(MEM_4K_BUF); @@ -1238,14 +1246,14 @@ if (n->rtt > 60000) /* RTT > 1 MIN probably bogus */ continue; - if (!SAFE_INET_ADDR(n->network, &addr)) + if (!safe_inet_addr(n->network, &addr)) continue; buf[i++] = (char) NETDB_EX_NETWORK; - xmemcpy(&buf[i], &addr, sizeof(addr)); + xmemcpy(&buf[i], &addr.s_addr, sizeof(addr.s_addr)); - i += sizeof(addr); + i += sizeof(addr.s_addr); buf[i++] = (char) NETDB_EX_RTT;