---------------------
PatchSet 4697 
Date: 2007/06/04 06:54:25
Author: amosjeffries
Branch: squid3-ipv6
Tag: (none) 
Log:
Roll conversion fully into squid.conf parser.
Document some more known problems.

Members: 
	NOTES-IPv6:1.1.2.31->1.1.2.32 
	src/cache_cf.cc:1.40.2.29->1.40.2.30 
	src/structs.h:1.66.2.22->1.66.2.23 
	src/wccp.cc:1.10.2.11->1.10.2.12 

Index: squid3/NOTES-IPv6
===================================================================
RCS file: /cvsroot/squid-sf//squid3/Attic/NOTES-IPv6,v
retrieving revision 1.1.2.31
retrieving revision 1.1.2.32
diff -u -r1.1.2.31 -r1.1.2.32
--- squid3/NOTES-IPv6	3 Jun 2007 12:58:31 -0000	1.1.2.31
+++ squid3/NOTES-IPv6	4 Jun 2007 06:54:25 -0000	1.1.2.32
@@ -1,4 +1,4 @@
-$Id: NOTES-IPv6,v 1.1.2.31 2007/06/03 12:58:31 amosjeffries Exp $
+$Id: NOTES-IPv6,v 1.1.2.32 2007/06/04 06:54:25 amosjeffries Exp $
 
 KNOWN BUGS:
 
@@ -8,15 +8,17 @@
           Solved for all known events now, but this may reccur at any time
           until conversion is completed.
 
+
 PROBLEM: Sockets created with IPv4 'family' cannot be use for IPv6 anywhere
 	Likewise ones opened for IPv6 on split-stack systems cannot be used for IPv4.
 	The system that allocates pre-opened sockets to connections needs to
-	be modified such that it records the family of a socket and checks the
-	client addr family matches the socket family before allocating it.
+	be modified such that it checks the stored family of the socket
+	matches the client addr family before allocating it.
 
 NP: have modified fde to store the sock_family a socket was allocated with.
     Also GetAddrInfo to specifiy needed protocol formatting of an addrinfo
     this will still fail retrieving AF_INET of an IPv6-pure destination.
+    Or on split-stacks needing a crossover port type (IPv4->IPv6, and reverse)
 
 
 PROBLEM Segmentation Fault retrieving NtoA of address.
@@ -79,6 +81,67 @@
 #34 0x080cb01e in main (argc=4, argv=0xbf8e70e4) at main.cc:1315
 
 
