--------------------- PatchSet 3287 Date: 2001/10/30 12:11:10 Author: rvenning Branch: ipv6 Tag: (none) Log: ipcacheAddEntryFromHosts microfix to warn sanely Quick hack to wccp.c to hopefully handle wccp connections over IPv4 through IPv6 socket using IPv4 mapped(? I get confused with compatible sometimes) addresses. Members: src/acl.c:1.4.6.11->1.4.6.12 src/ipcache.c:1.4.6.8->1.4.6.9 src/structs.h:1.7.2.7->1.7.2.8 src/wccp.c:1.3.6.1->1.3.6.2 Index: squid/src/acl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/acl.c,v retrieving revision 1.4.6.11 retrieving revision 1.4.6.12 diff -u -r1.4.6.11 -r1.4.6.12 --- squid/src/acl.c 30 Oct 2001 09:01:21 -0000 1.4.6.11 +++ squid/src/acl.c 30 Oct 2001 12:11:10 -0000 1.4.6.12 @@ -1,6 +1,6 @@ /* - * $Id: acl.c,v 1.4.6.11 2001/10/30 09:01:21 rvenning Exp $ + * $Id: acl.c,v 1.4.6.12 2001/10/30 12:11:10 rvenning Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -376,6 +376,7 @@ void make_mask(int len, struct IN_ADDR *mask) { +#ifdef INET6 int bp; if (len > 128 || len < 0) return; @@ -390,6 +391,11 @@ mask->s6_addr[bp] = 0xff << clearbits; } } +#else + if (len > 32 || len < 0) + return; + mask->s_addr = 0xffffffff << (32 - len); +#endif } /* @@ -401,6 +407,9 @@ decode_addr(const char *asc, struct IN_ADDR *addr, struct IN_ADDR *mask) { int a1 = 0; +#ifndef INET6 + u_num32 a; +#endif if(!SAFE_INET_ADDR(asc, addr)) { switch (sscanf(asc, "%d", &a1)) { @@ -417,6 +426,7 @@ if (mask != NULL) { /* mask == NULL if called to decode a netmask */ +#ifdef INET6 /* Guess netmask */ int shift = 127; while (shift >= 0) { @@ -428,16 +438,30 @@ } make_mask(shift+1, mask); +#else + /* Guess netmask */ + a = (u_num32) ntohl(addr->s_addr); + if (!(a & 0xFFFFFFFFul)) + mask->s_addr = htonl(0x00000000ul); + else if (!(a & 0x00FFFFFF)) + mask->s_addr = htonl(0xFF000000ul); + else if (!(a & 0x0000FFFF)) + mask->s_addr = htonl(0xFFFF0000ul); + else if (!(a & 0x000000FF)) + mask->s_addr = htonl(0xFFFFFF00ul); + else + mask->s_addr = htonl(0xFFFFFFFFul); +#endif } return 1; } -#define SCAN_ACL1 "%[0123456789.:]-%[0123456789.:]/%[0123456789.]" -#define SCAN_ACL2 "%[0123456789.:]-%[0123456789.:]%c" -#define SCAN_ACL3 "%[0123456789.:]/%[0123456789.:]" -#define SCAN_ACL4 "%[0123456789.:]%c" +#define SCAN_ACL1 "%[0123456789abcdefABCDEF.:]-%[0123456789abcdefABCDEF.:]/%[0123456789.]" +#define SCAN_ACL2 "%[0123456789abcdefABCDEF.:]-%[0123456789abcdefABCDEF.:]%c" +#define SCAN_ACL3 "%[0123456789abcdefABCDEF.:]/%[0123456789.:]" +#define SCAN_ACL4 "%[0123456789abcdefABCDEF.:]%c" static acl_ip_data * aclParseIpData(const char *t) Index: squid/src/ipcache.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ipcache.c,v retrieving revision 1.4.6.8 retrieving revision 1.4.6.9 diff -u -r1.4.6.8 -r1.4.6.9 --- squid/src/ipcache.c 25 Oct 2001 18:24:55 -0000 1.4.6.8 +++ squid/src/ipcache.c 30 Oct 2001 12:11:10 -0000 1.4.6.9 @@ -1,6 +1,6 @@ /* - * $Id: ipcache.c,v 1.4.6.8 2001/10/25 18:24:55 hno Exp $ + * $Id: ipcache.c,v 1.4.6.9 2001/10/30 12:11:10 rvenning Exp $ * * DEBUG: section 14 IP Cache * AUTHOR: Harvest Derived @@ -845,14 +845,24 @@ * adds a "static" entry from /etc/hosts. * returns 0 upon success, 1 if the ip address is invalid */ +#define V6ADDR "%[0123456789abcdefABCDEF.:]" + int ipcacheAddEntryFromHosts(const char *name, const char *ipaddr) { + LOCAL_ARRAY(char, v6test, 256); ipcache_entry *i; struct IN_ADDR ip; if (!SAFE_INET_ADDR(ipaddr, &ip)) { - debug(14, 1) ("ipcacheAddEntryFromHosts: bad IP address '%s'\n", - ipaddr); +#ifndef INET6 + if ((strlen(ipaddr) <= MAXIPSTRLEN) && + (sscanf(ipaddr, V6ADDR, v6test) == 1)) + debug(14, 1) ("ipcacheAddEntryFromHosts: this Squid has not been compiled with --enable-ipv6 - skipping '%s'\n", + ipaddr); + else +#endif + debug(14, 1) ("ipcacheAddEntryFromHosts: bad IP address '%s'\n", + ipaddr); return 1; } if ((i = ipcache_get(name))) { Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.7.2.7 retrieving revision 1.7.2.8 diff -u -r1.7.2.7 -r1.7.2.8 --- squid/src/structs.h 30 Oct 2001 09:01:28 -0000 1.7.2.7 +++ squid/src/structs.h 30 Oct 2001 12:11:10 -0000 1.7.2.8 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.7.2.7 2001/10/30 09:01:28 rvenning Exp $ + * $Id: structs.h,v 1.7.2.8 2001/10/30 12:11:10 rvenning Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -437,9 +437,9 @@ #endif #if USE_WCCP struct { - struct in_addr router; - struct in_addr incoming; - struct in_addr outgoing; + struct IN_ADDR router; + struct IN_ADDR incoming; + struct IN_ADDR outgoing; int version; } Wccp; #endif Index: squid/src/wccp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/wccp.c,v retrieving revision 1.3.6.1 retrieving revision 1.3.6.2 diff -u -r1.3.6.1 -r1.3.6.2 --- squid/src/wccp.c 23 Mar 2001 16:06:32 -0000 1.3.6.1 +++ squid/src/wccp.c 30 Oct 2001 12:11:10 -0000 1.3.6.2 @@ -1,6 +1,6 @@ /* - * $Id: wccp.c,v 1.3.6.1 2001/03/23 16:06:32 rvenning Exp $ + * $Id: wccp.c,v 1.3.6.2 2001/10/30 12:11:10 rvenning Exp $ * * DEBUG: section 80 WCCP Support * AUTHOR: Glenn Chisholm @@ -84,7 +84,7 @@ static struct wccp_here_i_am_t wccp_here_i_am; static struct wccp_i_see_you_t wccp_i_see_you; static int change; -static struct in_addr local_ip; +static struct IN_ADDR local_ip; static PF wccpHandleUdp; static int wccpLowestIP(void); @@ -108,7 +108,7 @@ wccp_here_i_am.version = htonl(Config.Wccp.version); wccp_here_i_am.revision = htonl(WCCP_REVISION); change = 0; - if (Config.Wccp.router.s_addr != any_addr.s_addr) + if (!ADDR_IS_ANYADDR(Config.Wccp.router)) if (!eventFind(wccpHereIam, NULL)) eventAdd("wccpHereIam", wccpHereIam, NULL, 5.0, 1); } @@ -117,10 +117,10 @@ wccpConnectionOpen(void) { u_short port = WCCP_PORT; - struct sockaddr_in router, local; + struct SOCKADDR_IN router, local; int local_len, router_len; debug(80, 5) ("wccpConnectionOpen: Called\n"); - if (Config.Wccp.router.s_addr == any_addr.s_addr) { + if (ADDR_IS_ANYADDR(Config.Wccp.router)) { debug(1, 1) ("WCCP Disabled.\n"); return; } @@ -139,7 +139,7 @@ 0); debug(1, 1) ("Accepting WCCP messages on port %d, FD %d.\n", (int) port, theInWccpConnection); - if (Config.Wccp.outgoing.s_addr != no_addr.s_addr) { + if (!ADDR_IS_NOADDR(Config.Wccp.outgoing)) { theOutWccpConnection = comm_open(SOCK_DGRAM, 0, Config.Wccp.outgoing, @@ -161,16 +161,16 @@ } router_len = sizeof(router); memset(&router, '\0', router_len); - router.sin_family = AF_INET; - router.sin_port = htons(port); - router.sin_addr = Config.Wccp.router; + FAMILY_FROM_SA(router) = AF_FAMILY; + PORT_FROM_SA(router) = htons(port); + ADDR_FROM_SA(router) = Config.Wccp.router; if (connect(theOutWccpConnection, (struct sockaddr *) &router, router_len)) fatal("Unable to connect WCCP out socket"); local_len = sizeof(local); memset(&local, '\0', local_len); if (getsockname(theOutWccpConnection, (struct sockaddr *) &local, &local_len)) fatal("Unable to getsockname on WCCP out socket"); - local_ip.s_addr = local.sin_addr.s_addr; + local_ip = ADDR_FROM_SA(local); } void @@ -206,7 +206,7 @@ static void wccpHandleUdp(int sock, void *not_used) { - struct sockaddr_in from; + struct SOCKADDR_IN from; socklen_t from_len; int len; @@ -227,7 +227,7 @@ &from_len); if (len < 0) return; - if (Config.Wccp.router.s_addr != from.sin_addr.s_addr) + if (memcmp(&Config.Wccp.router, &ADDR_FROM_SA(from), sizeof(Config.Wccp.router))) return; if (ntohl(wccp_i_see_you.version) != Config.Wccp.version) return; @@ -249,7 +249,11 @@ { int loop; for (loop = 0; loop < ntohl(wccp_i_see_you.number); loop++) { +#ifdef INET6 /* *** FIXME *** we presume that local_ip is really an IPv4 address */ + if (wccp_i_see_you.wccp_cache_entry[loop].ip_addr.s_addr < local_ip.s6_addr32[3]) +#else if (wccp_i_see_you.wccp_cache_entry[loop].ip_addr.s_addr < local_ip.s_addr) +#endif return 0; } return 1;