--------------------- PatchSet 5471 Date: 2007/08/22 02:27:03 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Part 1: IPv6 enabling external ACL helpers - Adds 'ipv6' / 'ipv4' options to external_acl_type - Removes hard-coded localhost address from globals - Uses SetLocalhost in place of hardcoded - Uses SetIPv4 to override default IPv6 localhost at need Members: include/IPAddress.h:1.1.2.35->1.1.2.36 lib/IPAddress.cc:1.1.2.66->1.1.2.67 src/external_acl.cc:1.37.6.13->1.37.6.14 src/globals.h:1.17.2.10->1.17.2.11 src/ipc.cc:1.9.4.13->1.9.4.14 src/main.cc:1.42.4.16->1.42.4.17 Index: squid3/include/IPAddress.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/include/Attic/IPAddress.h,v retrieving revision 1.1.2.35 retrieving revision 1.1.2.36 diff -u -r1.1.2.35 -r1.1.2.36 --- squid3/include/IPAddress.h 21 Aug 2007 12:52:17 -0000 1.1.2.35 +++ squid3/include/IPAddress.h 22 Aug 2007 02:27:03 -0000 1.1.2.36 @@ -1,5 +1,5 @@ /* - * $Id: IPAddress.h,v 1.1.2.35 2007/08/21 12:52:17 amosjeffries Exp $ + * $Id: IPAddress.h,v 1.1.2.36 2007/08/22 02:27:03 amosjeffries Exp $ * * DEBUG: section 14 IP Storage and Handling * AUTHOR: Amos Jeffries @@ -206,13 +206,13 @@ /// Fast reset of the stored content to what would be after default constructor. void SetEmpty(); -#if USE_IPV6 - /// HACK: While transparent fails on IPv6 ports. - // Partial-empty. Leaves the signature IPv4-mapped prefix. - // Used to force a wildcard address to default as IPv4 - // when GetAddrInfo() is called for port binding. + /** Require an IPv4-only address for this usage. + * Converts the object to prefer only IPv4 output. + \retval true Content can be IPv4 + \retval false Content CANNOT be IPv4 + */ bool SetIPv4(); -#endif + /** * Valid results IF and only IF the stored IP address is actually a network bitmask * \retval N number of bits which are set in the bitmask stored. Index: squid3/lib/IPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/IPAddress.cc,v retrieving revision 1.1.2.66 retrieving revision 1.1.2.67 diff -u -r1.1.2.66 -r1.1.2.67 --- squid3/lib/IPAddress.cc 21 Aug 2007 12:52:18 -0000 1.1.2.66 +++ squid3/lib/IPAddress.cc 22 Aug 2007 02:27:04 -0000 1.1.2.67 @@ -1,5 +1,5 @@ /* - * $Id: IPAddress.cc,v 1.1.2.66 2007/08/21 12:52:18 amosjeffries Exp $ + * $Id: IPAddress.cc,v 1.1.2.67 2007/08/22 02:27:04 amosjeffries Exp $ * * DEBUG: section 14 IP Storage and Handling * AUTHOR: Amos Jeffries @@ -302,13 +302,10 @@ memset(&m_SocketAddr, 0, sizeof(m_SocketAddr) ); } -#if USE_IPV6 -// HACK: Force 'transparent' ports to be always IPv4-only. -// Leaves the signature IPv4-mapped prefix. -// used to force a wildcard address to default as IPv4 -// when GetAddrInfo() is called for port binding. bool IPAddress::SetIPv4() { +#if USE_IPV6 + #if !IPV6_SPECIAL_LOCALHOST if( IsLocalhost() ) { m_SocketAddr.sin6_addr.s6_addr32[2] = htonl(0xffff); @@ -327,8 +324,10 @@ // anything non-IPv4 and non-convertable is BAD. return false; -} +#else + return true; // Always IPv4 in IPv4-only builds. #endif +} bool IPAddress::IsLocalhost() const { Index: squid3/src/external_acl.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/external_acl.cc,v retrieving revision 1.37.6.13 retrieving revision 1.37.6.14 diff -u -r1.37.6.13 -r1.37.6.14 --- squid3/src/external_acl.cc 30 May 2007 05:06:07 -0000 1.37.6.13 +++ squid3/src/external_acl.cc 22 Aug 2007 02:27:04 -0000 1.37.6.14 @@ -1,6 +1,6 @@ /* - * $Id: external_acl.cc,v 1.37.6.13 2007/05/30 05:06:07 amosjeffries Exp $ + * $Id: external_acl.cc,v 1.37.6.14 2007/08/22 02:27:04 amosjeffries Exp $ * * DEBUG: section 82 External ACL * AUTHOR: Henrik Nordstrom, MARA Systems AB @@ -129,6 +129,8 @@ } quote; + + IPAddress local_addr; }; struct _external_acl_format @@ -220,9 +222,13 @@ a = cbdataAlloc(external_acl); + /* set defaults */ a->ttl = DEFAULT_EXTERNAL_ACL_TTL; a->negative_ttl = -1; a->children = DEFAULT_EXTERNAL_ACL_CHILDREN; + a->local_addr.SetLocalhost(); + a->quote = external_acl::QUOTE_METHOD_URL; + token = strtok(NULL, w_space); @@ -233,8 +239,6 @@ token = strtok(NULL, w_space); - a->quote = external_acl::QUOTE_METHOD_URL; - /* Parse options */ while (token) { if (strncmp(token, "ttl=", 4) == 0) { @@ -257,6 +261,23 @@ a->quote = external_acl::QUOTE_METHOD_URL; } else if (strcmp(token, "quote=shell") == 0) { a->quote = external_acl::QUOTE_METHOD_SHELL; + + /* INET6: allow admin to configure some helpers explicitly to + bind to IPv4/v6 localhost port. */ + } else if (strcmp(token, "ipv4") == 0) { + if( !a->local_addr.SetIPv4() ) { +#if USE_IPV6_SPECIAL_LOCALHOST + debugs(3, 0, "WARNING: --with-localhost-ipv6 conflicts with external ACL helper to using IPv4: " << a->name ); +#else + (void)0; +#endif + } + } else if (strcmp(token, "ipv6") == 0) { +#if !USE_IPV6 + debugs(3, 0, "WARNING: --enable-ipv6 required for external ACL helpers to use IPv6: " << a->name ); +#else + (void)0; +#endif } else { break; } Index: squid3/src/globals.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/globals.h,v retrieving revision 1.17.2.10 retrieving revision 1.17.2.11 diff -u -r1.17.2.10 -r1.17.2.11 --- squid3/src/globals.h 14 Aug 2007 02:06:51 -0000 1.17.2.10 +++ squid3/src/globals.h 22 Aug 2007 02:27:04 -0000 1.17.2.11 @@ -1,6 +1,6 @@ /* - * $Id: globals.h,v 1.17.2.10 2007/08/14 02:06:51 amosjeffries Exp $ + * $Id: globals.h,v 1.17.2.11 2007/08/22 02:27:04 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -55,7 +55,6 @@ extern const char *cfg_filename; /* NULL */ extern const char *const appname; /* "squid" */ extern const char *const dash_str; /* "-" */ - extern const char *const localhost; /* "127.0.0.1" */ extern const char *const null_string; /* "" */ extern const char *const version_string; /* VERSION */ extern const char *const full_appname_string; /* PACKAGE "/" VERSION */ Index: squid3/src/ipc.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ipc.cc,v retrieving revision 1.9.4.13 retrieving revision 1.9.4.14 diff -u -r1.9.4.13 -r1.9.4.14 --- squid3/src/ipc.cc 30 Jul 2007 03:17:59 -0000 1.9.4.13 +++ squid3/src/ipc.cc 22 Aug 2007 02:27:04 -0000 1.9.4.14 @@ -1,6 +1,6 @@ /* - * $Id: ipc.cc,v 1.9.4.13 2007/07/30 03:17:59 amosjeffries Exp $ + * $Id: ipc.cc,v 1.9.4.14 2007/08/22 02:27:04 amosjeffries Exp $ * * DEBUG: section 54 Interprocess Communication * AUTHOR: Duane Wessels @@ -103,6 +103,10 @@ if (hIpc) *hIpc = NULL; +/* AYJ INET6 TODO : Some external helpers may require IPv4-localhost */ +/* Find a way to migrate a config option down here per-helper */ +/* once here we can set local_addr.SetLocalhost(AF_*) */ + if (type == IPC_TCP_SOCKET) { crfd = cwfd = comm_open(SOCK_STREAM, 0, Index: squid3/src/main.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/main.cc,v retrieving revision 1.42.4.16 retrieving revision 1.42.4.17 diff -u -r1.42.4.16 -r1.42.4.17 --- squid3/src/main.cc 18 Jun 2007 10:34:04 -0000 1.42.4.16 +++ squid3/src/main.cc 22 Aug 2007 02:27:04 -0000 1.42.4.17 @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.42.4.16 2007/06/18 10:34:04 amosjeffries Exp $ + * $Id: main.cc,v 1.42.4.17 2007/08/22 02:27:04 amosjeffries Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -1123,7 +1123,7 @@ if (oldmask) umask(oldmask); - local_addr = localhost; + local_addr.SetLocalhost(); squid_srandom(time(NULL));