+PROBLEM: BUG 1965 - Memory Violation(s) in FwdState
+	Write violation is critical. Read's are only major.
+NP: possible link to above SegFault, unconfirmed.
+Valgrind trace:
+==5271== 2 errors in context 20 of 26:
+==5271== Invalid write of size 4
+==5271==    at 0x8097943: FwdState::abort(void*) (RefCount.h:103)
+==5271==    by 0x8090896: EventDispatcher::dispatch() (event.cc:131)
+==5271==    by 0x8091833: EventLoop::runOnce() (EventLoop.cc:131)
+==5271==    by 0x8091919: EventLoop::run() (EventLoop.cc:100)
+==5271==    by 0x80CB05D: main (main.cc:1315)
+==5271==  Address 0x43E3DE4 is 20 bytes inside a block of size 56 free'd
+==5271==    at 0x402123A: free (vg_replace_malloc.c:233)
+==5271==    by 0x8125CDB: MemImplementingAllocator::free(void*) (MemPool.cc:555)
+==5271==    by 0x80704A2: cbdataInternalUnlock(void const*) (cbdata.cc:484)
+==5271==    by 0x81058E6: commCallCloseHandlers (comm.cc:1473)
+==5271==    by 0x810A0DF: _comm_close(int, char const*, int) (comm.cc:1646)
+==5271==    by 0x8097938: FwdState::abort(void*) (forward.cc:85)
+==5271==    by 0x8090896: EventDispatcher::dispatch() (event.cc:131)
+==5271==    by 0x8091833: EventLoop::runOnce() (EventLoop.cc:131)
+==5271==    by 0x8091919: EventLoop::run() (EventLoop.cc:100)
+==5271==    by 0x80CB05D: main (main.cc:1315)
+==5271== 
+==5271== 2 errors in context 21 of 26:
+==5271== Invalid read of size 4
+==5271==    at 0x8097940: FwdState::abort(void*) (RefCount.h:102)
+==5271==    by 0x8090896: EventDispatcher::dispatch() (event.cc:131)
+==5271==    by 0x8091833: EventLoop::runOnce() (EventLoop.cc:131)
+==5271==    by 0x8091919: EventLoop::run() (EventLoop.cc:100)
+==5271==    by 0x80CB05D: main (main.cc:1315)
+==5271==  Address 0x43E3DE4 is 20 bytes inside a block of size 56 free'd
+==5271==    at 0x402123A: free (vg_replace_malloc.c:233)
+==5271==    by 0x8125CDB: MemImplementingAllocator::free(void*) (MemPool.cc:555)
+==5271==    by 0x80704A2: cbdataInternalUnlock(void const*) (cbdata.cc:484)
+==5271==    by 0x81058E6: commCallCloseHandlers (comm.cc:1473)
+==5271==    by 0x810A0DF: _comm_close(int, char const*, int) (comm.cc:1646)
+==5271==    by 0x8097938: FwdState::abort(void*) (forward.cc:85)
+==5271==    by 0x8090896: EventDispatcher::dispatch() (event.cc:131)
+==5271==    by 0x8091833: EventLoop::runOnce() (EventLoop.cc:131)
+==5271==    by 0x8091919: EventLoop::run() (EventLoop.cc:100)
+==5271==    by 0x80CB05D: main (main.cc:1315)
+==5271== 
+==5271== 2 errors in context 22 of 26:
+==5271== Invalid write of size 4
+==5271==    at 0x8097939: FwdState::abort(void*) (forward.cc:86)
+==5271==    by 0x8090896: EventDispatcher::dispatch() (event.cc:131)
+==5271==    by 0x8091833: EventLoop::runOnce() (EventLoop.cc:131)
+==5271==    by 0x8091919: EventLoop::run() (EventLoop.cc:100)
+==5271==    by 0x80CB05D: main (main.cc:1315)
+==5271==  Address 0x43E3DDC is 12 bytes inside a block of size 56 free'd
+==5271==    at 0x402123A: free (vg_replace_malloc.c:233)
+==5271==    by 0x8125CDB: MemImplementingAllocator::free(void*) (MemPool.cc:555)
+==5271==    by 0x80704A2: cbdataInternalUnlock(void const*) (cbdata.cc:484)
+==5271==    by 0x81058E6: commCallCloseHandlers (comm.cc:1473)
+==5271==    by 0x810A0DF: _comm_close(int, char const*, int) (comm.cc:1646)
+==5271==    by 0x8097938: FwdState::abort(void*) (forward.cc:85)
+==5271==    by 0x8090896: EventDispatcher::dispatch() (event.cc:131)
+==5271==    by 0x8091833: EventLoop::runOnce() (EventLoop.cc:131)
+==5271==    by 0x8091919: EventLoop::run() (EventLoop.cc:100)
+==5271==    by 0x80CB05D: main (main.cc:1315)
+
 
 cache.log lines detected showing possible problems:
      (after a request for http://[2001:200:0:8002:203:47ff:fea5:3085]/ )
@@ -96,6 +159,8 @@
 
 1.2	Migrate code to using IPAddress object over any other method of struct storage
 
+1.3	Track and close all bugs listed above.
+
 3       Push incremental patches to HEAD (on hold for 3.1 branch)
 
 3.1             IPAddress.*
Index: squid3/src/cache_cf.cc
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/cache_cf.cc,v
retrieving revision 1.40.2.29
retrieving revision 1.40.2.30
diff -u -r1.40.2.29 -r1.40.2.30
--- squid3/src/cache_cf.cc	3 Jun 2007 12:14:45 -0000	1.40.2.29
+++ squid3/src/cache_cf.cc	4 Jun 2007 06:54:25 -0000	1.40.2.30
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.cc,v 1.40.2.29 2007/06/03 12:14:45 amosjeffries Exp $
+ * $Id: cache_cf.cc,v 1.40.2.30 2007/06/04 06:54:25 amosjeffries Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -843,15 +843,6 @@
     storeAppendPrintf(entry, "%s %s\n", name, addr.NtoA(buf,MAX_IPSTRLEN) );
 }
 
-/* FIXME INET6 : drop this following function once config parsing is fully converted */
-/* exists solely to enable smooth slow transition from old to new code. */
-static void
-dump_address(StoreEntry * entry, const char *name, struct IN_ADDR addr)
-{
-    IPAddress tmp(addr);
-    dump_address(entry, name, tmp);
-}
-
 static void
 parse_address(IPAddress *addr)
 {
@@ -874,33 +865,12 @@
         *addr = token;
 }
 
-/* FIXME INET6 : drop this temporary conversion function when Config parse is converted. */
-// exists solely so that we don't have to convert the entire Config structure and all 
-// the code that uses it in one update.
-static void parse_address(struct IN_ADDR *addr)
-{ 
-    // use a temporary wrapper IPAddress for the converted code.
-    IPAddress tmp;
-    tmp = *addr;
-    parse_address(&tmp);
-    // pull the resulting data back out into the unconverted struct(s) for use by unconverted code.
-    tmp.GetInAddr(*addr);
-}
-
 static void
 free_address(IPAddress *addr)
 {
     addr->SetEmpty();
 }
 
-/* FIXME INET6 : drop this function once conf parsing is fully converted */
-/* exists solely to enable smooth incremental transition to IPAddress */
-static void
-free_address(struct IN_ADDR *addr)
-{
-    memset(addr, '\0', sizeof(struct IN_ADDR));
-}
-
 CBDATA_TYPE(acl_address);
 
 static void
Index: squid3/src/structs.h
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/structs.h,v
retrieving revision 1.66.2.22
retrieving revision 1.66.2.23
diff -u -r1.66.2.22 -r1.66.2.23
--- squid3/src/structs.h	3 Jun 2007 12:14:48 -0000	1.66.2.22
+++ squid3/src/structs.h	4 Jun 2007 06:54:25 -0000	1.66.2.23
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.66.2.22 2007/06/03 12:14:48 amosjeffries Exp $
+ * $Id: structs.h,v 1.66.2.23 2007/06/04 06:54:25 amosjeffries Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -76,7 +76,7 @@
     long reqid;
     int outlen;
 
-    struct sockaddr_in from;
+    IPAddress from;
 
     struct snmp_pdu *PDU;
     ACLChecklist *acl_checklist;
@@ -299,9 +299,9 @@
     struct
     {
 
-        struct IN_ADDR router;
+        IPAddress router;
 
-        struct IN_ADDR address;
+        IPAddress address;
         int version;
     }
 
@@ -313,7 +313,7 @@
     {
         sockaddr_in_list *router;
 
-        struct IN_ADDR address;
+        IPAddress address;
         int forwarding_method;
         int return_method;
         int assignment_method;
@@ -434,9 +434,9 @@
         IPAddress udp_outgoing;
 #if SQUID_SNMP
 
-        struct IN_ADDR snmp_incoming;
+        IPAddress snmp_incoming;
 
-        struct IN_ADDR snmp_outgoing;
+        IPAddress snmp_outgoing;
 #endif
         /* INET6 : this should really be a CIDR value */
         IPAddress client_netmask;
@@ -665,7 +665,7 @@
     struct
     {
 
-        struct IN_ADDR addr;
+        IPAddress addr;
         int ttl;
         unsigned short port;
         char *encode_key;
@@ -1199,7 +1199,7 @@
 struct _pingerEchoData
 {
 
-    struct IN_ADDR to;
+    struct in_addr to;
     unsigned char opcode;
     int psize;
     char payload[PINGER_PAYLOAD_SZ];
@@ -1209,7 +1209,7 @@
 struct _pingerReplyData
 {
 
-    struct IN_ADDR from;
+    struct in_addr from;
     unsigned char opcode;
     int rtt;
     int hops;
Index: squid3/src/wccp.cc
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/wccp.cc,v
retrieving revision 1.10.2.11
retrieving revision 1.10.2.12
diff -u -r1.10.2.11 -r1.10.2.12
--- squid3/src/wccp.cc	1 May 2007 08:32:32 -0000	1.10.2.11
+++ squid3/src/wccp.cc	4 Jun 2007 06:54:25 -0000	1.10.2.12
@@ -1,6 +1,6 @@
 
 /*
- * $Id: wccp.cc,v 1.10.2.11 2007/05/01 08:32:32 amosjeffries Exp $
+ * $Id: wccp.cc,v 1.10.2.12 2007/06/04 06:54:25 amosjeffries Exp $
  *
  * DEBUG: section 80    WCCP Support
  * AUTHOR: Glenn Chisholm
@@ -61,8 +61,7 @@
 
 struct wccp_cache_entry_t
 {
-
-    struct IN_ADDR ip_addr;
+    IPAddress ip_addr;
     int revision;
     char hash[WCCP_HASH_SIZE];
     int reserved;
@@ -96,7 +95,7 @@
 static int last_assign_buckets_change;
 static unsigned int number_caches;
 
-static struct IN_ADDR local_ip;
+static IPAddress local_ip;
 
 static PF wccpHandleUdp;
 static int wccpLowestIP(void);
@@ -124,7 +123,7 @@
     last_assign_buckets_change = 0;
     number_caches = 0;
 
-    if (Config.Wccp.router.s_addr != any_addr.s_addr)
+    if (!Config.Wccp.router.IsAnyAddr())
         if (!eventFind(wccpHereIam, NULL))
             eventAdd("wccpHereIam", wccpHereIam, NULL, 5.0, 1);
 }
@@ -132,21 +131,24 @@
 void
 wccpConnectionOpen(void)
 {
-    u_short port = WCCP_PORT;
-
-    struct sockaddr_in router, local;
-    socklen_t local_len, router_len;
+    struct addrinfo *router = NULL, *local = NULL;
     debugs(80, 5, "wccpConnectionOpen: Called");
 
-    if (Config.Wccp.router.s_addr == any_addr.s_addr) {
+    if (Config.Wccp.router.IsAnyAddr()) {
         debugs(1, 1, "WCCP Disabled.");
         return;
     }
 
-/* FIXME INET6 : drop temp conversion boundary */ IPAddress tmp(Config.Wccp.address); tmp.SetPort(WCCP_PORT);
+    if (Config.Wccp.router.IsIPv4()) {
+        debugs(1, 1, "WCCP Disabled. IPv4 required.");
+        return;
+    }
+
+    Config.Wccp.address.SetPort(WCCP_PORT);
+
     theWccpConnection = comm_open(SOCK_DGRAM,
                                   IPPROTO_UDP,
-                                  tmp,
+                                  Config.Wccp.address,
                                   COMM_NONBLOCKING,
                                   "WCCP Socket");
 
@@ -159,30 +161,25 @@
                   NULL,
                   0);
 
-    debugs(1, 1, "Accepting WCCP messages on port " << port << ", FD " << theWccpConnection << ".");
-
+    debugs(1, 1, "Accepting WCCP messages on " << Config.Wccp.address << ", FD " << theWccpConnection << ".");
 
-    router_len = sizeof(router);
+    Config.Wccp.router.GetAddrInfo(router,AF_INET);
 
-    memset(&router, '\0', router_len);
-
-    router.sin_family = AF_INET;
-
-    router.sin_port = htons(port);
-
-    router.sin_addr = Config.Wccp.router;
-
-    if (connect(theWccpConnection, (struct sockaddr *) &router, router_len))
+    if (connect(theWccpConnection, router->ai_addr, router->ai_addrlen))
         fatal("Unable to connect WCCP out socket");
 
-    local_len = sizeof(local);
+    Config.Wccp.router.FreeAddrInfo(router);
+
+    Config.Wccp.address.GetAddrInfo(local,AF_INET);
 
-    memset(&local, '\0', local_len);
+    memset(local->ai_addr, '\0', local->ai_addrlen);
 
-    if (getsockname(theWccpConnection, (struct sockaddr *) &local, &local_len))
+    if (getsockname(theWccpConnection, local->ai_addr, &local->ai_addrlen))
         fatal("Unable to getsockname on WCCP out socket");
 
-    local_ip.s_addr = local.sin_addr.s_addr;
+    local_ip = *local;
+
+     Config.Wccp.address.FreeAddrInfo(local);
 }
 
 
@@ -291,10 +288,10 @@
     for (loop = 0; loop < (unsigned) ntohl(wccp_i_see_you.number); loop++) {
         assert(loop < WCCP_ACTIVE_CACHES);
 
-        if (wccp_i_see_you.wccp_cache_entry[loop].ip_addr.s_addr < local_ip.s_addr)
+        if (wccp_i_see_you.wccp_cache_entry[loop].ip_addr < local_ip)
             return 0;
 
-        if (wccp_i_see_you.wccp_cache_entry[loop].ip_addr.s_addr == local_ip.s_addr)
+        if (wccp_i_see_you.wccp_cache_entry[loop].ip_addr == local_ip)
             found = 1;
     }
 
@@ -359,7 +356,7 @@
     for (loop = 0; loop < number_caches; loop++) {
         int i;
         xmemcpy(&caches[loop],
-                &wccp_i_see_you.wccp_cache_entry[loop].ip_addr.s_addr,
+                &wccp_i_see_you.wccp_cache_entry[loop].ip_addr,
                 sizeof(*caches));
 
         for (i = 0; i < buckets_per_cache; i++) {
