--------------------- PatchSet 9698 Date: 2007/07/02 07:36:51 Author: amosjeffries Branch: ipv6 Tag: (none) Log: Rollback Jan2007 patch from Husni. Newer one available now. Members: include/rfc1035.h:1.3.6.7->1.3.6.8 include/util.h:1.4.4.6->1.4.4.7 lib/rfc1035.c:1.4.6.10->1.4.6.11 lib/safe_inet_addr.c:1.2.6.6->1.2.6.7 src/HttpRequest.c:1.3.6.5->1.3.6.6 src/access_log.c:1.5.2.10->1.5.2.11 src/acl.c:1.4.6.18->1.4.6.19 src/asn.c:1.4.4.7->1.4.4.8 src/authenticate.c:1.4.6.10->1.4.6.11 src/cache_cf.c:1.4.2.13->1.4.2.14 src/cf.data.pre:1.4.6.8->1.4.6.9 src/cf_gen.c:1.3.6.5->1.3.6.6 src/client_db.c:1.4.6.6->1.4.6.7 src/client_side.c:1.7.2.12->1.7.2.13 src/comm.c:1.4.6.11->1.4.6.12 src/comm_generic.c:1.8.14.3->1.8.14.4 src/defines.h:1.3.6.10->1.3.6.11 src/delay_pools.c:1.3.6.5->1.3.6.6 src/dns_internal.c:1.5.6.9->1.5.6.10 src/errorpage.c:1.5.2.8->1.5.2.9 src/external_acl.c:1.12.2.3->1.12.2.4 src/forward.c:1.4.6.9->1.4.6.10 src/fqdncache.c:1.4.6.7->1.4.6.8 src/ftp.c:1.5.2.9->1.5.2.10 src/globals.h:1.4.4.7->1.4.4.8 src/http.c:1.5.2.7->1.5.2.8 src/icp_v2.c:1.3.6.7->1.3.6.8 src/icp_v3.c:1.3.6.4->1.3.6.5 src/ident.c:1.4.6.6->1.4.6.7 src/internal.c:1.5.2.4->1.5.2.5 src/ipc.c:1.3.6.5->1.3.6.6 src/ipcache.c:1.4.6.14->1.4.6.15 src/main.c:1.5.4.8->1.5.4.9 src/multicast.c:1.3.6.5->1.3.6.6 src/neighbors.c:1.5.4.10->1.5.4.11 src/net_db.c:1.6.2.7->1.6.2.8 src/pconn.c:1.4.6.5->1.4.6.6 src/peer_select.c:1.3.6.8->1.3.6.9 src/peer_sourcehash.c:1.3.42.3->1.3.42.4 src/protos.h:1.5.2.14->1.5.2.15 src/redirect.c:1.3.6.6->1.3.6.7 src/send-announce.c:1.3.6.5->1.3.6.6 src/snmp_agent.c:1.3.6.5->1.3.6.6 src/snmp_core.c:1.3.6.9->1.3.6.10 src/ssl.c:1.3.6.9->1.3.6.10 src/stat.c:1.4.6.7->1.4.6.8 src/structs.h:1.7.2.12->1.7.2.13 src/tools.c:1.4.2.12->1.4.2.13 src/typedefs.h:1.4.2.7->1.4.2.8 src/url.c:1.3.6.7->1.3.6.8 src/wccp.c:1.3.6.5->1.3.6.6 src/wccp2.c:1.28.2.3->1.28.2.4 src/auth/digest/auth_digest.c:1.4.12.6->1.4.12.7 Index: squid/include/rfc1035.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/rfc1035.h,v retrieving revision 1.3.6.7 retrieving revision 1.3.6.8 diff -u -r1.3.6.7 -r1.3.6.8 --- squid/include/rfc1035.h 1 Jul 2007 05:46:09 -0000 1.3.6.7 +++ squid/include/rfc1035.h 2 Jul 2007 07:36:51 -0000 1.3.6.8 @@ -1,5 +1,5 @@ /* - * $Id: rfc1035.h,v 1.3.6.7 2007/07/01 05:46:09 amosjeffries Exp $ + * $Id: rfc1035.h,v 1.3.6.8 2007/07/02 07:36:51 amosjeffries Exp $ * * AUTHOR: Duane Wessels * @@ -38,9 +38,6 @@ #if HAVE_SYS_TYPES_H #include #endif -#if HAVE_SYS_SOCKET_H -#include -#endif #if HAVE_NETINET_IN_H #include #endif @@ -74,7 +71,6 @@ unsigned int tc:1; unsigned int rd:1; unsigned int ra:1; - unsigned int z:3; unsigned int rcode:4; unsigned short qdcount; unsigned short ancount; @@ -89,12 +85,7 @@ size_t sz, unsigned short qid, rfc1035_query * query); -extern ssize_t rfc1035BuildAAAAQuery(const char *hostname, - char *buf, - size_t sz, - unsigned short qid, - rfc1035_query * query); -extern ssize_t rfc1035BuildPTRQuery(const struct sockaddr *, +extern ssize_t rfc1035BuildPTRQuery(const struct in_addr, char *buf, size_t sz, unsigned short qid, @@ -109,7 +100,6 @@ extern const char *rfc1035_error_message; #define RFC1035_TYPE_A 1 -#define RFC1035_TYPE_AAAA 28 #define RFC1035_TYPE_CNAME 5 #define RFC1035_TYPE_PTR 12 #define RFC1035_CLASS_IN 1 Index: squid/include/util.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/util.h,v retrieving revision 1.4.4.6 retrieving revision 1.4.4.7 diff -u -r1.4.4.6 -r1.4.4.7 --- squid/include/util.h 1 Jul 2007 05:46:09 -0000 1.4.4.6 +++ squid/include/util.h 2 Jul 2007 07:36:51 -0000 1.4.4.7 @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.4.4.6 2007/07/01 05:46:09 amosjeffries Exp $ + * $Id: util.h,v 1.4.4.7 2007/07/02 07:36:51 amosjeffries Exp $ * * AUTHOR: Harvest Derived * @@ -104,7 +104,7 @@ extern void xmalloc_find_leaks(void); #endif -typedef struct sockaddr SIA; +typedef struct in_addr SIA; extern int safe_inet_addr(const char *, SIA *); extern time_t parse_iso3307_time(const char *buf); extern char *base64_decode(const char *coded); Index: squid/lib/rfc1035.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/rfc1035.c,v retrieving revision 1.4.6.10 retrieving revision 1.4.6.11 diff -u -r1.4.6.10 -r1.4.6.11 --- squid/lib/rfc1035.c 1 Jul 2007 05:46:09 -0000 1.4.6.10 +++ squid/lib/rfc1035.c 2 Jul 2007 07:36:51 -0000 1.4.6.11 @@ -1,6 +1,6 @@ /* - * $Id: rfc1035.c,v 1.4.6.10 2007/07/01 05:46:09 amosjeffries Exp $ + * $Id: rfc1035.c,v 1.4.6.11 2007/07/02 07:36:51 amosjeffries Exp $ * * Low level DNS protocol routines * AUTHOR: Duane Wessels @@ -644,7 +644,7 @@ h.qr = 0; h.rd = 1; h.opcode = 0; /* QUERY */ - h.qdcount = 1; + h.qdcount = (unsigned int) 1; offset += rfc1035HeaderPack(buf + offset, sz - offset, &h); offset += rfc1035QuestionPack(buf + offset, sz - offset, @@ -660,32 +660,6 @@ return offset; } -ssize_t -rfc1035BuildAAAAQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, rfc1035_query * query) -{ - static rfc1035_message h; - size_t offset = 0; - memset(&h, '\0', sizeof(h)); - h.id = qid; - h.qr = 0; - h.rd = 1; - h.opcode = 0; /* QUERY */ - h.qdcount = 1; - offset += rfc1035HeaderPack(buf + offset, sz - offset, &h); - offset += rfc1035QuestionPack(buf + offset, - sz - offset, - hostname, - RFC1035_TYPE_AAAA, - RFC1035_CLASS_IN); - if (query) { - query->qtype = RFC1035_TYPE_AAAA; - query->qclass = RFC1035_CLASS_IN; - xstrncpy(query->name, hostname, sizeof(query->name)); - } - assert(offset <= sz); - return offset; -} - /* * rfc1035BuildPTRQuery() * @@ -697,45 +671,19 @@ * Returns the size of the query */ ssize_t -rfc1035BuildPTRQuery(const struct sockaddr *addr, char *buf, size_t sz, unsigned short qid, rfc1035_query * query) +rfc1035BuildPTRQuery(const struct in_addr addr, char *buf, size_t sz, unsigned short qid, rfc1035_query * query) { static rfc1035_message h; size_t offset = 0; - static char rev[100]; + static char rev[32]; unsigned int i; memset(&h, '\0', sizeof(h)); - memset(rev, '\0', sizeof(rev)); - if (addr->sa_family == AF_INET) { - i = (unsigned int) ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr); + i = (unsigned int) ntohl(addr.s_addr); snprintf(rev, 32, "%u.%u.%u.%u.in-addr.arpa.", i & 255, (i >> 8) & 255, (i >> 16) & 255, (i >> 24) & 255); - } - if (addr->sa_family == AF_INET6) { - char temp[16]; - int sx, ex; - u_int8_t ci; -#if BYTE_ORDER == BIG_ENDIAN - sx = 0; -#elif BYTE_ORDER == LITTLE_ENDIAN - sx = 15; -#endif - for (i = 0; i < 16; i++) { - ci = ((struct sockaddr_in6 *)addr)->sin6_addr.s6_addr[sx]; - memset(temp, '\0', sizeof(temp)); - sprintf(temp, "%x.%x", ci & 0xf, ci & 0xf0); - strcat(rev, temp); -#if BYTE_ORDER == BIG_ENDIAN - sx++; -#elif BYTE_ORDER == LITTLE_ENDIAN - sx--; -#endif - - } - strcat(rev, ".ip6.arpa"); - } h.id = qid; h.qr = 0; h.rd = 1; Index: squid/lib/safe_inet_addr.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/safe_inet_addr.c,v retrieving revision 1.2.6.6 retrieving revision 1.2.6.7 diff -u -r1.2.6.6 -r1.2.6.7 --- squid/lib/safe_inet_addr.c 1 Jul 2007 05:46:09 -0000 1.2.6.6 +++ squid/lib/safe_inet_addr.c 2 Jul 2007 07:36:51 -0000 1.2.6.7 @@ -1,6 +1,6 @@ /* - * $Id: safe_inet_addr.c,v 1.2.6.6 2007/07/01 05:46:09 amosjeffries Exp $ + * $Id: safe_inet_addr.c,v 1.2.6.7 2007/07/02 07:36:51 amosjeffries Exp $ */ #include "config.h" @@ -24,9 +24,6 @@ #if HAVE_NETINET_IN_H #include #endif -#if HAVE_NETDB_H -#include -#endif #if HAVE_ARPA_INET_H #include #endif @@ -34,18 +31,36 @@ #include "snprintf.h" int -safe_inet_addr(const char *buf, struct sockaddr *addr) +safe_inet_addr(const char *buf, struct in_addr *addr) { - struct addrinfo hints, *res; - int error; - - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_NUMERICHOST|AI_PASSIVE; - hints.ai_family = PF_UNSPEC; - error = getaddrinfo(buf, NULL, &hints, &res); - if (error) return 0; - xmemcpy(addr, res->ai_addr, res->ai_addrlen); - freeaddrinfo(res); + static char addrbuf[32]; + int a1 = 0, a2 = 0, a3 = 0, a4 = 0; + struct in_addr A; + char x; +#if defined(_SQUID_HPUX_) + /* + * MIYOSHI Tsutomu says scanning 'buf' + * causes a bus error on hppa1.1-hp-hpux9.07, so we + * have a broad hack for all HP systems. + */ + static char buftmp[32]; + snprintf(buftmp, 32, "%s", buf); + if (sscanf(buftmp, "%d.%d.%d.%d%c", &a1, &a2, &a3, &a4, &x) != 4) +#else + if (sscanf(buf, "%d.%d.%d.%d%c", &a1, &a2, &a3, &a4, &x) != 4) +#endif + return 0; + if (a1 < 0 || a1 > 255) + return 0; + if (a2 < 0 || a2 > 255) + return 0; + if (a3 < 0 || a3 > 255) + return 0; + if (a4 < 0 || a4 > 255) + return 0; + snprintf(addrbuf, 32, "%d.%d.%d.%d", a1, a2, a3, a4); + A.s_addr = inet_addr(addrbuf); + if (addr) + addr->s_addr = A.s_addr; return 1; - } Index: squid/src/HttpRequest.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/HttpRequest.c,v retrieving revision 1.3.6.5 retrieving revision 1.3.6.6 diff -u -r1.3.6.5 -r1.3.6.6 --- squid/src/HttpRequest.c 1 Jul 2007 05:44:17 -0000 1.3.6.5 +++ squid/src/HttpRequest.c 2 Jul 2007 07:36:51 -0000 1.3.6.6 @@ -1,6 +1,6 @@ /* - * $Id: HttpRequest.c,v 1.3.6.5 2007/07/01 05:44:17 amosjeffries Exp $ + * $Id: HttpRequest.c,v 1.3.6.6 2007/07/02 07:36:51 amosjeffries Exp $ * * DEBUG: section 73 HTTP Request * AUTHOR: Duane Wessels @@ -45,8 +45,8 @@ stringReset(&req->urlpath, urlpath); req->max_forwards = -1; req->lastmod = -1; - memset(&req->client_addr, 0, sizeof(req->client_addr)); - memset(&req->my_addr, 0, sizeof(req->client_addr)); + req->client_addr = no_addr; + req->my_addr = no_addr; httpHeaderInit(&req->header, hoRequest); return req; } @@ -126,8 +126,8 @@ { assert(req && p); /* Client info */ - packerPrintf(p, "Client: %s ", sockaddr_ntoa(&req->client_addr)); - packerPrintf(p, "http_port: %s:%d", sockaddr_ntoa(&req->my_addr), req->my_port); + packerPrintf(p, "Client: %s ", inet_ntoa(req->client_addr)); + packerPrintf(p, "http_port: %s:%d", inet_ntoa(req->my_addr), req->my_port); if (req->auth_user_request && authenticateUserRequestUsername(req->auth_user_request)) packerPrintf(p, "user: %s", authenticateUserRequestUsername(req->auth_user_request)); packerPrintf(p, "\n"); Index: squid/src/access_log.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/access_log.c,v retrieving revision 1.5.2.10 retrieving revision 1.5.2.11 diff -u -r1.5.2.10 -r1.5.2.11 --- squid/src/access_log.c 1 Jul 2007 08:34:22 -0000 1.5.2.10 +++ squid/src/access_log.c 2 Jul 2007 07:36:51 -0000 1.5.2.11 @@ -1,6 +1,6 @@ /* - * $Id: access_log.c,v 1.5.2.10 2007/07/01 08:34:22 amosjeffries Exp $ + * $Id: access_log.c,v 1.5.2.11 2007/07/02 07:36:51 amosjeffries Exp $ * * DEBUG: section 46 Access Log * AUTHOR: Duane Wessels @@ -449,7 +449,6 @@ long int outint = 0; int doint = 0; int dofree = 0; - char caddr[80]; switch (fmt->type) { case LFT_NONE: out = ""; @@ -458,18 +457,13 @@ out = fmt->data.string; break; case LFT_CLIENT_IP_ADDRESS: - getnameinfo((struct sockaddr *)&al->cache.caddr, SOCKLEN(&al->cache.caddr), caddr, 80, - (char *)NULL, 0, NI_NUMERICHOST); - out = caddr; + out = inet_ntoa(al->cache.caddr); break; case LFT_CLIENT_FQDN: - out = fqdncache_gethostbyaddr((struct sockaddr *)&al->cache.caddr, FQDN_LOOKUP_IF_MISS); - if (!out) { - getnameinfo((struct sockaddr *)&al->cache.caddr, SOCKLEN(&al->cache.caddr), caddr, 80, - (char *)NULL, 0, NI_NUMERICHOST); - out = caddr; - } + out = fqdncache_gethostbyaddr(al->cache.caddr, FQDN_LOOKUP_IF_MISS); + if (!out) + out = inet_ntoa(al->cache.caddr); break; case LFT_CLIENT_PORT: @@ -485,18 +479,14 @@ out = al->hier.host; break; case LFT_OUTGOING_IP: - out = xstrdup(sockaddr_ntoa(&al->cache.out_ip)); + out = xstrdup(inet_ntoa(al->cache.out_ip)); break; /* case LFT_SERVER_PORT: */ case LFT_LOCAL_IP: - if (al->request) { - getnameinfo((struct sockaddr *)&al->request->my_addr, - SOCKLEN(&al->request->my_addr), - caddr, 80, (char *)NULL, 0, NI_NUMERICHOST); - out = caddr; - } + if (al->request) + out = inet_ntoa(al->request->my_addr); break; case LFT_LOCAL_PORT: @@ -1032,14 +1022,10 @@ { const char *client = NULL; const char *user = NULL; - char caddr[80]; if (Config.onoff.log_fqdn) - client = fqdncache_gethostbyaddr((struct sockaddr *)&al->cache.caddr, FQDN_LOOKUP_IF_MISS); - if (client == NULL) { - getnameinfo((struct sockaddr *)&al->cache.caddr, SOCKLEN(&al->cache.caddr), caddr, 80, - (char *)NULL, 0, NI_NUMERICHOST); - client = caddr; - } + client = fqdncache_gethostbyaddr(al->cache.caddr, FQDN_LOOKUP_IF_MISS); + if (client == NULL) + client = inet_ntoa(al->cache.caddr); user = accessLogFormatName(al->cache.authuser); if (!user) user = accessLogFormatName(al->cache.rfc931); @@ -1096,14 +1082,10 @@ { const char *client = NULL; char *user1 = NULL, *user2 = NULL; - char caddr[80]; if (Config.onoff.log_fqdn) - client = fqdncache_gethostbyaddr((struct sockaddr *)&al->cache.caddr, FQDN_LOOKUP_IF_MISS); - if (client == NULL) { - getnameinfo((struct sockaddr *)&al->cache.caddr, SOCKLEN(&al->cache.caddr), caddr, 80, - (char *)NULL, 0, NI_NUMERICHOST); - client = caddr; - } + client = fqdncache_gethostbyaddr(al->cache.caddr, 0); + if (client == NULL) + client = inet_ntoa(al->cache.caddr); user1 = accessLogFormatName(al->cache.authuser); user2 = accessLogFormatName(al->cache.rfc931); logfilePrintf(logfile, "%s %s %s [%s] \"%s %s HTTP/%d.%d\" %d %" PRINTF_OFF_T " %s:%s", Index: squid/src/acl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/acl.c,v retrieving revision 1.4.6.18 retrieving revision 1.4.6.19 diff -u -r1.4.6.18 -r1.4.6.19 --- squid/src/acl.c 1 Jul 2007 08:34:23 -0000 1.4.6.18 +++ squid/src/acl.c 2 Jul 2007 07:36:51 -0000 1.4.6.19 @@ -1,6 +1,6 @@ /* - * $Id: acl.c,v 1.4.6.18 2007/07/01 08:34:23 amosjeffries Exp $ + * $Id: acl.c,v 1.4.6.19 2007/07/02 07:36:51 amosjeffries Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -53,18 +53,18 @@ static int aclMatchAcl(struct _acl *, aclCheck_t *); static int aclMatchTime(acl_time_data * data, time_t when); static int aclMatchUser(void *proxyauth_acl, char *user); -static int aclMatchIp(void *dataptr, struct sockaddr *c); +static int aclMatchIp(void *dataptr, struct in_addr c); static int aclMatchDomainList(void *dataptr, const char *); static int aclMatchIntegerRange(intrange * data, int i); static int aclMatchWordList(wordlist *, const char *); static void aclParseUserMaxIP(void *data); static void aclDestroyUserMaxIP(void *data); static wordlist *aclDumpUserMaxIP(void *data); -static int aclMatchUserMaxIP(void *, auth_user_request_t *, struct sockaddr *); +static int aclMatchUserMaxIP(void *, auth_user_request_t *, struct in_addr); static void aclParseHeader(void *data); static void aclDestroyHeader(void *data); static squid_acl aclStrToType(const char *s); -static int decode_addr(const char *, struct sockaddr *); +static int decode_addr(const char *, struct in_addr *); static void aclCheck(aclCheck_t * checklist); static void aclCheckCallback(aclCheck_t * checklist, allow_t answer); #if USE_IDENT @@ -431,31 +431,35 @@ * This function should NOT be called if 'asc' is a hostname! */ static int -decode_addr(const char *asc, struct sockaddr *addr) +decode_addr(const char *asc, struct in_addr *addr) { - struct addrinfo hints, *res; - int error; + int a1 = 0, a2 = 0, a3 = 0, a4 = 0; - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_flags = AI_NUMERICHOST|AI_PASSIVE; - - error = getaddrinfo(asc, NULL, &hints, &res); - if (error) { + switch (sscanf(asc, "%d.%d.%d.%d", &a1, &a2, &a3, &a4)) { + case 4: /* a dotted quad */ + if (!safe_inet_addr(asc, addr)) { + debug(28, 0) ("decode_addr: unsafe IP address: '%s'\n", asc); + self_destruct(); + } + break; + case 1: /* a significant bits value for a mask */ + if (a1 >= 0 && a1 < 33) { + addr->s_addr = a1 ? htonl(0xfffffffful << (32 - a1)) : 0; + break; + } + default: debug(28, 0) ("decode_addr: Invalid IP address '%s'\n", asc); return 0; /* This is not valid address */ } - xmemcpy(addr, res->ai_addr, SOCKLEN(res->ai_addr)); - freeaddrinfo(res); return 1; } -#define SCAN_ACL1 "%[0123456789abcdef:.]-%[0123456789abcdef:.]/%[0123456789]" -#define SCAN_ACL2 "%[0123456789abcdef:.]-%[0123456789abcdef:.]%c" -#define SCAN_ACL3 "%[0123456789abcdef:.]/%[0123456789]" -#define SCAN_ACL4 "%[0123456789abcdef:.]%c" +#define SCAN_ACL1 "%[0123456789.]-%[0123456789.]/%[0123456789.]" +#define SCAN_ACL2 "%[0123456789.]-%[0123456789.]%c" +#define SCAN_ACL3 "%[0123456789.]/%[0123456789.]" +#define SCAN_ACL4 "%[0123456789.]%c" static acl_ip_data * aclParseIpData(const char *t) @@ -464,14 +468,19 @@ LOCAL_ARRAY(char, addr2, 256); LOCAL_ARRAY(char, mask, 256); acl_ip_data *q = memAllocate(MEM_ACL_IP_DATA); + acl_ip_data *r; + acl_ip_data **Q; + struct hostent *hp; + char **x; char c; debug(28, 5) ("aclParseIpData: %s\n", t); if (!strcasecmp(t, "all")) { - q->addr1.ss_family = 0; - q->addr2.ss_family = 0; - q->masklen = 0; + q->addr1.s_addr = 0; + q->addr2.s_addr = 0; + q->mask.s_addr = 0; return q; } + q->mask.s_addr = no_addr.s_addr; /* 255.255.255.255 */ if (sscanf(t, SCAN_ACL1, addr1, addr2, mask) == 3) { (void) 0; } else if (sscanf(t, SCAN_ACL2, addr1, addr2, &c) == 2) { @@ -480,21 +489,29 @@ addr2[0] = '\0'; } else if (sscanf(t, SCAN_ACL4, addr1, &c) == 1) { addr2[0] = '\0'; - strcpy(mask, "-1"); + mask[0] = '\0'; } else if (sscanf(t, "%[^/]/%s", addr1, mask) == 2) { addr2[0] = '\0'; } else if (sscanf(t, "%s", addr1) == 1) { - struct addrinfo hints, *res; - memset(&hints, '\0', sizeof(hints)); - hints.ai_family = PF_UNSPEC; - if (getaddrinfo(t, NULL, &hints, &res)) { + /* + * Note, must use plain gethostbyname() here because at startup + * ipcache hasn't been initialized + */ + if ((hp = gethostbyname(addr1)) == NULL) { debug(28, 0) ("aclParseIpData: Bad host/IP: '%s'\n", t); safe_free(q); return NULL; } - xmemcpy(&q->addr1, res->ai_addr, res->ai_addrlen); - q->masklen = (res->ai_family == AF_INET6) ? 128 : 32; - freeaddrinfo(res); + Q = &q; + for (x = hp->h_addr_list; x != NULL && *x != NULL; x++) { + if ((r = *Q) == NULL) + r = *Q = memAllocate(MEM_ACL_IP_DATA); + xmemcpy(&r->addr1.s_addr, *x, sizeof(r->addr1.s_addr)); + r->addr2.s_addr = 0; + r->mask.s_addr = no_addr.s_addr; /* 255.255.255.255 */ + Q = &r->next; + debug(28, 3) ("%s --> %s\n", addr1, inet_ntoa(r->addr1)); + } return q; } else { debug(28, 0) ("aclParseIpData: Bad host/IP: '%s'\n", t); @@ -502,7 +519,7 @@ return NULL; } /* Decode addr1 */ - if (!decode_addr(addr1, (struct sockaddr *)&q->addr1)) { + if (!decode_addr(addr1, &q->addr1)) { debug(28, 0) ("%s line %d: %s\n", cfg_filename, config_lineno, config_input_line); debug(28, 0) ("aclParseIpData: Ignoring invalid IP acl entry: unknown first address '%s'\n", addr1); @@ -510,7 +527,7 @@ return NULL; } /* Decode addr2 */ - if (*addr2 && !decode_addr(addr2, (struct sockaddr *)&q->addr2)) { + if (*addr2 && !decode_addr(addr2, &q->addr2)) { debug(28, 0) ("%s line %d: %s\n", cfg_filename, config_lineno, config_input_line); debug(28, 0) ("aclParseIpData: Ignoring invalid IP acl entry: unknown second address '%s'\n", addr2); @@ -518,30 +535,19 @@ return NULL; } /* Decode mask */ - if (*mask) { - q->masklen = atoi(mask); - switch (q->addr1.ss_family) { - case AF_INET: - if (q->masklen == -1) - q->masklen = 32; - if (q->masklen > 32) - q->masklen = -1; - break; - case AF_INET6: - if (q->masklen == -1) - q->masklen = 128; - if (q->masklen > 128) - q->masklen = -1; - break; - } - if (*mask && (q->masklen == -1)) { - debug(28, 0) ("%s line %d: %s\n", + if (*mask && !decode_addr(mask, &q->mask)) { + debug(28, 0) ("%s line %d: %s\n", cfg_filename, config_lineno, config_input_line); - debug(28, 0) ("aclParseIpData: Ignoring invalid IP acl entry: unknown masklen'%s'\n", mask); - safe_free(q); - return NULL; - } + debug(28, 0) ("aclParseIpData: Ignoring invalid IP acl entry: unknown netmask '%s'\n", mask); + safe_free(q); + return NULL; } + if ((q->addr1.s_addr & q->mask.s_addr) != q->addr1.s_addr || + (q->addr2.s_addr & q->mask.s_addr) != q->addr2.s_addr) + debug(28, 0) ("aclParseIpData: WARNING: Netmask masks away part of the specified IP in '%s'\n", t); + q->addr1.s_addr &= q->mask.s_addr; + q->addr2.s_addr &= q->mask.s_addr; + /* 1.2.3.4/255.255.255.0 --> 1.2.3.0 */ return q; } @@ -1289,7 +1295,7 @@ /**************/ static int -aclMatchIp(void *dataptr, struct sockaddr *c) +aclMatchIp(void *dataptr, struct in_addr c) { splayNode **Top = dataptr; acl_ip_data x; @@ -1302,12 +1308,13 @@ * XXX Could eliminate these repetitive assignments with a * static structure. */ - xmemcpy(&x.addr1, c, SOCKLEN(c)); - x.masklen = 0; + x.addr1 = c; + x.addr2 = any_addr; + x.mask = no_addr; x.next = NULL; *Top = splay_splay(&x, *Top, aclIpAddrNetworkCompare); debug(28, 3) ("aclMatchIp: '%s' %s\n", - sockaddr_ntoa(c), splayLastResult ? "NOT found" : "found"); + inet_ntoa(c), splayLastResult ? "NOT found" : "found"); return !splayLastResult; } @@ -1542,7 +1549,7 @@ */ int aclMatchUserMaxIP(void *data, auth_user_request_t * auth_user_request, - struct sockaddr *src_addr) + struct in_addr src_addr) { /* * the logic for flush the ip list when the limit is hit vs keep @@ -1707,7 +1714,7 @@ } /* get authed here */ /* Note: this fills in checklist->auth_user_request when applicable (auth incomplete) */ - switch (authenticateTryToAuthenticateAndSetAuthUser(&checklist->auth_user_request, headertype, checklist->request, checklist->conn, (struct sockaddr *)&checklist->src_addr)) { + switch (authenticateTryToAuthenticateAndSetAuthUser(&checklist->auth_user_request, headertype, checklist->request, checklist->conn, checklist->src_addr)) { case AUTH_ACL_CANNOT_AUTHENTICATE: debug(28, 4) ("aclMatchAcl: returning 0 user authenticated but not authorised.\n"); return 0; @@ -1778,16 +1785,16 @@ debug(28, 3) ("aclMatchAcl: checking '%s'\n", ae->cfgline); switch (ae->type) { case ACL_SRC_IP: - return aclMatchIp(&ae->data, (struct sockaddr *)&checklist->src_addr); + return aclMatchIp(&ae->data, checklist->src_addr); /* NOTREACHED */ case ACL_MY_IP: - return aclMatchIp(&ae->data, (struct sockaddr *)&checklist->my_addr); + return aclMatchIp(&ae->data, checklist->my_addr); /* NOTREACHED */ case ACL_DST_IP: ia = ipcache_gethostbyname(r->host, IP_LOOKUP_IF_MISS); if (ia) { for (k = 0; k < (int) ia->count; k++) { - if (aclMatchIp(&ae->data, (struct sockaddr *)&ia->in_addrs[k])) + if (aclMatchIp(&ae->data, ia->in_addrs[k])) return 1; } return 0; @@ -1805,24 +1812,24 @@ return 1; if ((ia = ipcacheCheckNumeric(r->host)) == NULL) return 0; - fqdn = fqdncache_gethostbyaddr((struct sockaddr *)&ia->in_addrs[0], FQDN_LOOKUP_IF_MISS); + fqdn = fqdncache_gethostbyaddr(ia->in_addrs[0], FQDN_LOOKUP_IF_MISS); if (fqdn) return aclMatchDomainList(&ae->data, fqdn); if (checklist->state[ACL_DST_DOMAIN] == ACL_LOOKUP_NONE) { debug(28, 3) ("aclMatchAcl: Can't yet compare '%s' ACL for '%s'\n", - ae->name, sockaddr_ntoa(&ia->in_addrs[0])); + ae->name, inet_ntoa(ia->in_addrs[0])); checklist->state[ACL_DST_DOMAIN] = ACL_LOOKUP_NEEDED; return 0; } return aclMatchDomainList(&ae->data, "none"); /* NOTREACHED */ case ACL_SRC_DOMAIN: - fqdn = fqdncache_gethostbyaddr((struct sockaddr *)&checklist->src_addr, FQDN_LOOKUP_IF_MISS); + fqdn = fqdncache_gethostbyaddr(checklist->src_addr, FQDN_LOOKUP_IF_MISS); if (fqdn) { return aclMatchDomainList(&ae->data, fqdn); } else if (checklist->state[ACL_SRC_DOMAIN] == ACL_LOOKUP_NONE) { debug(28, 3) ("aclMatchAcl: Can't yet compare '%s' ACL for '%s'\n", - ae->name, ""); /*XXX inet_ntoa(checklist->src_addr)); */ + ae->name, inet_ntoa(checklist->src_addr)); checklist->state[ACL_SRC_DOMAIN] = ACL_LOOKUP_NEEDED; return 0; } @@ -1833,24 +1840,24 @@ return 1; if ((ia = ipcacheCheckNumeric(r->host)) == NULL) return 0; - fqdn = fqdncache_gethostbyaddr((struct sockaddr *)&ia->in_addrs[0], FQDN_LOOKUP_IF_MISS); + fqdn = fqdncache_gethostbyaddr(ia->in_addrs[0], FQDN_LOOKUP_IF_MISS); if (fqdn) return aclMatchRegex(ae->data, fqdn); if (checklist->state[ACL_DST_DOMAIN] == ACL_LOOKUP_NONE) { debug(28, 3) ("aclMatchAcl: Can't yet compare '%s' ACL for '%s'\n", - ae->name, sockaddr_ntoa(&ia->in_addrs[0])); + ae->name, inet_ntoa(ia->in_addrs[0])); checklist->state[ACL_DST_DOMAIN] = ACL_LOOKUP_NEEDED; return 0; } return aclMatchRegex(ae->data, "none"); /* NOTREACHED */ case ACL_SRC_DOM_REGEX: - fqdn = fqdncache_gethostbyaddr((struct sockaddr *)&checklist->src_addr, FQDN_LOOKUP_IF_MISS); + fqdn = fqdncache_gethostbyaddr(checklist->src_addr, FQDN_LOOKUP_IF_MISS); if (fqdn) { return aclMatchRegex(ae->data, fqdn); } else if (checklist->state[ACL_SRC_DOMAIN] == ACL_LOOKUP_NONE) { debug(28, 3) ("aclMatchAcl: Can't yet compare '%s' ACL for '%s'\n", - ae->name, sockaddr_ntoa(&checklist->src_addr)); + ae->name, inet_ntoa(checklist->src_addr)); checklist->state[ACL_SRC_DOMAIN] = ACL_LOOKUP_NEEDED; return 0; } @@ -1880,7 +1887,7 @@ return k; /* NOTREACHED */ case ACL_MAXCONN: - k = clientdbEstablished((struct sockaddr *)&checklist->src_addr, 0); + k = clientdbEstablished(checklist->src_addr, 0); return ((k > ((intlist *) ae->data)->i) ? 1 : 0); /* NOTREACHED */ case ACL_URL_PORT: @@ -1943,7 +1950,7 @@ if ((ti = aclAuthenticated(checklist)) != 1) return ti; ti = aclMatchUserMaxIP(ae->data, r->auth_user_request, - (struct sockaddr *)&checklist->src_addr); + checklist->src_addr); return ti; /* NOTREACHED */ #if SQUID_SNMP @@ -1952,13 +1959,13 @@ /* NOTREACHED */ #endif case ACL_SRC_ASN: - return asnMatchIp(ae->data, (struct sockaddr *)&checklist->src_addr); + return asnMatchIp(ae->data, checklist->src_addr); /* NOTREACHED */ case ACL_DST_ASN: ia = ipcache_gethostbyname(r->host, IP_LOOKUP_IF_MISS); if (ia) { for (k = 0; k < (int) ia->count; k++) { - if (asnMatchIp(ae->data, (struct sockaddr *)&ia->in_addrs[k])) + if (asnMatchIp(ae->data, ia->in_addrs[k])) return 1; } return 0; @@ -1967,13 +1974,13 @@ ae->name, r->host); checklist->state[ACL_DST_ASN] = ACL_LOOKUP_NEEDED; } else { - return asnMatchIp(ae->data, (struct sockaddr *)&no_addr); + return asnMatchIp(ae->data, no_addr); } return 0; /* NOTREACHED */ #if USE_ARP_ACL case ACL_SRC_ARP: - return aclMatchArp(&ae->data, (struct sockaddr *)&checklist->src_addr); + return aclMatchArp(&ae->data, checklist->src_addr); /* NOTREACHED */ #endif case ACL_REQ_MIME_TYPE: @@ -2169,7 +2176,7 @@ return; } else if (checklist->state[ACL_SRC_DOMAIN] == ACL_LOOKUP_NEEDED) { checklist->state[ACL_SRC_DOMAIN] = ACL_LOOKUP_PENDING; - fqdncache_nbgethostbyaddr((struct sockaddr *)&checklist->src_addr, + fqdncache_nbgethostbyaddr(checklist->src_addr, aclLookupSrcFQDNDone, checklist); return; } else if (checklist->state[ACL_DST_DOMAIN] == ACL_LOOKUP_NEEDED) { @@ -2180,7 +2187,7 @@ } checklist->dst_addr = ia->in_addrs[0]; checklist->state[ACL_DST_DOMAIN] = ACL_LOOKUP_PENDING; - fqdncache_nbgethostbyaddr((struct sockaddr *)&checklist->dst_addr, + fqdncache_nbgethostbyaddr(checklist->dst_addr, aclLookupDstFQDNDone, checklist); return; } else if (checklist->state[ACL_PROXY_AUTH] == ACL_LOOKUP_NEEDED) { @@ -2202,7 +2209,7 @@ else if (checklist->state[ACL_IDENT] == ACL_LOOKUP_NEEDED) { debug(28, 3) ("aclCheck: Doing ident lookup\n"); if (cbdataValid(checklist->conn)) { - identStart((struct sockaddr *)&checklist->conn->me, (struct sockaddr *)&checklist->conn->peer, + identStart(&checklist->conn->me, &checklist->conn->peer, aclLookupIdentDone, checklist); checklist->state[ACL_IDENT] = ACL_LOOKUP_PENDING; return; @@ -2374,17 +2381,7 @@ aclChecklistCacheInit(aclCheck_t * checklist) { request_t *request = checklist->request; - struct sockaddr *A = (struct sockaddr*)&checklist->src_addr; - if( request != NULL && - ( - ( (checklist->src_addr.ss_family == AF_INET6) - && IN6_IS_ADDR_UNSPECIFIED( &((struct sockaddr_in6 *)A)->sin6_addr ) - ) || - ( (checklist->src_addr.ss_family == AF_INET) - && (((struct sockaddr_in *)A)->sin_addr.s_addr == 0) - ) - ) - ) { + if (request != NULL && checklist->src_addr.s_addr == 0) { #if FOLLOW_X_FORWARDED_FOR if (Config.onoff.acl_uses_indirect_client) { checklist->src_addr = request->indirect_client_addr; @@ -2696,7 +2693,19 @@ static void aclIpDataToStr(const acl_ip_data * ip, char *buf, int len) { - snprintf(buf, len, "%s/%d", sockaddr_ntoa(&ip->addr1), ip->masklen); + char b1[20]; + char b2[20]; + char b3[20]; + snprintf(b1, 20, "%s", inet_ntoa(ip->addr1)); + if (ip->addr2.s_addr != any_addr.s_addr) + snprintf(b2, 20, "-%s", inet_ntoa(ip->addr2)); + else + b2[0] = '\0'; + if (ip->mask.s_addr != no_addr.s_addr) + snprintf(b3, 20, "/%s", inet_ntoa(ip->mask)); + else + b3[0] = '\0'; + snprintf(buf, len, "%s%s%s", b1, b2, b3); } /* @@ -2709,77 +2718,27 @@ static int aclIpNetworkCompare2(const acl_ip_data * p, const acl_ip_data * q) { - if (q->addr1.ss_family < p->addr1.ss_family) - return -1; - else - if (q->addr1.ss_family > p->addr1.ss_family) - return 1; - else - if (q->addr1.ss_family == AF_INET) { - u_int32_t maskedup_B; - u_int32_t A = ntohl(((struct sockaddr_in *)&p->addr1)->sin_addr.s_addr); - u_int32_t B = ntohl(((struct sockaddr_in *)&q->addr1)->sin_addr.s_addr); - - if (q->masklen == 0) - return 0; - - maskedup_B = ((B >> (32 - q->masklen)) + 1) << (32 - q->masklen); - maskedup_B--; - - if (A < B) - return -1; - else if (A > maskedup_B) - return 1; + struct in_addr A = p->addr1; + const struct in_addr B = q->addr1; + const struct in_addr C = q->addr2; + int rc = 0; + A.s_addr &= q->mask.s_addr; /* apply netmask */ + if (C.s_addr == 0) { /* single address check */ + if (ntohl(A.s_addr) > ntohl(B.s_addr)) + rc = 1; + else if (ntohl(A.s_addr) < ntohl(B.s_addr)) + rc = -1; else - return 0; - } - else - if (q->addr1.ss_family == AF_INET6) { - - int masklen, invmasklen, i, rc; - struct in6_addr A, B; - - if (q->masklen == 0) - return 0; - - xmemcpy(&A, &((struct sockaddr_in6 *)&p->addr1)->sin6_addr, sizeof(struct in6_addr)); - xmemcpy(&B, &((struct sockaddr_in6 *)&q->addr1)->sin6_addr, sizeof(struct in6_addr)); - - invmasklen = 128 - q->masklen; - masklen = q->masklen; - - rc = 0; - for (i = 0; i < 16; i=i+4) { - if (masklen >= 32) { - if (IN6_NTOHL_N(&A, i) < IN6_NTOHL_N(&B, i)) - return -1; - else - if (IN6_NTOHL_N(&A, i) > IN6_NTOHL_N(&B, i)) - return 1; - else - masklen = masklen - 32; - } - else if (masklen > 0) { - invmasklen = 32 - masklen; - debug(28, 3) ("aclIpNetworkCompare2: %s vs %s,\n", - sockaddr_ntoa(&p->addr1), sockaddr_ntoa(&q->addr1)); - debug(28, 3) ("aclIpNetworkCompare2: %x/%d (%x) vs %x\n", - IN6_NTOHL_N(&A, i), masklen, - IN6_NTOHL_N(&A, i) & (0xffffffff << invmasklen), - IN6_NTOHL_N(&B, i)); - if (IN6_NTOHL_N(&A, i) < IN6_NTOHL_N(&B, i)) - return -1; - else - if ((IN6_NTOHL_N(&A, i) & (0xffffffff << invmasklen)) > IN6_NTOHL_N(&B, i)) - return 1; - else - return 0; - } - } + rc = 0; + } else { /* range address check */ + if (ntohl(A.s_addr) > ntohl(C.s_addr)) + rc = 1; + else if (ntohl(A.s_addr) < ntohl(B.s_addr)) + rc = -1; + else + rc = 0; } - else - return 0; - return 0; + return rc; } /* @@ -2803,14 +2762,16 @@ ret = aclIpNetworkCompare2(n1, n2); } if (ret == 0) { - char buf_n1[100]; - char buf_n2[100]; - getnameinfo((struct sockaddr *)&n1->addr1, SOCKLEN(&n1->addr1), buf_n1, 100, NULL, 0, NI_NUMERICHOST); - getnameinfo((struct sockaddr *)&n2->addr1, SOCKLEN(&n2->addr1), buf_n2, 100, NULL, 0, NI_NUMERICHOST); + char buf_n1[60]; + char buf_n2[60]; + char buf_a[60]; + aclIpDataToStr(n1, buf_n1, 60); + aclIpDataToStr(n2, buf_n2, 60); + aclIpDataToStr((acl_ip_data *) a, buf_a, 60); debug(28, 0) ("WARNING: '%s' is a subnetwork of " "'%s'\n", buf_n1, buf_n2); debug(28, 0) ("WARNING: because of this '%s' is ignored " - "to keep splay tree searching predictable\n", buf_n1); + "to keep splay tree searching predictable\n", buf_a); debug(28, 0) ("WARNING: You should probably remove '%s' " "from the ACL named '%s'\n", buf_n1, AclMatchedName); } @@ -2861,12 +2822,11 @@ MemBuf mb; wordlist **W = state; memBufDefInit(&mb); - memBufPrintf(&mb, "%s", sockaddr_ntoa(&ip->addr1)); -/* + memBufPrintf(&mb, "%s", inet_ntoa(ip->addr1)); if (ip->addr2.s_addr != any_addr.s_addr) - memBufPrintf(&mb, "-%s", sockaddr_ntoa(&ip->addr2)); -*/ - memBufPrintf(&mb, "/%d", ip->masklen); + memBufPrintf(&mb, "-%s", inet_ntoa(ip->addr2)); + if (ip->mask.s_addr != no_addr.s_addr) + memBufPrintf(&mb, "/%s", inet_ntoa(ip->mask)); wordlistAdd(W, mb.buf); memBufClean(&mb); } @@ -3273,7 +3233,7 @@ /* Do lookup */ *Top = splay_splay(&arpReq.arp_ha.sa_data, *Top, aclArpCompare); debug(28, 3) ("aclMatchArp: '%s' %s\n", - sockaddr_ntoa(c), splayLastResult ? "NOT found" : "found"); + inet_ntoa(c), splayLastResult ? "NOT found" : "found"); return (0 == splayLastResult); } /* lookup list of interface names */ Index: squid/src/asn.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/asn.c,v retrieving revision 1.4.4.7 retrieving revision 1.4.4.8 diff -u -r1.4.4.7 -r1.4.4.8 --- squid/src/asn.c 1 Jul 2007 05:44:18 -0000 1.4.4.7 +++ squid/src/asn.c 2 Jul 2007 07:36:52 -0000 1.4.4.8 @@ -1,6 +1,6 @@ /* - * $Id: asn.c,v 1.4.4.7 2007/07/01 05:44:18 amosjeffries Exp $ + * $Id: asn.c,v 1.4.4.8 2007/07/02 07:36:52 amosjeffries Exp $ * * DEBUG: section 53 AS Number handling * AUTHOR: Duane Wessels, Kostas Anagnostakis @@ -103,7 +103,7 @@ /* PUBLIC */ int -asnMatchIp(void *data, struct sockaddr *saddr) +asnMatchIp(void *data, struct in_addr addr) { unsigned long lh; struct squid_radix_node *rn; @@ -111,10 +111,6 @@ m_int m_addr; intlist *a = NULL; intlist *b = NULL; - struct in_addr addr = ((struct sockaddr_in *)saddr)->sin_addr; - - if (saddr->sa_family == AF_INET6) - return 1; lh = ntohl(addr.s_addr); debug(53, 3) ("asnMatchIp: Called for %s.\n", inet_ntoa(addr)); Index: squid/src/authenticate.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/authenticate.c,v retrieving revision 1.4.6.10 retrieving revision 1.4.6.11 diff -u -r1.4.6.10 -r1.4.6.11 --- squid/src/authenticate.c 1 Jul 2007 05:44:18 -0000 1.4.6.10 +++ squid/src/authenticate.c 2 Jul 2007 07:36:52 -0000 1.4.6.11 @@ -1,6 +1,6 @@ /* - * $Id: authenticate.c,v 1.4.6.10 2007/07/01 05:44:18 amosjeffries Exp $ + * $Id: authenticate.c,v 1.4.6.11 2007/07/02 07:36:52 amosjeffries Exp $ * * DEBUG: section 29 Authenticator * AUTHOR: Duane Wessels @@ -43,7 +43,7 @@ CBDATA_TYPE(auth_user_ip_t); static void authenticateDecodeAuth(const char *proxy_auth, auth_user_request_t * auth_user_request); -static auth_acl_t authenticateAuthenticate(auth_user_request_t ** auth_user_request, http_hdr_type headertype, request_t * request, ConnStateData * conn, struct sockaddr *src_addr); +static auth_acl_t authenticateAuthenticate(auth_user_request_t ** auth_user_request, http_hdr_type headertype, request_t * request, ConnStateData * conn, struct in_addr src_addr); /* * @@ -259,10 +259,11 @@ } static void -authenticateAuthUserRequestSetIp(auth_user_request_t * auth_user_request, struct sockaddr *ipaddr) +authenticateAuthUserRequestSetIp(auth_user_request_t * auth_user_request, struct in_addr ipaddr) { auth_user_ip_t *ipdata, *next; auth_user_t *auth_user; + char *ip1; int found = 0; CBDATA_INIT_TYPE(auth_user_ip_t); if (!auth_user_request->auth_user) @@ -277,7 +278,7 @@ while ((ipdata = next) != NULL) { next = (auth_user_ip_t *) ipdata->node.next; /* walk the ip list */ - if (!memcmp(&ipdata->ipaddr, ipaddr, SOCKLEN(ipaddr))) { + if (ipdata->ipaddr.s_addr == ipaddr.s_addr) { /* This ip has already been seen. */ found = 1; /* update IP ttl */ @@ -294,15 +295,17 @@ /* This ip is not in the seen list */ ipdata = cbdataAlloc(auth_user_ip_t); ipdata->ip_expiretime = squid_curtime; - xmemcpy(&ipdata->ipaddr, ipaddr, SOCKLEN(ipaddr)); + ipdata->ipaddr = ipaddr; dlinkAddTail(ipdata, &ipdata->node, &auth_user->ip_list); auth_user->ipcount++; - debug(29, 2) ("authenticateAuthUserRequestSetIp: user '%s' has been seen at a new IP address (%s)\n", authenticateUserUsername(auth_user), sockaddr_ntoa(ipaddr)); + ip1 = xstrdup(inet_ntoa(ipaddr)); + debug(29, 2) ("authenticateAuthUserRequestSetIp: user '%s' has been seen at a new IP address (%s)\n", authenticateUserUsername(auth_user), ip1); + safe_free(ip1); } void -authenticateAuthUserRequestRemoveIp(auth_user_request_t * auth_user_request, struct sockaddr *ipaddr) +authenticateAuthUserRequestRemoveIp(auth_user_request_t * auth_user_request, struct in_addr ipaddr) { auth_user_ip_t *ipdata; auth_user_t *auth_user; @@ -312,7 +315,7 @@ ipdata = (auth_user_ip_t *) auth_user->ip_list.head; while (ipdata) { /* walk the ip list */ - if (!memcmp(&ipdata->ipaddr, ipaddr, SOCKLEN(ipaddr))) { + if (ipdata->ipaddr.s_addr == ipaddr.s_addr) { authenticateAuthUserRemoveIpEntry(auth_user, ipdata); return; } @@ -431,7 +434,7 @@ * the authenticateStart routine for rv==AUTH_ACL_HELPER */ auth_acl_t -authenticateAuthenticate(auth_user_request_t ** auth_user_request, http_hdr_type headertype, request_t * request, ConnStateData * conn, struct sockaddr *src_addr) +authenticateAuthenticate(auth_user_request_t ** auth_user_request, http_hdr_type headertype, request_t * request, ConnStateData * conn, struct in_addr src_addr) { const char *proxy_auth; assert(headertype != 0); @@ -497,8 +500,8 @@ if (proxy_auth && !request->auth_user_request && conn && conn->auth_user_request) { int id = authenticateAuthSchemeId(proxy_auth) + 1; if (!conn->auth_user_request->auth_user || conn->auth_user_request->auth_user->auth_module != id) { - debug(29, 1) ("authenticateAuthenticate: Unexpected change of authentication scheme from '%s' to '%s'", /* (client %s)\n",*/ - authscheme_list[conn->auth_user_request->auth_user->auth_module - 1].typestr, proxy_auth/*, inet_ntoa(src_addr)*/); /* XXX husni */ + debug(29, 1) ("authenticateAuthenticate: Unexpected change of authentication scheme from '%s' to '%s' (client %s)\n", + authscheme_list[conn->auth_user_request->auth_user->auth_module - 1].typestr, proxy_auth, inet_ntoa(src_addr)); authenticateAuthUserRequestUnlock(conn->auth_user_request); conn->auth_user_request = NULL; conn->auth_type = AUTH_UNKNOWN; @@ -599,7 +602,7 @@ } auth_acl_t -authenticateTryToAuthenticateAndSetAuthUser(auth_user_request_t ** auth_user_request, http_hdr_type headertype, request_t * request, ConnStateData * conn, struct sockaddr *src_addr) +authenticateTryToAuthenticateAndSetAuthUser(auth_user_request_t ** auth_user_request, http_hdr_type headertype, request_t * request, ConnStateData * conn, struct in_addr src_addr) { /* If we have already been called, return the cached value */ auth_user_request_t *t = authTryGetUser(auth_user_request, conn, request); Index: squid/src/cache_cf.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cache_cf.c,v retrieving revision 1.4.2.13 retrieving revision 1.4.2.14 diff -u -r1.4.2.13 -r1.4.2.14 --- squid/src/cache_cf.c 1 Jul 2007 08:34:23 -0000 1.4.2.13 +++ squid/src/cache_cf.c 2 Jul 2007 07:36:52 -0000 1.4.2.14 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.c,v 1.4.2.13 2007/07/01 08:34:23 amosjeffries Exp $ + * $Id: cache_cf.c,v 1.4.2.14 2007/07/02 07:36:52 amosjeffries Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -80,7 +80,6 @@ }; -static void cbdataFree_http_port(void *data); static void update_maxobjsize(void); static void configDoConfigure(void); static void parse_refreshpattern(refresh_t **); @@ -108,11 +107,11 @@ static void dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var); static void free_denyinfo(acl_deny_info_list ** var); #if USE_WCCPv2 -static void parse_sockaddr_storage_list(sockaddr_storage_list **); -static void dump_sockaddr_storage_list(StoreEntry *, const char *, const sockaddr_storage_list *); -static void free_sockaddr_storage_list(sockaddr_storage_list **); +static void parse_sockaddr_in_list(sockaddr_in_list **); +static void dump_sockaddr_in_list(StoreEntry *, const char *, const sockaddr_in_list *); +static void free_sockaddr_in_list(sockaddr_in_list **); #if UNUSED_CODE -static int check_null_sockaddr_storage_list(const sockaddr_storage_list *); +static int check_null_sockaddr_in_list(const sockaddr_in_list *); #endif #endif static void parse_http_port_list(http_port_list **); @@ -755,43 +754,31 @@ } static void -dump_address(StoreEntry * entry, const char *name, struct sockaddr *addr) +dump_address(StoreEntry * entry, const char *name, struct in_addr addr) { - storeAppendPrintf(entry, "%s %s\n", name, sockaddr_ntoa(addr)); + storeAppendPrintf(entry, "%s %s\n", name, inet_ntoa(addr)); } static void -parse_address(struct sockaddr *addr) +parse_address(struct in_addr *addr) { - struct addrinfo hints, *res, *res0; - int error; + const struct hostent *hp; char *token = strtok(NULL, w_space); if (token == NULL) self_destruct(); if (safe_inet_addr(token, addr) == 1) (void) 0; - else { - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_flags = AI_PASSIVE; - error = getaddrinfo(token, NULL, &hints, &res); - if (error) - self_destruct(); - for (res = res0; res; res = res->ai_next) { - if ((res->ai_family == AF_INET) || (res->ai_family == AF_INET6)) { - xmemcpy(addr, res->ai_addr, SOCKLEN(res->ai_addr)); - break; - } - } - freeaddrinfo(res0); - } + else if ((hp = gethostbyname(token))) /* dont use ipcache */ + *addr = inaddrFromHostent(hp); + else + self_destruct(); } static void -free_address(struct sockaddr *addr) +free_address(struct in_addr *addr) { - memset(addr, '\0', SOCKLEN(addr)); + memset(addr, '\0', sizeof(struct in_addr)); } CBDATA_TYPE(acl_address); @@ -801,8 +788,10 @@ { acl_address *l; for (l = head; l; l = l->next) { - storeAppendPrintf(entry, "%s %s", name, sockaddr_ntoa(&l->addr)); -/* storeAppendPrintf(entry, "%s autoselect", name); */ + if (l->addr.s_addr != INADDR_ANY) + storeAppendPrintf(entry, "%s %s", name, inet_ntoa(l->addr)); + else + storeAppendPrintf(entry, "%s autoselect", name); dump_acl_list(entry, l->acl_list); storeAppendPrintf(entry, "\n"); } @@ -2646,20 +2635,19 @@ #if USE_WCCPv2 static void -parse_sockaddr_storage_list(sockaddr_storage_list ** head) +parse_sockaddr_in_list(sockaddr_in_list ** head) { char *token; char *t; char *host; char *tmp; - struct addrinfo hints, *res, *res0; + const struct hostent *hp; unsigned short port = 0; - sockaddr_storage_list *s; - int error; + sockaddr_in_list *s; while ((token = strtok(NULL, w_space))) { host = NULL; port = 0; - if ((t = strrchr(token, ':'))) { + if ((t = strchr(token, ':'))) { /* host:port */ host = token; *t = '\0'; @@ -2673,27 +2661,15 @@ port = 0; } s = xcalloc(1, sizeof(*s)); - if (safe_inet_addr(token, &s->s) == 1) + s->s.sin_port = htons(port); + if (NULL == host) + s->s.sin_addr = any_addr; + else if (1 == safe_inet_addr(host, &s->s.sin_addr)) (void) 0; - else { - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_flags = AI_PASSIVE; - error = getaddrinfo(token, NULL, &hints, &res); - if (error) - self_destruct(); - for (res = res0; res; res = res->ai_next) { - if ((res->ai_family == AF_INET) || (res->ai_family == AF_INET6)) { - xmemcpy(&s->s, res->ai_addr, SOCKLEN(res->ai_addr)); - break; - } - } - freeaddrinfo(res0); - } - if (s->s.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&s->s)->sin6_port = htons(port); + else if ((hp = gethostbyname(host))) /* dont use ipcache */ + s->s.sin_addr = inaddrFromHostent(hp); else - ((struct sockaddr_in *)&s->s)->sin_port = htons(port); + self_destruct(); while (*head) head = &(*head)->next; *head = s; @@ -2701,23 +2677,21 @@ } static void -dump_sockaddr_storage_list(StoreEntry * e, const char *n, const sockaddr_storage_list * s) +dump_sockaddr_in_list(StoreEntry * e, const char *n, const sockaddr_in_list * s) { while (s) { storeAppendPrintf(e, "%s %s:%d\n", n, - sockaddr_ntoa(&s->s), - s->s.ss_family == AF_INET6 ? - ntohs(((struct sockaddr_in6 *)&s->s)->sin6_port) : - ntohs(((struct sockaddr_in *)&s->s)->sin_port)); + inet_ntoa(s->s.sin_addr), + ntohs(s->s.sin_port)); s = s->next; } } static void -free_sockaddr_storage_list(sockaddr_storage_list ** head) +free_sockaddr_in_list(sockaddr_in_list ** head) { - sockaddr_storage_list *s; + sockaddr_in_list *s; while ((s = *head) != NULL) { *head = s->next; xfree(s); @@ -2726,7 +2700,7 @@ #if UNUSED_CODE static int -check_null_sockaddr_storage_list(const sockaddr_storage_list * s) +check_null_sockaddr_in_list(const sockaddr_in_list * s) { return NULL == s; } @@ -2736,64 +2710,32 @@ static void parse_http_port_specification(http_port_list * s, char *token) { - CBDATA_TYPE(http_port_list); char *host = NULL; - char *portstr = NULL; - struct addrinfo hints, *res, *res0; - http_port_list *sn1, *sn2; - int error; + const struct hostent *hp; unsigned short port = 0; char *t; - CBDATA_INIT_TYPE_FREECB(http_port_list, cbdataFree_http_port); - if ((t = strrchr(token, ':'))) { + if ((t = strchr(token, ':'))) { /* host:port */ - port = xatos(t + 1); - portstr = t + 1; host = token; *t = '\0'; - t--; - if (*t == ']') { - *t = '\0'; - host = token+1; - } + port = xatos(t + 1); } else { /* port */ port = xatos(token); - portstr = token; } if (port == 0) self_destruct(); - - memset(&hints, 0, sizeof(hints)); - if (!host) { - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - } - error = getaddrinfo(host, portstr, &hints, &res0); - if (error) - self_destruct(); - sn1 = s; - sn2 = s; - for (res = res0; res; res = res->ai_next) { - if ((res->ai_family == AF_INET) ||(res->ai_family == AF_INET6)) { - if (!sn2) { - sn2 = cbdataAlloc(http_port_list); - sn1->next = sn2; - sn1 = sn2; - } - xmemcpy(&sn2->s, res->ai_addr, SOCKLEN(res->ai_addr)); - if (res->ai_family == AF_INET6) - ((struct sockaddr_in6 *)&sn2->s)->sin6_port = htons(port); - else - ((struct sockaddr_in *)&sn2->s)->sin_port = htons(port); - if (host) - sn2->defaultsite = xstrdup(host); - sn2 = sn2->next; - } - } - freeaddrinfo(res0); - + s->s.sin_port = htons(port); + if (NULL == host) + s->s.sin_addr = any_addr; + else if (1 == safe_inet_addr(host, &s->s.sin_addr)) + (void) 0; + else if ((hp = gethostbyname(host))) { + /* dont use ipcache */ + s->s.sin_addr = inaddrFromHostent(hp); + s->defaultsite = xstrdup(host); + } else + self_destruct(); } static void @@ -2812,9 +2754,7 @@ s->vhost = 1; s->accel = 1; } else if (strcmp(token, "vport") == 0) { - s->vport = (s->s.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&s->s)->sin6_port) : - ntohs(((struct sockaddr_in *)&s->s)->sin_port); + s->vport = ntohs(s->s.sin_port); s->accel = 1; } else if (strncmp(token, "vport=", 6) == 0) { s->vport = xatos(token + 6); @@ -2894,9 +2834,10 @@ static void dump_generic_http_port(StoreEntry * e, const char *n, const http_port_list * s) { - char host[100], port[8]; - getnameinfo((struct sockaddr *)&s->s, SOCKLEN(&s->s), host, 100, port, 8, NI_NUMERICHOST|NI_NUMERICSERV); - storeAppendPrintf(e, "%s %s:%s", n, host, port); + storeAppendPrintf(e, "%s %s:%d", + n, + inet_ntoa(s->s.sin_addr), + ntohs(s->s.sin_port)); if (s->transparent) storeAppendPrintf(e, " transparent"); if (s->accel) @@ -2905,8 +2846,7 @@ storeAppendPrintf(e, " defaultsite=%s", s->defaultsite); if (s->vhost) storeAppendPrintf(e, " vhost"); - if ( (s->s.ss_family == AF_INET6 && s->vport == ntohs(((struct sockaddr_in6 *)&s->s)->sin6_port) ) || - (s->s.ss_family == AF_INET && s->vport == ntohs(((struct sockaddr_in *)&s->s)->sin_port) ) ) + if (s->vport == ntohs(s->s.sin_port)) storeAppendPrintf(e, " vport"); else if (s->vport) storeAppendPrintf(e, " vport=%d", s->vport); Index: squid/src/cf.data.pre =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cf.data.pre,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/cf.data.pre 1 Jul 2007 05:44:18 -0000 1.4.6.8 +++ squid/src/cf.data.pre 2 Jul 2007 07:36:53 -0000 1.4.6.9 @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.4.6.8 2007/07/01 05:44:18 amosjeffries Exp $ +# $Id: cf.data.pre,v 1.4.6.9 2007/07/02 07:36:53 amosjeffries Exp $ # # SQUID Web Proxy Cache http://www.squid-cache.org/ # ---------------------------------------------------------- @@ -384,26 +384,14 @@ By default, Squid doesn't listen on any multicast groups. DOC_END -NAME: udp_incoming_address6 -TYPE: address* -LOC:Config.Addrs.udp6_incoming -DEFAULT: :: -DOC_NONE - -NAME: udp_outgoing_address6 -TYPE: address* -LOC:Config.Addrs.udp6_outgoing -DEFAULT: ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff -DOC_NONE - NAME: udp_incoming_address -TYPE: address* +TYPE: address LOC:Config.Addrs.udp_incoming DEFAULT: 0.0.0.0 DOC_NONE NAME: udp_outgoing_address -TYPE: address* +TYPE: address LOC: Config.Addrs.udp_outgoing DEFAULT: 255.255.255.255 DOC_START @@ -427,7 +415,6 @@ have the same value since they both use port 3130. DOC_END - COMMENT_START OPTIONS WHICH AFFECT THE NEIGHBOR SELECTION ALGORITHM ----------------------------------------------------------------------------- @@ -1485,20 +1472,8 @@ browsing. DOC_END -NAME: client_masklen -TYPE: int -LOC: Config.Addrs.client_masklen -DEFAULT: 32 -DOC_NONE - -NAME: client6_masklen -TYPE: int -LOC: Config.Addrs.client6_masklen -DEFAULT: 128 -DOC_NONE - NAME: client_netmask -TYPE: address* +TYPE: address LOC: Config.Addrs.client_netmask DEFAULT: 255.255.255.255 DOC_START @@ -2824,10 +2799,10 @@ NOCOMMENT_START #Recommended minimum configuration: -acl all src 0.0.0.0/0 ::/0 +acl all src 0.0.0.0/0.0.0.0 acl manager proto cache_object -acl localhost src 127.0.0.1/32 ::1/128 -acl to_localhost dst 127.0.0.0/8 ::/126 +acl localhost src 127.0.0.1/255.255.255.255 +acl to_localhost dst 127.0.0.0/8 acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp @@ -3145,8 +3120,8 @@ Example where normal_service_net uses the TOS value 0x00 and normal_service_net uses 0x20 - acl normal_service_net src 10.0.0.0/24 - acl good_service_net src 10.0.1.0/24 + acl normal_service_net src 10.0.0.0/255.255.255.0 + acl good_service_net src 10.0.1.0/255.255.255.0 tcp_outgoing_tos 0x00 normal_service_net 0x00 tcp_outgoing_tos 0x20 good_service_net @@ -3184,8 +3159,8 @@ source address 10.1.0.2 and the rest will be forwarded with source address 10.1.0.3. - acl normal_service_net src 10.0.0.0/24 - acl good_service_net src 10.0.1.0/24 + acl normal_service_net src 10.0.0.0/255.255.255.0 + acl good_service_net src 10.0.1.0/255.255.255.0 tcp_outgoing_address 10.0.0.1 normal_service_net tcp_outgoing_address 10.0.0.2 good_service_net tcp_outgoing_address 10.0.0.3 @@ -3614,13 +3589,13 @@ COMMENT_END NAME: wccp_router -TYPE: address* +TYPE: address LOC: Config.Wccp.router DEFAULT: 0.0.0.0 IFDEF: USE_WCCP DOC_NONE NAME: wccp2_router -TYPE: sockaddr_storage_list +TYPE: sockaddr_in_list LOC: Config.Wccp2.router DEFAULT: none IFDEF: USE_WCCPv2 @@ -3790,13 +3765,13 @@ DOC_END NAME: wccp_address -TYPE: address* +TYPE: address LOC: Config.Wccp.address DEFAULT: 0.0.0.0 IFDEF: USE_WCCP DOC_NONE NAME: wccp2_address -TYPE: address* +TYPE: address LOC: Config.Wccp2.address DEFAULT: 0.0.0.0 IFDEF: USE_WCCPv2 @@ -4422,7 +4397,7 @@ requests, except those in your local domain use something like: acl local-servers dstdomain .foo.net - acl all src 0.0.0.0/0 ::/0 + acl all src 0.0.0.0/0.0.0.0 never_direct deny local-servers never_direct allow all @@ -4627,13 +4602,13 @@ DOC_END NAME: snmp_incoming_address -TYPE: address* +TYPE: address LOC: Config.Addrs.snmp_incoming DEFAULT: 0.0.0.0 IFDEF: SQUID_SNMP DOC_NONE NAME: snmp_outgoing_address -TYPE: address* +TYPE: address LOC: Config.Addrs.snmp_outgoing DEFAULT: 255.255.255.255 IFDEF: SQUID_SNMP @@ -4778,7 +4753,7 @@ NAME: mcast_miss_addr IFDEF: MULTICAST_MISS_STREAM -TYPE: address* +TYPE: address LOC: Config.mcast_miss.addr DEFAULT: 255.255.255.255 DOC_START Index: squid/src/cf_gen.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cf_gen.c,v retrieving revision 1.3.6.5 retrieving revision 1.3.6.6 diff -u -r1.3.6.5 -r1.3.6.6 --- squid/src/cf_gen.c 1 Jul 2007 05:44:20 -0000 1.3.6.5 +++ squid/src/cf_gen.c 2 Jul 2007 07:36:53 -0000 1.3.6.6 @@ -1,6 +1,6 @@ /* - * $Id: cf_gen.c,v 1.3.6.5 2007/07/01 05:44:20 amosjeffries Exp $ + * $Id: cf_gen.c,v 1.3.6.6 2007/07/02 07:36:53 amosjeffries Exp $ * * DEBUG: none Generate squid.conf.default and cf_parser.h * AUTHOR: Max Okumoto @@ -85,7 +85,6 @@ Line *doc; Line *nocomment; int array_flag; - int ptr_flag; struct Entry *next; } Entry; @@ -216,12 +215,6 @@ curr->array_flag = 1; *(ptr + strlen(ptr) - 2) = '\0'; } - /* hack to support pointers to struct */ - curr->ptr_flag = 0; - if (0 == strcmp(ptr + strlen(ptr) - 1, "*")) { - curr->ptr_flag = 1; - *(ptr + strlen(ptr) - 1) = '\0'; - } curr->type = xstrdup(ptr); } else if (!strncmp(buff, "IFDEF:", 6)) { if ((ptr = strtok(buff + 6, WS)) == NULL) { @@ -528,10 +521,9 @@ continue; if (entry->ifdef) fprintf(fp, "#if %s\n", entry->ifdef); - fprintf(fp, "\tdump_%s(entry, \"%s\", %s%s);\n", + fprintf(fp, "\tdump_%s(entry, \"%s\", %s);\n", entry->type, entry->name, - entry->ptr_flag ? "&" : "", entry->loc); if (entry->ifdef) fprintf(fp, "#endif\n"); Index: squid/src/client_db.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_db.c,v retrieving revision 1.4.6.6 retrieving revision 1.4.6.7 diff -u -r1.4.6.6 -r1.4.6.7 --- squid/src/client_db.c 1 Jul 2007 05:44:20 -0000 1.4.6.6 +++ squid/src/client_db.c 2 Jul 2007 07:36:53 -0000 1.4.6.7 @@ -1,6 +1,6 @@ /* - * $Id: client_db.c,v 1.4.6.6 2007/07/01 05:44:20 amosjeffries Exp $ + * $Id: client_db.c,v 1.4.6.7 2007/07/02 07:36:53 amosjeffries Exp $ * * DEBUG: section 0 Client Database * AUTHOR: Duane Wessels @@ -36,7 +36,7 @@ #include "squid.h" static hash_table *client_table = NULL; -static ClientInfo *clientdbAdd(struct sockaddr *addr); +static ClientInfo *clientdbAdd(struct in_addr addr); static FREE clientdbFreeItem; static void clientdbStartGC(void); static void clientdbScheduledGC(void *); @@ -49,14 +49,12 @@ #define CLIENT_DB_HASH_SIZE 467 static ClientInfo * -clientdbAdd(struct sockaddr *addr) +clientdbAdd(struct in_addr addr) { ClientInfo *c; - char host[100]; - getnameinfo(addr, SOCKLEN(addr), host, 100, NULL, 0, NI_NUMERICHOST); c = memAllocate(MEM_CLIENT_INFO); - c->hash.key = xstrdup(host); - xmemcpy(&c->addr, addr, SOCKLEN(addr)); + c->hash.key = xstrdup(xinet_ntoa(addr)); + c->addr = addr; hash_join(client_table, &c->hash); statCounter.client_http.clients++; if ((statCounter.client_http.clients > max_clients) && !cleanup_running && cleanup_scheduled < 2) { @@ -79,13 +77,13 @@ } void -clientdbUpdate(struct sockaddr *addr, log_type ltype, protocol_t p, squid_off_t size) +clientdbUpdate(struct in_addr addr, log_type ltype, protocol_t p, squid_off_t size) { - const char key[100]; + const char *key; ClientInfo *c; if (!Config.onoff.client_db) return; - getnameinfo(addr, SOCKLEN(addr), key, 100, NULL, 0, NI_NUMERICHOST); + key = xinet_ntoa(addr); c = (ClientInfo *) hash_lookup(client_table, key); if (c == NULL) c = clientdbAdd(addr); @@ -115,13 +113,13 @@ * -1. To get the current value, simply call with delta = 0. */ int -clientdbEstablished(struct sockaddr *addr, int delta) +clientdbEstablished(struct in_addr addr, int delta) { - const char key[100]; + const char *key; ClientInfo *c; if (!Config.onoff.client_db) return 0; - getnameinfo(addr, SOCKLEN(addr), key, 100, NULL, 0, NI_NUMERICHOST); + key = xinet_ntoa(addr); c = (ClientInfo *) hash_lookup(client_table, key); if (c == NULL) c = clientdbAdd(addr); @@ -133,16 +131,16 @@ #define CUTOFF_SECONDS 3600 int -clientdbCutoffDenied(struct sockaddr *addr) +clientdbCutoffDenied(struct in_addr addr) { - const char key[100]; + const char *key; int NR; int ND; double p; ClientInfo *c; if (!Config.onoff.client_db) return 0; - getnameinfo(addr, SOCKLEN(addr), key, 100, NULL, 0, NI_NUMERICHOST); + key = xinet_ntoa(addr); c = (ClientInfo *) hash_lookup(client_table, key); if (c == NULL) return 0; @@ -186,7 +184,7 @@ hash_first(client_table); while ((c = (ClientInfo *) hash_next(client_table))) { storeAppendPrintf(sentry, "Address: %s\n", hashKeyStr(&c->hash)); - storeAppendPrintf(sentry, "Name: %s\n", fqdnFromAddr(&c->addr)); + storeAppendPrintf(sentry, "Name: %s\n", fqdnFromAddr(c->addr)); storeAppendPrintf(sentry, "Currently established connections: %d\n", c->n_established); storeAppendPrintf(sentry, " ICP Requests %d\n", @@ -301,7 +299,6 @@ } #if SQUID_SNMP -/* XXX husni */ struct in_addr * client_entry(struct in_addr *current) { @@ -350,7 +347,7 @@ switch (Var->name[LEN_SQ_NET + 2]) { case MESH_CTBL_ADDR: Answer = snmp_var_new_integer(Var->name, Var->name_length, - (snint) 0 /* c->addr.s_addr */, + (snint) c->addr.s_addr, SMI_IPADDRESS); break; case MESH_CTBL_HTBYTES: Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.7.2.12 retrieving revision 1.7.2.13 diff -u -r1.7.2.12 -r1.7.2.13 --- squid/src/client_side.c 1 Jul 2007 08:34:23 -0000 1.7.2.12 +++ squid/src/client_side.c 2 Jul 2007 07:36:53 -0000 1.7.2.13 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.7.2.12 2007/07/01 08:34:23 amosjeffries Exp $ + * $Id: client_side.c,v 1.7.2.13 2007/07/02 07:36:53 amosjeffries Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -220,8 +220,8 @@ request_t *request = http->request; request->x_forwarded_for_iterator = httpHeaderGetList( &request->header, HDR_X_FORWARDED_FOR); - debug(33, 5) ("clientFollowXForwardedForStart: indirect_client_addr=%s XFF='%s'\n", - sockaddr_ntoa(&request->indirect_client_addr), + debug(33, 5) ("clientFollowXForwardedForStart: indirect_client_addr=%s XFF='%s'\n", + inet_ntoa(request->indirect_client_addr), strBuf(request->x_forwarded_for_iterator)); clientFollowXForwardedForNext(http); } @@ -232,7 +232,7 @@ clientHttpRequest *http = data; request_t *request = http->request; debug(33, 5) ("clientFollowXForwardedForNext: indirect_client_addr=%s XFF='%s'\n", - sockaddr_ntoa(&request->indirect_client_addr), + inet_ntoa(request->indirect_client_addr), strBuf(request->x_forwarded_for_iterator)); if (strLen(request->x_forwarded_for_iterator) != 0) { /* check the acl to see whether to believe the X-Forwarded-For header */ @@ -266,10 +266,9 @@ const char *p; const char *asciiaddr; int l; - struct addrinfo hints, *res; - + struct in_addr addr; debug(33, 5) ("clientFollowXForwardedForDone: indirect_client_addr=%s is trusted\n", - sockaddr_ntoa(&request->indirect_client_addr)); + inet_ntoa(request->indirect_client_addr)); p = strBuf(request->x_forwarded_for_iterator); l = strLen(request->x_forwarded_for_iterator); @@ -291,18 +290,16 @@ while (l > 0 && !(p[l - 1] == ',' || xisspace(p[l - 1]))) l--; asciiaddr = p + l; - memset(&hints, 0, sizeof(hints)); - if (getaddrinfo(asciiaddr, NULL, &hints, &res)) { + if (inet_aton(asciiaddr, &addr) == 0) { /* the address is not well formed; do not use it */ debug(33, 3) ("clientFollowXForwardedForDone: malformed address '%s'\n", asciiaddr); goto done; } - debug(33, 3) ("clientFollowXForwardedForDone: changing indirect_client_addr from %s to '%s'\n", - sockaddr_ntoa(&request->indirect_client_addr), + inet_ntoa(request->indirect_client_addr), asciiaddr); - xmemcpy(&request->indirect_client_addr, res->ai_addr, SOCKLEN(res->ai_addr)); + request->indirect_client_addr = addr; strCut(request->x_forwarded_for_iterator, l); if (!Config.onoff.acl_uses_indirect_client) { /* @@ -315,10 +312,10 @@ return; } else if (answer == ACCESS_DENIED) { debug(33, 5) ("clientFollowXForwardedForDone: indirect_client_addr=%s not trusted\n", - sockaddr_ntoa(&request->indirect_client_addr)); + inet_ntoa(request->indirect_client_addr)); } else { debug(33, 5) ("clientFollowXForwardedForDone: indirect_client_addr=%s nothing more to do\n", - sockaddr_ntoa(&request->indirect_client_addr)); + inet_ntoa(request->indirect_client_addr)); } done: /* clean up, and pass control to clientAccessCheck */ @@ -329,10 +326,10 @@ * instead of the direct client. */ ConnStateData *conn = http->conn; - xmemcpy(&conn->log_addr, &request->indirect_client_addr, - sizeof(struct sockaddr_storage)); + conn->log_addr = request->indirect_client_addr; + conn->log_addr.s_addr &= Config.Addrs.client_netmask.s_addr; debug(33, 3) ("clientFollowXForwardedForDone: setting log_addr=%s\n", - sockaddr_ntoa(&conn->log_addr)); + inet_ntoa(conn->log_addr)); } stringClean(&request->x_forwarded_for_iterator); http->acl_checklist = NULL; /* XXX do we need to aclChecklistFree() ? */ @@ -605,14 +602,12 @@ http->uri = xstrdup(urlCanonical(new_request)); new_request->http_ver = old_request->http_ver; httpHeaderAppend(&new_request->header, &old_request->header); - xmemcpy(&new_request->client_addr, &old_request->client_addr, - sizeof(struct sockaddr_storage)); + new_request->client_addr = old_request->client_addr; new_request->client_port = old_request->client_port; #if FOLLOW_X_FORWARDED_FOR new_request->indirect_client_addr = old_request->indirect_client_addr; #endif /* FOLLOW_X_FORWARDED_FOR */ - xmemcpy(&new_request->my_addr, &old_request->my_addr, - sizeof(struct sockaddr_storage)); + new_request->my_addr = old_request->my_addr; new_request->my_port = old_request->my_port; new_request->flags = old_request->flags; new_request->flags.redirected = 1; @@ -1272,7 +1267,7 @@ http->al.icp.opcode = ICP_INVALID; http->al.url = http->uri; debug(33, 9) ("httpRequestFree: al.url='%s'\n", http->al.url); - xmemcpy(&http->al.cache.out_ip, &request->out_ip, sizeof(struct sockaddr_storage)); + http->al.cache.out_ip = request->out_ip; if (http->reply && http->log_type != LOG_TCP_DENIED) { http->al.http.code = http->reply->sline.status; http->al.http.content_type = strBuf(http->reply->content_type); @@ -1280,8 +1275,7 @@ http->al.http.code = mem->reply->sline.status; http->al.http.content_type = strBuf(mem->reply->content_type); } - xmemcpy(&http->al.cache.caddr, &conn->log_addr, - sizeof(struct sockaddr_storage)); + http->al.cache.caddr = conn->log_addr; http->al.cache.size = http->out.size; http->al.cache.code = http->log_type; http->al.cache.msec = tvSubMsec(http->start, current_time); @@ -1323,7 +1317,7 @@ http->al.reply = http->reply; accessLogLog(&http->al, http->acl_checklist); clientUpdateCounters(http); - clientdbUpdate((struct sockaddr*)&conn->peer, http->log_type, PROTO_HTTP, http->out.size); + clientdbUpdate(conn->peer.sin_addr, http->log_type, PROTO_HTTP, http->out.size); } } if (http->acl_checklist) @@ -1378,7 +1372,7 @@ clientHttpRequest *http; debug(33, 3) ("connStateFree: FD %d\n", fd); assert(connState != NULL); - clientdbEstablished((struct sockaddr*)&connState->peer, -1); /* decrement */ + clientdbEstablished(connState->peer.sin_addr, -1); /* decrement */ n = connState->reqs.head; while (n != NULL) { http = n->data; @@ -1536,11 +1530,11 @@ } #if USE_USERAGENT_LOG if ((str = httpHeaderGetStr(req_hdr, HDR_USER_AGENT))) - logUserAgent(fqdnFromAddr(&http->conn->log_addr), str); + logUserAgent(fqdnFromAddr(http->conn->log_addr), str); #endif #if USE_REFERER_LOG if ((str = httpHeaderGetStr(req_hdr, HDR_REFERER))) - logReferer(fqdnFromAddr(&http->conn->log_addr), str, rfc1738_escape_unescaped(http->uri)); + logReferer(fqdnFromAddr(http->conn->log_addr), str, rfc1738_escape_unescaped(http->uri)); #endif #if FORW_VIA_DB if (httpHeaderHas(req_hdr, HDR_X_FORWARDED_FOR)) { @@ -3019,7 +3013,7 @@ #if SIZEOF_SQUID_OFF_T <= 4 if (http->out.size > 0x7FFF0000) { debug(33, 1) ("WARNING: closing FD %d to prevent counter overflow\n", fd); - debug(33, 1) ("\tclient %s\n", sockaddr_ntoa(&http->conn->peer)); + debug(33, 1) ("\tclient %s\n", inet_ntoa(http->conn->peer.sin_addr)); debug(33, 1) ("\treceived %d bytes\n", (int) http->out.size); debug(33, 1) ("\tURI %s\n", http->log_uri); comm_close(fd); @@ -3028,7 +3022,7 @@ #if SIZEOF_SQUID_OFF_T <= 4 if (http->out.offset > 0x7FFF0000) { debug(33, 1) ("WARNING: closing FD %d to prevent counter overflow\n", fd); - debug(33, 1) ("\tclient %s\n", sockaddr_ntoa(&http->conn->peer)); + debug(33, 1) ("\tclient %s\n", inet_ntoa(http->conn->peer.sin_addr)); debug(33, 1) ("\treceived %d bytes (offset %d)\n", (int) http->out.size, (int) http->out.offset); debug(33, 1) ("\tURI %s\n", http->log_uri); @@ -3537,13 +3531,10 @@ http->flags.accel = 1; debug(33, 5) ("INTERNAL REWRITE: '%s'\n", http->uri); } else if (*url == '/' && conn->port->transparent) { - char *q = NULL; int port = 0; const char *host = mime_get_header(req_hdr, "Host"); char *portstr; - if (!(q = strchr(host, ']'))) - q = host; - if (host && (portstr = strchr(q, ':')) != NULL) { + if (host && (portstr = strchr(host, ':')) != NULL) { *portstr++ = '\0'; port = atoi(portstr); } @@ -3563,11 +3554,9 @@ if (conn->port->transparent && clientNatLookup(conn) == 0) conn->transparent = 1; if (!host && conn->transparent) { - port = (conn->me.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&conn->me)->sin6_port) : - ntohs(((struct sockaddr_in *)&conn->me)->sin_port); + port = ntohs(conn->me.sin_port); if (!host) - host = sockaddr_ntoa(&conn->me); + host = inet_ntoa(conn->me.sin_addr); } if (host) { size_t url_sz = 10 + strlen(host) + 6 + strlen(url) + 32 + Config.appendDomainLen; @@ -3599,13 +3588,9 @@ if (*url != '/') { /* Fully qualified URL. Nothing special to do */ } else if (vhost && (t = mime_get_header(req_hdr, "Host"))) { - char *portstr, *q; + char *portstr = strchr(t, ':'); int port = 0; size_t url_sz = strlen(url) + 32 + Config.appendDomainLen + strlen(t); - - if (!(q = strchr(t, ']'))) - q = t; - portstr = strchr(q, ':'); if (portstr) { *portstr++ = '\0'; port = atoi(portstr); @@ -3634,7 +3619,7 @@ http->uri = xcalloc(url_sz, 1); snprintf(http->uri, url_sz, "%s://%s:%d%s", http->conn->port->protocol, - sockaddr_ntoa(&http->conn->me), + inet_ntoa(http->conn->me.sin_addr), vport, url); debug(33, 5) ("VPORT REWRITE: '%s'\n", http->uri); } else if (internalCheck(url)) { @@ -3743,7 +3728,7 @@ if (parser_return_code < 0) { debug(33, 1) ("clientReadRequest: FD %d (%s:%d) Invalid Request\n", fd, fd_table[fd].ipaddr, fd_table[fd].remote_port); err = errorCon(ERR_INVALID_REQ, HTTP_BAD_REQUEST, NULL); - xmemcpy(&err->src_addr, &conn->peer, sizeof(struct sockaddr_storage)); + err->src_addr = conn->peer.sin_addr; err->request_hdrs = xstrdup(conn->in.buf); http->log_type = LOG_TCP_DENIED; http->entry = clientCreateStoreEntry(http, method, null_request_flags); @@ -3753,7 +3738,7 @@ if ((request = urlParse(method, http->uri)) == NULL) { debug(33, 5) ("Invalid URL: %s\n", http->uri); err = errorCon(ERR_INVALID_URL, HTTP_BAD_REQUEST, NULL); - xmemcpy(&err->src_addr, &conn->peer, sizeof(struct sockaddr_storage)); + err->src_addr = conn->peer.sin_addr; err->url = xstrdup(http->uri); http->al.http.code = err->http_status; http->log_type = LOG_TCP_DENIED; @@ -3809,20 +3794,13 @@ request->content_length = httpHeaderGetSize(&request->header, HDR_CONTENT_LENGTH); request->flags.internal = http->flags.internal; - xmemcpy(&request->client_addr, &conn->peer, sizeof(struct sockaddr_storage)); - request->client_port = (conn->peer.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&conn->peer)->sin6_port) : - ntohs(((struct sockaddr_in *)&conn->peer)->sin_port); + request->client_addr = conn->peer.sin_addr; + request->client_port = ntohs(conn->peer.sin_port); #if FOLLOW_X_FORWARDED_FOR request->indirect_client_addr = request->client_addr; #endif /* FOLLOW_X_FORWARDED_FOR */ - xmemcpy(&request->my_addr, &conn->me, sizeof(struct sockaddr_storage)); - request->my_port = (conn->me.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&conn->me)->sin6_port) : - ntohs(((struct sockaddr_in *)&conn->me)->sin_port); - request->client_port = (conn->peer.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&conn->peer)->sin6_port) : - ntohs(((struct sockaddr_in *)&conn->peer)->sin_port); + request->my_addr = conn->me.sin_addr; + request->my_port = ntohs(conn->me.sin_port); request->http_ver = http->http_ver; if (!urlCheckRequest(request) || httpHeaderHas(&request->header, HDR_TRANSFER_ENCODING)) { @@ -3867,7 +3845,7 @@ if (!DLINK_ISEMPTY(conn->reqs) && DLINK_HEAD(conn->reqs) == http) clientCheckFollowXForwardedFor(http); else { - debug(33, 1)("WARNING: pipelined CONNECT request seen from %s\n", sockaddr_ntoa(&http->conn->peer)); + debug(33, 1) ("WARNING: pipelined CONNECT request seen from %s\n", inet_ntoa(http->conn->peer.sin_addr)); debugObj(33, 1, "Previous request:\n", ((clientHttpRequest *) DLINK_HEAD(conn->reqs))->request, (ObjPackMethod) & httpRequestPackDebug); debugObj(33, 1, "This request:\n", request, (ObjPackMethod) & httpRequestPackDebug); @@ -3888,7 +3866,7 @@ debug(33, 1) ("Config 'request_header_max_size'= %ld bytes.\n", (long int) Config.maxRequestHeaderSize); err = errorCon(ERR_TOO_BIG, HTTP_REQUEST_ENTITY_TOO_LARGE, NULL); - xmemcpy(&err->src_addr, &conn->peer, sizeof(struct sockaddr_storage)); + err->src_addr = conn->peer.sin_addr; http = parseHttpRequestAbort(conn, "error:request-too-large"); /* add to the client request queue */ dlinkAddTail(http, &http->node, &conn->reqs); @@ -4194,7 +4172,8 @@ { clientHttpRequest *http = data; ConnStateData *conn = http->conn; - debug(33, 1) ("WARNING: Closing client %s connection due to lifetime timeout\n", sockaddr_ntoa(&conn->peer)); + debug(33, 1) ("WARNING: Closing client %s connection due to lifetime timeout\n", + inet_ntoa(conn->peer.sin_addr)); debug(33, 1) ("\t%s\n", http->uri); comm_close(fd); } @@ -4304,7 +4283,7 @@ clientNatLookup(ConnStateData * conn) { socklen_t sock_sz = sizeof(conn->me); - struct in_addr orig_addr = ((struct sockaddr_in *)&conn->me)->sin_addr; + struct in_addr orig_addr = conn->me.sin_addr; static time_t last_reported = 0; /* If the call fails the address structure will be unchanged */ if (getsockopt(conn->fd, SOL_IP, SO_ORIGINAL_DST, &conn->me, &sock_sz) != 0) { @@ -4314,8 +4293,8 @@ } return -1; } - debug(33, 5) ("clientNatLookup: addr = %s", sockaddr_ntoa(&conn->me)); - if (orig_addr.s_addr != ((struct sockaddr_in *)&conn->me)->sin_addr.s_addr) + debug(33, 5) ("clientNatLookup: addr = %s", inet_ntoa(conn->me.sin_addr)); + if (orig_addr.s_addr != conn->me.sin_addr.s_addr) return 0; else return -1; @@ -4386,17 +4365,17 @@ int fd = -1; fde *F; ConnStateData *connState = NULL; - struct sockaddr_storage peer; - struct sockaddr_storage me; + struct sockaddr_in peer; + struct sockaddr_in me; int max = INCOMING_HTTP_MAX; #if USE_IDENT static aclCheck_t identChecklist; #endif commSetSelect(sock, COMM_SELECT_READ, httpAccept, data, 0); while (max-- && !httpAcceptDefer(sock, NULL)) { - memset(&peer, '\0', sizeof(struct sockaddr_storage)); - memset(&me, '\0', sizeof(struct sockaddr_storage)); - if ((fd = comm_accept(sock, (struct sockaddr*)&peer, (struct sockaddr*)&me)) < 0) { + memset(&peer, '\0', sizeof(struct sockaddr_in)); + memset(&me, '\0', sizeof(struct sockaddr_in)); + if ((fd = comm_accept(sock, &peer, &me)) < 0) { if (!ignoreErrno(errno)) debug(50, 1) ("httpAccept: FD %d: accept failure: %s\n", sock, xstrerror()); @@ -4408,36 +4387,27 @@ connState = cbdataAlloc(ConnStateData); connState->port = s; cbdataLock(connState->port); - xmemcpy(&connState->peer, &peer, - sizeof(struct sockaddr_storage)); - xmemcpy(&connState->log_addr, &peer, - sizeof(struct sockaddr_storage)); -/* + connState->peer = peer; + connState->log_addr = peer.sin_addr; connState->log_addr.s_addr &= Config.Addrs.client_netmask.s_addr; -*/ - xmemcpy(&connState->me, &me, - sizeof(struct sockaddr_storage)); + connState->me = me; connState->fd = fd; connState->pinning.fd = -1; connState->in.buf = memAllocBuf(CLIENT_REQ_BUF_SZ, &connState->in.size); comm_add_close_handler(fd, connStateFree, connState); if (Config.onoff.log_fqdn) - fqdncache_gethostbyaddr(&peer, FQDN_LOOKUP_IF_MISS); + fqdncache_gethostbyaddr(peer.sin_addr, FQDN_LOOKUP_IF_MISS); commSetTimeout(fd, Config.Timeout.request, requestTimeout, connState); #if USE_IDENT - xmemcpy(&identChecklist.src_addr, &peer, - sizeof(struct sockaddr_storage)); - xmemcpy(&identChecklist.my_addr, &me, - sizeof(struct sockaddr_storage)); - identChecklist.my_port = (me.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&me)->sin6_port) : - ntohs(((struct sockaddr_in *)&me)->sin_port) ; + identChecklist.src_addr = peer.sin_addr; + identChecklist.my_addr = me.sin_addr; + identChecklist.my_port = ntohs(me.sin_port); if (aclCheckFast(Config.accessList.identLookup, &identChecklist)) identStart(&me, &peer, clientIdentDone, connState); #endif commSetSelect(fd, COMM_SELECT_READ, clientReadRequest, connState, 0); commSetDefer(fd, clientReadDefer, connState); - clientdbEstablished(&peer, 1); + clientdbEstablished(peer.sin_addr, 1); incoming_sockets_accepted++; } } @@ -4555,8 +4525,8 @@ https_port_list *s = data; int fd = -1; ConnStateData *connState = NULL; - struct sockaddr_storage peer; - struct sockaddr_storage me; + struct sockaddr_in peer; + struct sockaddr_in me; int max = INCOMING_HTTP_MAX; #if USE_IDENT static aclCheck_t identChecklist; @@ -4564,8 +4534,8 @@ commSetSelect(sock, COMM_SELECT_READ, httpsAccept, s, 0); while (max-- && !httpAcceptDefer(sock, NULL)) { fde *F; - memset(&peer, '\0', sizeof(struct sockaddr_storage)); - memset(&me, '\0', sizeof(struct sockaddr_storage)); + memset(&peer, '\0', sizeof(struct sockaddr_in)); + memset(&me, '\0', sizeof(struct sockaddr_in)); if ((fd = comm_accept(sock, &peer, &me)) < 0) { if (!ignoreErrno(errno)) debug(50, 1) ("httpsAccept: FD %d: accept failure: %s\n", @@ -4577,34 +4547,25 @@ connState = cbdataAlloc(ConnStateData); connState->port = (http_port_list *) s; cbdataLock(connState->port); - xmemcpy(&connState->peer, &peer, - sizeof(struct sockaddr_storage)); - xmemcpy(&connState->log_addr, &peer, - sizeof(struct sockaddr_storage)); -/* + connState->peer = peer; + connState->log_addr = peer.sin_addr; connState->log_addr.s_addr &= Config.Addrs.client_netmask.s_addr; -*/ - xmemcpy(&connState->me, &me, - sizeof(struct sockaddr_storage)); + connState->me = me; connState->fd = fd; connState->pinning.fd = -1; connState->in.buf = memAllocBuf(CLIENT_REQ_BUF_SZ, &connState->in.size); comm_add_close_handler(fd, connStateFree, connState); if (Config.onoff.log_fqdn) - fqdncache_gethostbyaddr(&peer, FQDN_LOOKUP_IF_MISS); + fqdncache_gethostbyaddr(peer.sin_addr, FQDN_LOOKUP_IF_MISS); commSetTimeout(fd, Config.Timeout.request, requestTimeout, connState); #if USE_IDENT - xmemcpy(&identChecklist.src_addr, &peer, - sizeof(struct sockaddr_storage)); - xmemcpy(&identChecklist.my_addr, &me, - sizeof(struct sockaddr_storage)); -/* + identChecklist.src_addr = peer.sin_addr; + identChecklist.my_addr = me.sin_addr; identChecklist.my_port = ntohs(me.sin_port); -*/ if (aclCheckFast(Config.accessList.identLookup, &identChecklist)) identStart(&me, &peer, clientIdentDone, connState); #endif - clientdbEstablished(&peer, 1); + clientdbEstablished(peer.sin_addr, 1); incoming_sockets_accepted++; httpsAcceptSSL(connState, s->sslContext); } @@ -4742,7 +4703,6 @@ { http_port_list *s; int fd; - char host[100], port[8]; for (s = Config.Sockaddr.http; s; s = s->next) { if (MAXHTTPPORTS == NHttpSockets) { debug(1, 1) ("WARNING: You have too many 'http_port' lines.\n"); @@ -4750,10 +4710,12 @@ continue; } enter_suid(); - fd = comm_open(SOCK_STREAM, IPPROTO_TCP, - (struct sockaddr *)&s->s, - COMM_NONBLOCKING, - "HTTP Socket"); + fd = comm_open(SOCK_STREAM, + IPPROTO_TCP, + s->s.sin_addr, + ntohs(s->s.sin_port), + COMM_NONBLOCKING, + "HTTP Socket"); leave_suid(); if (fd < 0) continue; @@ -4764,14 +4726,12 @@ * peg the CPU with select() when we hit the FD limit. */ commSetDefer(fd, httpAcceptDefer, NULL); - getnameinfo((struct sockaddr*)&s->s, SOCKLEN(&s->s), - host, 100, port, 8, NI_NUMERICHOST|NI_NUMERICSERV); - debug(1, 1) ("Accepting %s HTTP connections at %s, port %s, FD %d.\n", + debug(1, 1) ("Accepting %s HTTP connections at %s, port %d, FD %d.\n", s->transparent ? "transparently proxied" : s->accel ? "accelerated" : "proxy", - host, - port, + inet_ntoa(s->s.sin_addr), + (int) ntohs(s->s.sin_port), fd); HttpSockets[NHttpSockets++] = fd; } @@ -4794,7 +4754,8 @@ enter_suid(); fd = comm_open(SOCK_STREAM, IPPROTO_TCP, - &s->http.s, + s->http.s.sin_addr, + ntohs(s->http.s.sin_port), COMM_NONBLOCKING, "HTTPS Socket"); leave_suid(); @@ -4804,10 +4765,8 @@ commSetSelect(fd, COMM_SELECT_READ, httpsAccept, s, 0); commSetDefer(fd, httpAcceptDefer, NULL); debug(1, 1) ("Accepting HTTPS connections at %s, port %d, FD %d.\n", - sockaddr_ntoa(&s->http.s), - (int) s->http.s.ss_family == AF_INET6 ? - ntohs(((struct sockaddr_in6 *)&s->http.s)->sin6_port) : - ntohs(((struct sockaddr_in *)&s->http.s)->sin_port) , + inet_ntoa(s->http.s.sin_addr), + (int) ntohs(s->http.s.sin_port), fd); HttpSockets[NHttpSockets++] = fd; } Index: squid/src/comm.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm.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/comm.c 1 Jul 2007 08:34:27 -0000 1.4.6.11 +++ squid/src/comm.c 2 Jul 2007 07:36:57 -0000 1.4.6.12 @@ -1,6 +1,6 @@ /* - * $Id: comm.c,v 1.4.6.11 2007/07/01 08:34:27 amosjeffries Exp $ + * $Id: comm.c,v 1.4.6.12 2007/07/02 07:36:57 amosjeffries Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -50,19 +50,18 @@ typedef struct { char *host; u_short port; - struct sockaddr_storage S; + struct sockaddr_in S; CNCB *callback; void *data; - struct sockaddr_storage in_addr; + struct in_addr in_addr; int fd; int tries; - int ia_cur; int addrcount; int connstart; } ConnectStateData; /* STATIC */ -static int commBind(int s, struct sockaddr *S); +static int commBind(int s, struct in_addr, u_short port); static void commSetReuseAddr(int); static void commSetNoLinger(int); static void CommWriteStateCallbackAndFree(int fd, int code); @@ -112,7 +111,7 @@ u_short comm_local_port(int fd) { - struct sockaddr_storage addr; + struct sockaddr_in addr; socklen_t addr_len = 0; fde *F = &fd_table[fd]; @@ -123,29 +122,33 @@ } if (F->local_port) return F->local_port; - addr_len = sizeof(struct sockaddr_storage); + addr_len = sizeof(addr); if (getsockname(fd, (struct sockaddr *) &addr, &addr_len)) { debug(5, 1) ("comm_local_port: Failed to retrieve TCP/UDP port number for socket: FD %d: %s\n", fd, xstrerror()); return 0; } - F->local_port = (addr.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&addr)->sin6_port): - ntohs(((struct sockaddr_in *)&addr)->sin_port) ; + F->local_port = ntohs(addr.sin_port); debug(5, 6) ("comm_local_port: FD %d: port %d\n", fd, (int) F->local_port); return F->local_port; } static int -commBind(int s, struct sockaddr *S) +commBind(int s, struct in_addr in_addr, u_short port) { - char hbuf[80], sbuf[8]; + struct sockaddr_in S; + + memset(&S, '\0', sizeof(S)); + S.sin_family = AF_INET; + S.sin_port = htons(port); + S.sin_addr = in_addr; statCounter.syscalls.sock.binds++; - if (bind(s, S, SOCKLEN(S)) == 0) + if (bind(s, (struct sockaddr *) &S, sizeof(S)) == 0) return COMM_OK; - getnameinfo(S, S->sa_family, hbuf, 80, sbuf, 8, - NI_NUMERICHOST|NI_NUMERICSERV); - debug(5, 0) ("commBind: Cannot bind socket FD %d to %s:%s: %s\n", - s, hbuf, sbuf, xstrerror()); + debug(5, 0) ("commBind: Cannot bind socket FD %d to %s:%d: %s\n", + s, + S.sin_addr.s_addr == INADDR_ANY ? "*" : inet_ntoa(S.sin_addr), + (int) port, + xstrerror()); return COMM_ERROR; } @@ -154,11 +157,12 @@ int comm_open(int sock_type, int proto, - struct sockaddr *addr, + struct in_addr addr, + u_short port, int flags, const char *note) { - return comm_openex(sock_type, proto, addr, flags, 0, note); + return comm_openex(sock_type, proto, addr, port, flags, 0, note); } @@ -167,19 +171,19 @@ int comm_openex(int sock_type, int proto, - struct sockaddr *addr, + struct in_addr addr, + u_short port, int flags, unsigned char TOS, const char *note) { int new_socket; - u_short port; int tos = 0; fde *F = NULL; /* Create socket for accepting new connections. */ statCounter.syscalls.sock.sockets++; - if ((new_socket = socket(addr->sa_family, sock_type, proto)) < 0) { + if ((new_socket = socket(AF_INET, sock_type, proto)) < 0) { /* Increase the number of reserved fd's if calls to socket() * are failing because the open file table is full. This * limits the number of simultaneous clients */ @@ -209,15 +213,12 @@ debug(5, 5) ("comm_open: FD %d is a new socket\n", new_socket); fd_open(new_socket, FD_SOCKET, note); F = &fd_table[new_socket]; - xmemcpy(&F->local_addr, addr, SOCKLEN(addr)); + F->local_addr = addr; F->tos = tos; if (!(flags & COMM_NOCLOEXEC)) commSetCloseOnExec(new_socket); if ((flags & COMM_REUSEADDR)) commSetReuseAddr(new_socket); - port = (addr->sa_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)addr)->sin6_port) : - ntohs(((struct sockaddr_in *)addr)->sin_port); if (port > (u_short) 0) { #ifdef _SQUID_MSWIN_ if (sock_type != SOCK_DGRAM) @@ -226,38 +227,14 @@ if (opt_reuseaddr) commSetReuseAddr(new_socket); } - switch (addr->sa_family) { - case AF_INET: - if (((struct sockaddr_in *)addr)->sin_addr.s_addr != no_addr.s_addr) { - if (commBind(new_socket, addr) != COMM_OK) { - comm_close(new_socket); - return -1; - } - } - F->local_port = ntohs(((struct sockaddr_in *)addr)->sin_port); - break; - case AF_INET6: - { - struct in6_addr *s6 = &((struct sockaddr_in6 *)addr)->sin6_addr; - if (!IN6_IS_ADDR_ALLF( s6 ) ) { -#ifdef IPV6_V6ONLY - const int on = 1; - if (setsockopt(new_socket, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0) { - comm_close(new_socket); - return -1; - } -#endif - if (commBind(new_socket, addr) != COMM_OK) { - comm_close(new_socket); - return -1; - } - } - F->local_port = ntohs(((struct sockaddr_in6 *)addr)->sin6_port); - } - break; + if (addr.s_addr != no_addr.s_addr) { + if (commBind(new_socket, addr, port) != COMM_OK) { + comm_close(new_socket); + return -1; + } } + F->local_port = port; - xmemcpy(&F->local_addr, addr, SOCKLEN(addr)); if (flags & COMM_NONBLOCKING) if (commSetNonBlocking(new_socket) == COMM_ERROR) return -1; @@ -291,10 +268,9 @@ } void -commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *data, struct sockaddr *addr) +commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *data, struct in_addr *addr) { ConnectStateData *cs; - FwdState *fwdState = data; debug(5, 3) ("commConnectStart: FD %d, %s:%d\n", fd, host, (int) port); cs = cbdataAlloc(ConnectStateData); cs->fd = fd; @@ -303,12 +279,11 @@ cs->callback = callback; cs->data = data; if (addr != NULL) { - xmemcpy(&cs->in_addr, addr, sizeof(struct sockaddr_storage)); + cs->in_addr = *addr; cs->addrcount = 1; } else { cs->addrcount = 0; } - cs->ia_cur= fwdState->ia_cur; cbdataLock(cs->data); comm_add_close_handler(fd, commConnectFree, cs); ipcache_nbgethostbyname(host, commConnectDnsHandle, cs); @@ -336,15 +311,9 @@ return; } assert(ia->cur < ia->count); - if (Config.onoff.balance_on_multiple_ip) { - if (cs->ia_cur < 0) { - ipcacheCycleAddr(cs->host, NULL); - cs->ia_cur = ia->cur; - } - } - else - cs->ia_cur = ia->cur; - xmemcpy(&cs->in_addr, &ia->in_addrs[cs->ia_cur], sizeof(struct sockaddr_storage)); + cs->in_addr = ia->in_addrs[ia->cur]; + if (Config.onoff.balance_on_multiple_ip) + ipcacheCycleAddr(cs->host, NULL); cs->addrcount = ia->count; cs->connstart = squid_curtime; commConnectHandle(cs->fd, cs); @@ -355,9 +324,7 @@ { CNCB *callback = cs->callback; void *data = cs->data; - FwdState *fwdState = cs->data; int fd = cs->fd; - fwdState->ia_cur = cs->ia_cur; comm_remove_close_handler(fd, commConnectFree, cs); cs->callback = NULL; cs->data = NULL; @@ -385,17 +352,10 @@ { int fd2; fde *F; - struct sockaddr_storage oldsock; - socklen_t oldsocklen = sizeof(oldsock); if (!cbdataValid(cs->data)) return 0; statCounter.syscalls.sock.sockets++; - getsockname(cs->fd, (struct sockaddr *)&oldsock, &oldsocklen); - F = &fd_table[cs->fd]; - if (F->local_addr.ss_family == AF_INET6) - fd2 = socket(AF_INET6, SOCK_STREAM, 0); - else - fd2 = socket(AF_INET, SOCK_STREAM, 0); + fd2 = socket(AF_INET, SOCK_STREAM, 0); statCounter.syscalls.sock.sockets++; if (fd2 < 0) { debug(5, 0) ("commResetFD: socket: %s\n", xstrerror()); @@ -418,12 +378,13 @@ return 0; } close(fd2); + F = &fd_table[cs->fd]; fd_table[cs->fd].flags.called_connect = 0; /* * yuck, this has assumptions about comm_open() arguments for * the original socket */ - if (commBind(cs->fd, &F->local_addr) != COMM_OK) { + if (commBind(cs->fd, F->local_addr, F->local_port) != COMM_OK) { debug(5, 0) ("commResetFD: bind: %s\n", xstrerror()); return 0; } @@ -478,14 +439,10 @@ commConnectHandle(int fd, void *data) { ConnectStateData *cs = data; - struct sockaddr *sa; - if ((cs->in_addr.ss_family == AF_INET) || (cs->in_addr.ss_family == AF_INET6)) { - xmemcpy(&cs->S, &cs->in_addr, sizeof(struct sockaddr_storage)); - sa =(struct sockaddr *)&cs->S; - if (sa->sa_family == AF_INET6) - ((struct sockaddr_in6 *)&cs->S)->sin6_port = htons(cs->port); - else - ((struct sockaddr_in *)&cs->S)->sin_port = htons(cs->port); + if (cs->S.sin_addr.s_addr == 0) { + cs->S.sin_family = AF_INET; + cs->S.sin_addr = cs->in_addr; + cs->S.sin_port = htons(cs->port); } switch (comm_connect_addr(fd, &cs->S)) { case COMM_INPROGRESS: @@ -493,18 +450,14 @@ commSetSelect(fd, COMM_SELECT_WRITE, commConnectHandle, cs, 0); break; case COMM_OK: - ipcacheMarkGoodAddr(cs->host, &cs->S); + ipcacheMarkGoodAddr(cs->host, cs->S.sin_addr); commConnectCallback(cs, COMM_OK); break; - case COMM_ERR_NOSUPPORT: - case COMM_ERR_INV_ARGS: - commConnectCallback(cs, COMM_ERR_INV_ARGS); - break; default: cs->tries++; - ipcacheMarkBadAddr(cs->host, &cs->S); + ipcacheMarkBadAddr(cs->host, cs->S.sin_addr); if (Config.onoff.test_reachability) - netdbDeleteAddrNetwork(&cs->S); + netdbDeleteAddrNetwork(cs->S.sin_addr); if (commRetryConnect(cs)) { eventAdd("commReconnect", commReconnect, cs, cs->addrcount == 1 ? 0.05 : 0.0, 0); } else { @@ -537,31 +490,26 @@ } int -comm_connect_addr(int sock, const struct sockaddr *address) +comm_connect_addr(int sock, const struct sockaddr_in *address) { int status = COMM_OK; fde *F = &fd_table[sock]; int x; int err = 0; socklen_t errlen; - - if (address->sa_family == AF_INET6) - assert(ntohs(((struct sockaddr_in6 *)address)->sin6_port) != 0); - else - assert(ntohs(((struct sockaddr_in *)address)->sin_port) != 0); + assert(ntohs(address->sin_port) != 0); /* Establish connection. */ errno = 0; if (!F->flags.called_connect) { F->flags.called_connect = 1; statCounter.syscalls.sock.connects++; - x = connect(sock, address, SOCKLEN(address)); + x = connect(sock, (struct sockaddr *) address, sizeof(*address)); if (x < 0) - debug(5, 2) ("connect FD %d to %s : %s\n", sock, - sockaddr_ntoa((struct sockaddr *)address), xstrerror()); + debug(5, 9) ("connect FD %d: %s\n", sock, xstrerror()); } else { #if defined(_SQUID_NEWSOS6_) /* Makoto MATSUSHITA */ - connect(sock, address, SOCKLEN(address)); + connect(sock, (struct sockaddr *) address, sizeof(*address)); if (errno == EINVAL) { errlen = sizeof(err); x = getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &errlen); @@ -589,16 +537,10 @@ status = COMM_OK; else if (ignoreErrno(errno)) status = COMM_INPROGRESS; - else if (errno == COMM_ERR_INV_ARGS) - return COMM_ERR_INV_ARGS; - else if (errno == COMM_ERR_NOSUPPORT) - return COMM_ERR_INV_ARGS; else return COMM_ERROR; - xstrncpy(F->ipaddr, sockaddr_ntoa((struct sockaddr *)address), 80); - F->remote_port = (address->sa_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)address)->sin6_port) : - ntohs(((struct sockaddr_in *)address)->sin_port); + xstrncpy(F->ipaddr, xinet_ntoa(address->sin_addr), 16); + F->remote_port = ntohs(address->sin_port); if (status == COMM_OK) { debug(5, 10) ("comm_connect_addr: FD %d connected to %s:%d\n", sock, F->ipaddr, F->remote_port); @@ -611,11 +553,11 @@ /* Wait for an incoming connection on FD. FD should be a socket returned * from comm_listen. */ int -comm_accept(int fd, struct sockaddr *pn, struct sockaddr *me) +comm_accept(int fd, struct sockaddr_in *pn, struct sockaddr_in *me) { int sock; - struct sockaddr_storage P; - struct sockaddr_storage M; + struct sockaddr_in P; + struct sockaddr_in M; socklen_t Slen; fde *F = NULL; Slen = sizeof(P); @@ -633,27 +575,19 @@ } } if (pn) - xmemcpy(pn, &P, SOCKLEN(&P)); + *pn = P; Slen = sizeof(M); memset(&M, '\0', Slen); getsockname(sock, (struct sockaddr *) &M, &Slen); if (me) - xmemcpy(me, &M, SOCKLEN(&M)); + *me = M; commSetCloseOnExec(sock); /* fdstat update */ fd_open(sock, FD_SOCKET, "HTTP Request"); F = &fd_table[sock]; - xstrncpy(F->ipaddr, sockaddr_ntoa((struct sockaddr *)&P), 80); - switch (P.ss_family) { - case AF_INET6: - F->remote_port = ntohs(((struct sockaddr_in6 *)&P)->sin6_port); - F->local_port = ntohs(((struct sockaddr_in6 *)&M)->sin6_port); - break; - case AF_INET: - F->remote_port = ntohs(((struct sockaddr_in *)&P)->sin_port); - F->local_port = ntohs(((struct sockaddr_in *)&M)->sin_port); - break; - } + xstrncpy(F->ipaddr, xinet_ntoa(P.sin_addr), 16); + F->remote_port = htons(P.sin_port); + F->local_port = htons(M.sin_port); commSetNonBlocking(sock); return sock; } @@ -841,25 +775,22 @@ /* Send a udp datagram to specified TO_ADDR. */ int comm_udp_sendto(int fd, - const struct sockaddr *to_addr, + const struct sockaddr_in *to_addr, int addr_len, const void *buf, int len) { int x; - char hbuf[100], sbuf[8]; statCounter.syscalls.sock.sendtos++; - x = sendto(fd, buf, len, 0, to_addr, SOCKLEN(to_addr)); + x = sendto(fd, buf, len, 0, (struct sockaddr *) to_addr, addr_len); if (x < 0) { - getnameinfo(to_addr, SOCKLEN(to_addr), hbuf, 100, sbuf, 8, - NI_NUMERICHOST|NI_NUMERICSERV); #ifdef _SQUID_LINUX_ if (ECONNREFUSED != errno) #endif - debug(5, 1) ("comm_udp_sendto: FD %d, %s, port %s: %s\n", + debug(5, 1) ("comm_udp_sendto: FD %d, %s, port %d: %s\n", fd, - hbuf, - sbuf, + inet_ntoa(to_addr->sin_addr), + (int) htons(to_addr->sin_port), xstrerror()); return COMM_ERROR; } Index: squid/src/comm_generic.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm_generic.c,v retrieving revision 1.8.14.3 retrieving revision 1.8.14.4 diff -u -r1.8.14.3 -r1.8.14.4 --- squid/src/comm_generic.c 1 Jul 2007 05:44:21 -0000 1.8.14.3 +++ squid/src/comm_generic.c 2 Jul 2007 07:36:57 -0000 1.8.14.4 @@ -1,6 +1,6 @@ /* - * $Id: comm_generic.c,v 1.8.14.3 2007/07/01 05:44:21 amosjeffries Exp $ + * $Id: comm_generic.c,v 1.8.14.4 2007/07/02 07:36:57 amosjeffries Exp $ * * DEBUG: section 5 Socket Functions * @@ -165,10 +165,6 @@ do_call_incoming(theInIcpConnection); if (theOutIcpConnection != theInIcpConnection) do_call_incoming(theOutIcpConnection); - if (theInIcpConnection6 >= 0) - do_call_incoming(theInIcpConnection6); - if (theOutIcpConnection6 != theInIcpConnection6) - do_call_incoming(theOutIcpConnection6); } static inline void Index: squid/src/defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/defines.h,v retrieving revision 1.3.6.10 retrieving revision 1.3.6.11 diff -u -r1.3.6.10 -r1.3.6.11 --- squid/src/defines.h 1 Jul 2007 05:44:22 -0000 1.3.6.10 +++ squid/src/defines.h 2 Jul 2007 07:36:58 -0000 1.3.6.11 @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.3.6.10 2007/07/01 05:44:22 amosjeffries Exp $ + * $Id: defines.h,v 1.3.6.11 2007/07/02 07:36:58 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -84,8 +84,6 @@ #define COMM_ERR_CONNECT (-7) #define COMM_ERR_DNS (-8) #define COMM_ERR_CLOSING (-9) -#define COMM_ERR_INV_ARGS (22) -#define COMM_ERR_NOSUPPORT (97) /* Select types. */ #define COMM_SELECT_READ (0x1) @@ -366,18 +364,4 @@ #define DLINK_ISEMPTY(n) ( (n).head == NULL ) #define DLINK_HEAD(n) ( (n).head->data ) -/* - * Macro to compare IPv6 addresses (b is 0, 4, 8, 12) - */ -#define IN6_NTOHL_N(a,b) \ - (ntohl(*(const u_int32_t *)(const void *)(&(a)->s6_addr[(b)]))) - -#define IN6_IS_ADDR_ALLF(a) \ - (IN6_NTOHL_N(a,0) & IN6_NTOHL_N(a,4) & \ - IN6_NTOHL_N(a,8) & IN6_NTOHL_N(a,12) == \ - (u_int32_t)0xffffffff) - -#define SOCKLEN(a) \ - (((struct sockaddr_storage *)(a))->ss_family == AF_INET6 ? \ - sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) #endif /* SQUID_DEFINES_H */ Index: squid/src/delay_pools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/delay_pools.c,v retrieving revision 1.3.6.5 retrieving revision 1.3.6.6 diff -u -r1.3.6.5 -r1.3.6.6 --- squid/src/delay_pools.c 1 Jul 2007 05:44:22 -0000 1.3.6.5 +++ squid/src/delay_pools.c 2 Jul 2007 07:36:58 -0000 1.3.6.6 @@ -1,6 +1,6 @@ /* - * $Id: delay_pools.c,v 1.3.6.5 2007/07/01 05:44:22 amosjeffries Exp $ + * $Id: delay_pools.c,v 1.3.6.6 2007/07/02 07:36:58 amosjeffries Exp $ * * DEBUG: section 77 Delay Pools * AUTHOR: David Luyer @@ -319,8 +319,7 @@ memset(&ch, '\0', sizeof(ch)); ch.conn = http->conn; ch.request = r; - if(r->client_addr.ss_family == AF_INET && - ((struct sockaddr_in *)&r->client_addr)->sin_addr.s_addr == INADDR_BROADCAST) { + if (r->client_addr.s_addr == INADDR_BROADCAST) { debug(77, 2) ("delayClient: WARNING: Called with 'allones' address, ignoring\n"); return delayId(0, 0); } @@ -336,10 +335,7 @@ if (class == 1) return delayId(pool + 1, 0); if (class == 2) { -/* XXX husni host = ntohl(ch.src_addr.s_addr) & 0xff; -*/ - host = 255; if (host == 255) { if (!delay_data[pool].class2->individual_255_used) { delay_data[pool].class2->individual_255_used = 1; @@ -365,10 +361,7 @@ return delayId(pool + 1, i); } /* class == 3 */ -/* XXX husni host = ntohl(ch.src_addr.s_addr) & 0xffff; -*/ - host = 0xffff; net = host >> 8; host &= 0xff; if (net == 255) { Index: squid/src/dns_internal.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/dns_internal.c,v retrieving revision 1.5.6.9 retrieving revision 1.5.6.10 diff -u -r1.5.6.9 -r1.5.6.10 --- squid/src/dns_internal.c 1 Jul 2007 05:44:22 -0000 1.5.6.9 +++ squid/src/dns_internal.c 2 Jul 2007 07:36:59 -0000 1.5.6.10 @@ -1,6 +1,6 @@ /* - * $Id: dns_internal.c,v 1.5.6.9 2007/07/01 05:44:22 amosjeffries Exp $ + * $Id: dns_internal.c,v 1.5.6.10 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 78 DNS lookups; interacts with lib/rfc1035.c * AUTHOR: Duane Wessels @@ -89,13 +89,12 @@ struct _idns_query { hash_link hash; - int ia_cur; rfc1035_query query; char buf[RESOLV_BUFSZ]; char name[NS_MAXDNAME + 1]; char orig[NS_MAXDNAME + 1]; ssize_t sz; - unsigned short id, id_pair; + unsigned short id; int nsends; struct timeval start_t; struct timeval sent_t; @@ -115,7 +114,7 @@ }; struct _ns { - struct sockaddr_storage S; + struct sockaddr_in S; int nqueries; int nreplies; }; @@ -151,7 +150,7 @@ #endif static void idnsCacheQuery(idns_query * q); static void idnsSendQuery(idns_query * q); -static int idnsFromKnownNameserver(struct sockaddr *from); +static int idnsFromKnownNameserver(struct sockaddr_in *from); static idns_query *idnsFindQuery(unsigned short id); static void idnsGrokReply(const char *buf, size_t sz); static PF idnsRead; @@ -162,13 +161,12 @@ static void idnsAddNameserver(const char *buf) { - struct sockaddr_storage A; + struct in_addr A; if (!safe_inet_addr(buf, &A)) { debug(78, 0) ("WARNING: rejecting '%s' as a name server, because it is not a numeric IP address\n", buf); return; } - if ( ((A.ss_family == AF_INET6) && IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)&A)->sin6_addr)) || - ((A.ss_family == AF_INET) && (((struct sockaddr_in *)&A)->sin_addr.s_addr == 0)) ) { + if (A.s_addr == 0) { debug(78, 0) ("WARNING: Squid does not accept 0.0.0.0 in DNS server specifications.\n"); debug(78, 0) ("Will be using 127.0.0.1 instead, assuming you meant that DNS is running on the same machine\n"); safe_inet_addr("127.0.0.1", &A); @@ -187,13 +185,11 @@ safe_free(oldptr); } assert(nns < nns_alloc); - xmemcpy(&nameservers[nns].S, &A, sizeof(struct sockaddr_storage)); - if (A.ss_family == AF_INET) - ((struct sockaddr_in *)&nameservers[nns].S)->sin_port = htons(NS_DEFAULTPORT); - if (A.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&nameservers[nns].S)->sin6_port = htons(NS_DEFAULTPORT); + nameservers[nns].S.sin_family = AF_INET; + nameservers[nns].S.sin_port = htons(NS_DEFAULTPORT); + nameservers[nns].S.sin_addr.s_addr = A.s_addr; debug(78, 3) ("idnsAddNameserver: Added nameserver #%d: %s\n", - nns, sockaddr_ntoa(&nameservers[nns].S)); + nns, inet_ntoa(nameservers[nns].S.sin_addr)); nns++; } @@ -503,7 +499,7 @@ storeAppendPrintf(sentry, "--------------- --------- ---------\n"); for (i = 0; i < nns; i++) { storeAppendPrintf(sentry, "%-15s %9d %9d\n", - sockaddr_ntoa(&nameservers[i].S), + inet_ntoa(nameservers[i].S.sin_addr), nameservers[i].nqueries, nameservers[i].nreplies); } @@ -555,7 +551,6 @@ { int x; int ns; - int DnsSocketTemp; if (DnsSocket < 0) { debug(78, 1) ("idnsSendQuery: Can't send query, no DNS socket!\n"); return; @@ -567,29 +562,21 @@ idnsTcpCleanup(q); try_again: ns = q->nsends % nns; - if (nameservers[ns].S.ss_family == AF_INET6) - DnsSocketTemp = DnsSocket6; - else - DnsSocketTemp = DnsSocket; - - x = comm_udp_sendto(DnsSocketTemp, + x = comm_udp_sendto(DnsSocket, &nameservers[ns].S, - SOCKLEN(&nameservers[ns].S), + sizeof(nameservers[ns].S), q->buf, q->sz); q->nsends++; q->sent_t = current_time; if (x < 0) { debug(50, 1) ("idnsSendQuery: FD %d: sendto: %s\n", - DnsSocketTemp, xstrerror()); + DnsSocket, xstrerror()); if (q->nsends % nns != 0) goto try_again; } else { - fd_bytes(DnsSocketTemp, x, FD_WRITE); -/* - if (q->query.qtype == RFC1035_TYPE_A) -*/ - commSetSelect(DnsSocketTemp, COMM_SELECT_READ, idnsRead, NULL, 0); + fd_bytes(DnsSocket, x, FD_WRITE); + commSetSelect(DnsSocket, COMM_SELECT_READ, idnsRead, NULL, 0); } nameservers[ns].nqueries++; dlinkAdd(q, &q->lru, &lru_list); @@ -597,19 +584,13 @@ } static int -idnsFromKnownNameserver(struct sockaddr *from) +idnsFromKnownNameserver(struct sockaddr_in *from) { int i; for (i = 0; i < nns; i++) { - if (nameservers[i].S.ss_family != from->sa_family) - continue; - if (from->sa_family == AF_INET && - (((struct sockaddr_in *)&nameservers[i].S)->sin_addr.s_addr != ((struct sockaddr_in *)from)->sin_addr.s_addr || - ((struct sockaddr_in *)&nameservers[i].S)->sin_port != ((struct sockaddr_in *)from)->sin_port)) + if (nameservers[i].S.sin_addr.s_addr != from->sin_addr.s_addr) continue; - if (from->sa_family == AF_INET6 && - (!IN6_ARE_ADDR_EQUAL( &((struct sockaddr_in6 *)&nameservers[i].S)->sin6_addr, &((struct sockaddr_in6 *)from)->sin6_addr) || - ((struct sockaddr_in6 *)&nameservers[i].S)->sin6_port != ((struct sockaddr_in6 *)from)->sin6_port)) + if (nameservers[i].S.sin_port != from->sin_port) continue; return i; } @@ -743,29 +724,23 @@ static void idnsRetryTcp(idns_query * q) { - struct sockaddr_storage addr; - char host[100], port[8]; + struct in_addr addr; int ns = (q->nsends - 1) % nns; idnsTcpCleanup(q); - if ((Config.Addrs.udp_outgoing.ss_family == AF_INET6 && -!IN6_IS_ADDR_ALLF(&((struct sockaddr_in6 *)&Config.Addrs.udp_outgoing)->sin6_addr)) - || (Config.Addrs.udp_outgoing.ss_family == AF_INET && - ((struct sockaddr_in *)&Config.Addrs.udp_outgoing)->sin_addr.s_addr != no_addr.s_addr)) - xmemcpy(&addr, &Config.Addrs.udp_outgoing, sizeof(addr)); + if (Config.Addrs.udp_outgoing.s_addr != no_addr.s_addr) + addr = Config.Addrs.udp_outgoing; else - xmemcpy(&addr, &Config.Addrs.udp_incoming, sizeof(addr)); + addr = Config.Addrs.udp_incoming; q->tcp_socket = comm_open(SOCK_STREAM, IPPROTO_TCP, - &addr, + addr, + 0, COMM_NONBLOCKING, "DNS TCP Socket"); dlinkAdd(q, &q->lru, &lru_list); - q->ia_cur = -1; commConnectStart(q->tcp_socket, - sockaddr_ntoa(&addr), - addr.ss_family == AF_INET6 ? - ntohs(((struct sockaddr_in6 *)&addr)->sin6_port) : - ntohs(((struct sockaddr_in *)&addr)->sin_port) , + inet_ntoa(nameservers[ns].S.sin_addr), + ntohs(nameservers[ns].S.sin_port), idnsSendTcpQuery, q, NULL @@ -777,7 +752,7 @@ { int n; rfc1035_message *message = NULL; - idns_query *q, *q_pair; + idns_query *q; n = rfc1035MessageUnpack(buf, sz, &message); @@ -794,9 +769,6 @@ rfc1035MessageDestroy(message); return; } - - q_pair = idnsFindQuery(q->id_pair); - if (rfc1035QueryCompare(&q->query, message->query) != 0) { debug(78, 3) ("idnsGrokReply: Query mismatch (%s != %s)\n", q->query.name, message->query->name); rfc1035MessageDestroy(message); @@ -856,19 +828,11 @@ return; } } - if (q_pair) - n = n + 10000; - debug(78, 3) ("idnsGrokReply: id %d pair %d: %d\n", q->id, q_pair ? q->id_pair: -1, n); idnsCallback(q, message->answer, n, q->error); rfc1035MessageDestroy(message); idnsTcpCleanup(q); - if (!q_pair) { - cbdataFree(q); -/* - cbdataFree(q_pair); -*/ - } + cbdataFree(q); } static void @@ -876,7 +840,7 @@ { int *N = &incoming_sockets_accepted; ssize_t len; - struct sockaddr_storage from; + struct sockaddr_in from; socklen_t from_len; int max = INCOMING_DNS_MAX; static char rbuf[SQUID_UDP_SO_RCVBUF]; @@ -902,13 +866,13 @@ fd, xstrerror()); break; } - fd_bytes(fd, len, FD_READ); + fd_bytes(DnsSocket, len, FD_READ); assert(N); (*N)++; debug(78, 3) ("idnsRead: FD %d: received %d bytes from %s.\n", fd, (int) len, - sockaddr_ntoa(&from)); + inet_ntoa(from.sin_addr)); ns = idnsFromKnownNameserver(&from); if (ns >= 0) { nameservers[ns].nreplies++; @@ -916,7 +880,7 @@ static time_t last_warning = 0; if (squid_curtime - last_warning > 60) { debug(78, 1) ("WARNING: Reply from unknown nameserver [%s]\n", - sockaddr_ntoa(&from)); + inet_ntoa(from.sin_addr)); last_warning = squid_curtime; } continue; @@ -924,7 +888,7 @@ idnsGrokReply(rbuf, len); } if (lru_list.head) - commSetSelect(fd, COMM_SELECT_READ, idnsRead, NULL, 0); + commSetSelect(DnsSocket, COMM_SELECT_READ, idnsRead, NULL, 0); } static void @@ -986,15 +950,15 @@ CBDATA_INIT_TYPE(idns_query); if (DnsSocket < 0) { int port; - struct sockaddr_storage addr; - memset(&addr, 0, sizeof(addr)); - addr.ss_family = AF_INET; -#if defined(_SQUID_FREEBSD_) || defined(_SQUID_NETBSD_) || defined(_SQUID_OPENBSD_) - addr.ss_len = sizeof(struct sockaddr_in); -#endif + struct in_addr addr; + if (Config.Addrs.udp_outgoing.s_addr != no_addr.s_addr) + addr = Config.Addrs.udp_outgoing; + else + addr = Config.Addrs.udp_incoming; DnsSocket = comm_open(SOCK_DGRAM, IPPROTO_UDP, - &addr, + addr, + 0, COMM_NONBLOCKING, "DNS Socket"); if (DnsSocket < 0) @@ -1004,32 +968,9 @@ */ port = comm_local_port(DnsSocket); debug(78, 1) ("DNS Socket created at %s, port %d, FD %d\n", - sockaddr_ntoa(&addr), + inet_ntoa(addr), port, DnsSocket); } - if (DnsSocket6 < 0) { - int port; - struct sockaddr_storage addr; - memset(&addr, 0, sizeof(addr)); - addr.ss_family = AF_INET6; -#if defined(_SQUID_FREEBSD_) || defined(_SQUID_NETBSD_) || defined(_SQUID_OPENBSD_) - addr.ss_len = sizeof(struct sockaddr_in6); -#endif - DnsSocket6 = comm_open(SOCK_DGRAM, - IPPROTO_UDP, - &addr, - COMM_NONBLOCKING, - "DNS Socket v6"); - if (DnsSocket < 0) - fatal("Could not create a DNS socket"); - /* Ouch... we can't call functions using debug from a debug - * statement. Doing so messes up the internal _db_level - */ - port = comm_local_port(DnsSocket6); - debug(78, 1) ("DNS Socket v6 created at %s, port %d, FD %d\n", - sockaddr_ntoa(&addr), - port, DnsSocket6); - } assert(0 == nns); idnsParseNameservers(); #ifndef _SQUID_MSWIN_ @@ -1064,12 +1005,10 @@ void idnsShutdown(void) { - if (DnsSocket < 0 && DnsSocket6 < 0) + if (DnsSocket < 0) return; comm_close(DnsSocket); - comm_close(DnsSocket6); DnsSocket = -1; - DnsSocket6 = -1; idnsFreeNameservers(); idnsFreeSearchpath(); } @@ -1098,57 +1037,6 @@ hash_join(idns_lookup_hash, &q->hash); } -static void -idnsAAAALookup(const char *name, IDNSCB * callback, void *data, unsigned short id_pair, unsigned short id) -{ - unsigned int i; - int nd = 0; - idns_query *q; - q = cbdataAlloc(idns_query); - q->tcp_socket = -1; - q->id = id; - q->id_pair = id_pair; - - for (i = 0; i < strlen(name); i++) { - if (name[i] == '.') { - nd++; - } - } - - if (Config.onoff.res_defnames && npc > 0 && name[strlen(name) - 1] != '.') { - q->do_searchpath = 1; - } else { - q->do_searchpath = 0; - } - strcpy(q->orig, name); - strcpy(q->name, q->orig); - if (q->do_searchpath && nd < ndots) { - q->domain = 0; - strcat(q->name, "."); - strcat(q->name, searchpath[q->domain].domain); - debug(78, 3) ("idnsALookup: searchpath used for %s\n", - q->name); - } - q->sz = rfc1035BuildAAAAQuery(q->name, q->buf, sizeof(q->buf), q->id, - &q->query); - - if (q->sz < 0) { - /* problem with query data -- query not sent */ - callback(data, NULL, 0, "Internal error"); - cbdataFree(q); - return; - } - debug(78, 3) ("idnsAAAALookup: buf is %d bytes for %s, id = %#hx\n", - (int) q->sz, q->name, q->id); - q->callback = callback; - q->callback_data = data; - cbdataLock(q->callback_data); - q->start_t = current_time; - idnsCacheQuery(q); - idnsSendQuery(q); -} - - void idnsALookup(const char *name, IDNSCB * callback, void *data) { @@ -1160,7 +1048,6 @@ q = cbdataAlloc(idns_query); q->tcp_socket = -1; q->id = idnsQueryID(); - q->id_pair = idnsQueryID(); for (i = 0; i < strlen(name); i++) { if (name[i] == '.') { @@ -1199,14 +1086,13 @@ q->start_t = current_time; idnsCacheQuery(q); idnsSendQuery(q); - idnsAAAALookup(name, callback, data, q->id, q->id_pair); } void -idnsPTRLookup(const struct sockaddr *addr, IDNSCB * callback, void *data) +idnsPTRLookup(const struct in_addr addr, IDNSCB * callback, void *data) { idns_query *q; - const char *ip = sockaddr_ntoa(addr); + const char *ip = inet_ntoa(addr); q = cbdataAlloc(idns_query); q->tcp_socket = -1; q->id = idnsQueryID(); Index: squid/src/errorpage.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/errorpage.c,v retrieving revision 1.5.2.8 retrieving revision 1.5.2.9 diff -u -r1.5.2.8 -r1.5.2.9 --- squid/src/errorpage.c 1 Jul 2007 05:44:22 -0000 1.5.2.8 +++ squid/src/errorpage.c 2 Jul 2007 07:36:59 -0000 1.5.2.9 @@ -1,6 +1,6 @@ /* - * $Id: errorpage.c,v 1.5.2.8 2007/07/01 05:44:22 amosjeffries Exp $ + * $Id: errorpage.c,v 1.5.2.9 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -507,7 +507,7 @@ p = "[unknown host]"; break; case 'i': - memBufPrintf(&mb, "%s", sockaddr_ntoa(&err->src_addr)); + memBufPrintf(&mb, "%s", inet_ntoa(err->src_addr)); break; case 'I': if (r && r->hier.host) { Index: squid/src/external_acl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/external_acl.c,v retrieving revision 1.12.2.3 retrieving revision 1.12.2.4 diff -u -r1.12.2.3 -r1.12.2.4 --- squid/src/external_acl.c 1 Jul 2007 05:44:22 -0000 1.12.2.3 +++ squid/src/external_acl.c 2 Jul 2007 07:36:59 -0000 1.12.2.4 @@ -1,6 +1,6 @@ /* - * $Id: external_acl.c,v 1.12.2.3 2007/07/01 05:44:22 amosjeffries Exp $ + * $Id: external_acl.c,v 1.12.2.4 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 82 External ACL * AUTHOR: Henrik Nordstrom, MARA Systems AB @@ -643,14 +643,14 @@ break; #endif case EXT_ACL_SRC: - str = sockaddr_ntoa(&ch->src_addr); + str = inet_ntoa(ch->src_addr); break; case EXT_ACL_SRCPORT: snprintf(buf, sizeof(buf), "%d", request->client_port); str = buf; break; case EXT_ACL_MYADDR: - str = sockaddr_ntoa(&request->my_addr); + str = inet_ntoa(request->my_addr); break; case EXT_ACL_MYPORT: snprintf(buf, sizeof(buf), "%d", request->my_port); Index: squid/src/forward.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/forward.c,v retrieving revision 1.4.6.9 retrieving revision 1.4.6.10 diff -u -r1.4.6.9 -r1.4.6.10 --- squid/src/forward.c 1 Jul 2007 08:34:28 -0000 1.4.6.9 +++ squid/src/forward.c 2 Jul 2007 07:36:59 -0000 1.4.6.10 @@ -1,6 +1,6 @@ /* - * $Id: forward.c,v 1.4.6.9 2007/07/01 08:34:28 amosjeffries Exp $ + * $Id: forward.c,v 1.4.6.10 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 17 Request Forwarding * AUTHOR: Duane Wessels @@ -351,15 +351,6 @@ err->dnsserver_msg = xstrdup(dns_error_message); fwdFail(fwdState, err); comm_close(server_fd); - } else if (status == COMM_ERR_INV_ARGS) { - assert(fs); - err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE, fwdState->request); - err->xerrno = errno; - fwdState->server_fd_was_inv_args = 1; - fwdFail(fwdState, err); - if (fs->peer) - peerConnectFailed(fs->peer); - comm_close(server_fd); } else if (status != COMM_OK) { assert(fs); err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE, fwdState->request); @@ -406,20 +397,17 @@ comm_close(fd); } -static struct sockaddr_storage * +static struct in_addr aclMapAddr(acl_address * head, aclCheck_t * ch) { acl_address *l; - struct sockaddr_storage *addr; - struct sockaddr_in *addr4; + struct in_addr addr; aclChecklistCacheInit(ch); for (l = head; l; l = l->next) { if (aclMatchAclList(l->acl_list, ch)) - return &l->addr; + return l->addr; } - addr = xmalloc(sizeof(struct sockaddr_storage)); - addr4 = (struct sockaddr_in *)addr; - addr4->sin_addr.s_addr = INADDR_ANY; + addr.s_addr = INADDR_ANY; return addr; } @@ -435,7 +423,7 @@ return 0; } -struct sockaddr_storage * +struct in_addr getOutgoingAddr(request_t * request) { aclCheck_t ch; @@ -467,13 +455,11 @@ FwdServer *fs = fwdState->servers; const char *host; const char *name; - char portstr[8]; unsigned short port; const char *domain = NULL; int ctimeout; int ftimeout = Config.Timeout.forward - (squid_curtime - fwdState->start); - struct sockaddr_storage outgoing, peerinfo; - struct addrinfo hints, *res; + struct in_addr outgoing; unsigned short tos; #if LINUX_TPROXY struct in_tproxy itp; @@ -482,9 +468,6 @@ assert(fs); assert(fwdState->server_fd == -1); debug(17, 3) ("fwdConnectStart: %s\n", url); - debug(17, 3) (" fwdState: 0x%x was IPv4: %d tries: %d err: %d\n", - fwdState, fwdState->server_fd_was_v4, fwdState->n_tries, - fwdState->err ? fwdState->err->xerrno : 0); if (fs->peer) { host = fs->peer->host; name = fs->peer->name; @@ -533,7 +516,7 @@ fd = pconnPop(name, port, domain, &fwdState->request->client_addr, 0); #endif if (fd == -1) - fd = pconnPop(name, port, domain, NULL); + fd = pconnPop(name, port, domain, NULL, 0); if (fd != -1) { /* Don't cache if the returned fd does not have valid DNS */ if (fd_table[fd].flags.dnsfailed) @@ -564,46 +547,17 @@ #if URL_CHECKSUM_DEBUG assert(fwdState->entry->mem_obj->chksum == url_checksum(url)); #endif - - if (fwdState->server_fd_was_inv_args) { - fwdState->n_tries--; - if (!fs->peer) - fwdState->origin_tries--; - } - else - fwdState->ia_cur = -1; - memset(&outgoing, 0, sizeof(outgoing)); - if (fwdState->server_fd_was_v4) - outgoing.ss_family = fwdState->server_fd_was_inv_args ? - AF_INET6 : AF_INET ; - else - outgoing.ss_family = fwdState->server_fd_was_inv_args ? - AF_INET : AF_INET6 ; - - fwdState->server_fd_was_inv_args = 0; - if (fs->peer && fs->peer->in_addr.ss_family == AF_INET6) - outgoing.ss_family = AF_INET6; - if (outgoing.ss_family == AF_INET) - fwdState->server_fd_was_v4 = 1; - else - fwdState->server_fd_was_v4 = 0; -#if defined(_SQUID_FREEBSD_) || defined(_SQUID_NETBSD_) || defined(_SQUID_OPENBSD_) - outgoing.ss_len = outgoing.ss_family == AF_INET6 ? - sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in); -#endif - tos = 0; -/* HUSNI skip ACL outgoing = getOutgoingAddr(fwdState->request); tos = getOutgoingTOS(fwdState->request); -*/ fwdState->request->out_ip = outgoing; debug(17, 3) ("fwdConnectStart: got addr %s, tos %d\n", - sockaddr_ntoa(&outgoing), tos); + inet_ntoa(outgoing), tos); fd = comm_openex(SOCK_STREAM, IPPROTO_TCP, - &outgoing, + outgoing, + 0, COMM_NONBLOCKING, tos, url); @@ -872,8 +826,7 @@ * from peer_digest.c, asn.c, netdb.c, etc and should always * be allowed. yuck, I know. */ - if (((struct sockaddr_in *)&r->client_addr)->sin_addr.s_addr != no_addr.s_addr - && r->protocol != PROTO_INTERNAL && r->protocol != PROTO_CACHEOBJ) { + if (r->client_addr.s_addr != no_addr.s_addr && r->protocol != PROTO_INTERNAL && r->protocol != PROTO_CACHEOBJ) { /* * Check if this host is allowed to fetch MISSES from us (miss_access) */ @@ -926,7 +879,9 @@ #if LINUX_TPROXY /* If we need to transparently proxy the request * then we need the client source address and port */ - xmemcpy(&fwdState->src, &r->client_addr, sizeof(struct sockaddr_storage)); + fwdState->src.sin_family = AF_INET; + fwdState->src.sin_addr = r->client_addr; + fwdState->src.sin_port = r->client_port; #endif storeLockObject(e); @@ -1000,11 +955,6 @@ err_type_str[errorState->type], httpStatusString(errorState->http_status), storeUrl(fwdState->entry)); - if (fwdState->server_fd_was_inv_args) { - errorStateFree(errorState); - return; - } - fwdState->server_fd_was_inv_args = 0; if (fwdState->err) errorStateFree(fwdState->err); fwdState->err = errorState; Index: squid/src/fqdncache.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fqdncache.c,v retrieving revision 1.4.6.7 retrieving revision 1.4.6.8 diff -u -r1.4.6.7 -r1.4.6.8 --- squid/src/fqdncache.c 1 Jul 2007 05:44:22 -0000 1.4.6.7 +++ squid/src/fqdncache.c 2 Jul 2007 07:36:59 -0000 1.4.6.8 @@ -1,6 +1,6 @@ /* - * $Id: fqdncache.c,v 1.4.6.7 2007/07/01 05:44:22 amosjeffries Exp $ + * $Id: fqdncache.c,v 1.4.6.8 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 35 FQDN Cache * AUTHOR: Harvest Derived @@ -351,12 +351,11 @@ } void -fqdncache_nbgethostbyaddr(struct sockaddr *addr, FQDNH * handler, void *handlerData) +fqdncache_nbgethostbyaddr(struct in_addr addr, FQDNH * handler, void *handlerData) { fqdncache_entry *f = NULL; - char name[80]; + char *name = inet_ntoa(addr); generic_cbdata *c; - getnameinfo(addr, SOCKLEN(addr), name, 80, NULL, 0, NULL); assert(handler); debug(35, 4) ("fqdncache_nbgethostbyaddr: Name '%s'.\n", name); FqdncacheStats.requests++; @@ -428,12 +427,11 @@ } const char * -fqdncache_gethostbyaddr(struct sockaddr *addr, int flags) +fqdncache_gethostbyaddr(struct in_addr addr, int flags) { - char name[80]; + char *name = inet_ntoa(addr); fqdncache_entry *f = NULL; struct in_addr ip; - getnameinfo(addr, SOCKLEN(addr), name, 80, NULL, 0, NULL); assert(name); FqdncacheStats.requests++; f = fqdncache_get(name); @@ -454,7 +452,7 @@ } dns_error_message = NULL; /* check if it's already a FQDN address in text form. */ - if (!safe_inet_addr(name, &ip)) + if (!safe_inet_addr(name, &ip)) return name; FqdncacheStats.misses++; if (flags & FQDN_LOOKUP_IF_MISS) @@ -508,13 +506,13 @@ } const char * -fqdnFromAddr(struct sockaddr *addr) +fqdnFromAddr(struct in_addr addr) { const char *n; - static char buf[80]; + static char buf[32]; if (Config.onoff.log_fqdn && (n = fqdncache_gethostbyaddr(addr, 0))) return n; - xstrncpy(buf, sockaddr_ntoa(addr), 80); + xstrncpy(buf, inet_ntoa(addr), 32); return buf; } Index: squid/src/ftp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ftp.c,v retrieving revision 1.5.2.9 retrieving revision 1.5.2.10 diff -u -r1.5.2.9 -r1.5.2.10 --- squid/src/ftp.c 1 Jul 2007 05:44:22 -0000 1.5.2.9 +++ squid/src/ftp.c 2 Jul 2007 07:36:59 -0000 1.5.2.10 @@ -1,6 +1,6 @@ /* - * $Id: ftp.c,v 1.5.2.9 2007/07/01 05:44:22 amosjeffries Exp $ + * $Id: ftp.c,v 1.5.2.10 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -81,8 +81,6 @@ }; typedef struct _Ftpdata { - hash_link hash; /* dummy, must be fist */ - int ia_cur; StoreEntry *entry; request_t *request; char user[MAX_URL]; @@ -1069,11 +1067,7 @@ strCat(ftpState->title_url, ftpState->user); strCat(ftpState->title_url, "@"); } - if (strchr(request->host, ':')) - strCat(ftpState->title_url, "["); strCat(ftpState->title_url, request->host); - if (strchr(request->host, ':')) - strCat(ftpState->title_url, "]"); if (request->port != urlDefaultPort(PROTO_FTP)) { strCat(ftpState->title_url, ":"); strCat(ftpState->title_url, xitoa(request->port)); @@ -1733,7 +1727,7 @@ ftpSendPasv(FtpStateData * ftpState) { int fd; - struct sockaddr_storage addr; + struct sockaddr_in addr; socklen_t addr_len; if (ftpState->request->method == METHOD_HEAD && (ftpState->flags.isdir || ftpState->size != -1)) { /* Terminate here for HEAD requests */ @@ -1766,14 +1760,10 @@ return; } /* Open data channel with the same local address as control channel */ - if (addr.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&addr)->sin6_port = 0; - else - ((struct sockaddr_in *)&addr)->sin_port = 0; - fd = comm_open(SOCK_STREAM, IPPROTO_TCP, - &addr, + addr.sin_addr, + 0, COMM_NONBLOCKING, storeUrl(ftpState->entry)); debug(9, 3) ("ftpSendPasv: Unconnected data socket created on FD %d\n", fd); @@ -1792,10 +1782,7 @@ * managed correctly and comm close handlers are cbdata fenced */ ftpState->data.fd = fd; - if (addr.ss_family == AF_INET6) - snprintf(cbuf, 1024, "EPSV\r\n"); - else - snprintf(cbuf, 1024, "PASV\r\n"); + snprintf(cbuf, 1024, "PASV\r\n"); ftpWriteCommand(cbuf, ftpState); ftpState->state = SENT_PASV; /* @@ -1816,22 +1803,12 @@ int fd = ftpState->data.fd; char *buf; LOCAL_ARRAY(char, ipaddr, 1024); - struct sockaddr_storage ipaddr_sock; - socklen_t addr_len; debug(9, 3) ("This is ftpReadPasv\n"); - addr_len = sizeof(ipaddr_sock); - if (getsockname(ftpState->ctrl.fd, (struct sockaddr *) &ipaddr_sock, &addr_len)) { - debug(9, 0) ("ftpSendPasv: getsockname(%d,..): %s\n", - ftpState->ctrl.fd, xstrerror()); - ftpFail(ftpState); - return; - } - if (code != 227 && code != 229) { + if (code != 227) { debug(9, 3) ("PASV not supported by remote end\n"); ftpSendPort(ftpState); return; } - if (code == 227) { /* 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2). */ /* ANSI sez [^0-9] is undefined, it breaks on Watcom cc */ debug(9, 5) ("scanning: %s\n", ftpState->ctrl.last_reply); @@ -1843,24 +1820,12 @@ return; } snprintf(ipaddr, 1024, "%d.%d.%d.%d", h1, h2, h3, h4); - port = ((p1 << 8) + p2); - memset(&ipaddr_sock, 0, sizeof(ipaddr_sock)); - if (!safe_inet_addr(ipaddr, &ipaddr_sock)) { + if (!safe_inet_addr(ipaddr, NULL)) { debug(9, 1) ("Unsafe PASV reply from %s: %s\n", fd_table[ftpState->ctrl.fd].ipaddr, ftpState->ctrl.last_reply); ftpSendPort(ftpState); return; } - } - if (code == 229) { - debug(9, 5) ("scanning: %s\n", ftpState->ctrl.last_reply); - buf = ftpState->ctrl.last_reply + strcspn(ftpState->ctrl.last_reply, "("); - n = sscanf(buf, "(|||%d||)",&p1); - port = p1; - } - if (ipaddr_sock.ss_family == AF_INET) - ((struct sockaddr_in *)&ipaddr_sock)->sin_port = htons(port); - if (ipaddr_sock.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&ipaddr_sock)->sin6_port = htons(port); + port = ((p1 << 8) + p2); if (0 == port) { debug(9, 1) ("Unsafe PASV reply from %s: %s\n", fd_table[ftpState->ctrl.fd].ipaddr, ftpState->ctrl.last_reply); ftpSendPort(ftpState); @@ -1877,13 +1842,12 @@ if (Config.Ftp.sanitycheck) ftpState->data.host = xstrdup(fd_table[ftpState->ctrl.fd].ipaddr); else - ftpState->data.host = xstrdup(sockaddr_ntoa(&ipaddr_sock)); + ftpState->data.host = xstrdup(ipaddr); safe_free(ftpState->ctrl.last_command); safe_free(ftpState->ctrl.last_reply); ftpState->ctrl.last_command = xstrdup("Connect to server data port"); - ftpState->ia_cur = -1; debug(9, 5) ("ftpReadPasv: connecting to %s, port %d\n", ftpState->data.host, ftpState->data.port); - commConnectStart(fd, ftpState->data.host, port, ftpPasvCallback, ftpState, NULL); + commConnectStart(fd, ipaddr, port, ftpPasvCallback, ftpState, NULL); } static void @@ -1906,7 +1870,7 @@ ftpOpenListenSocket(FtpStateData * ftpState, int fallback) { int fd; - struct sockaddr_storage addr; + struct sockaddr_in addr; socklen_t addr_len; int on = 1; u_short port = 0; @@ -1934,13 +1898,12 @@ */ if (fallback) { setsockopt(ftpState->ctrl.fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)); - port = (addr.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&addr)->sin6_port) : - ntohs(((struct sockaddr_in *)&addr)->sin_port); + port = ntohs(addr.sin_port); } fd = comm_open(SOCK_STREAM, IPPROTO_TCP, - &addr, + addr.sin_addr, + port, COMM_NONBLOCKING | (fallback ? COMM_REUSEADDR : 0), storeUrl(ftpState->entry)); debug(9, 3) ("ftpOpenListenSocket: Unconnected data socket created on FD %d\n", fd); @@ -1962,7 +1925,7 @@ ftpSendPort(FtpStateData * ftpState) { int fd; - struct sockaddr_storage addr; + struct sockaddr_in addr; socklen_t addr_len; unsigned char *addrptr; unsigned char *portptr; @@ -1976,18 +1939,11 @@ ftpFail(ftpState); return; } - if (addr.ss_family == AF_INET) { - addrptr = (unsigned char *) &((struct sockaddr_in *)&addr)->sin_addr.s_addr; - portptr = (unsigned char *) &((struct sockaddr_in *)&addr)->sin_port; + addrptr = (unsigned char *) &addr.sin_addr.s_addr; + portptr = (unsigned char *) &addr.sin_port; snprintf(cbuf, 1024, "PORT %d,%d,%d,%d,%d,%d\r\n", addrptr[0], addrptr[1], addrptr[2], addrptr[3], portptr[0], portptr[1]); - } - if (addr.ss_family == AF_INET6) { - snprintf(cbuf, 1024, "EPRT |2|%s|%u|\r\n", - sockaddr_ntoa(&addr), - ntohs(((struct sockaddr_in6 *)&addr)->sin6_port)); - } ftpWriteCommand(cbuf, ftpState); ftpState->state = SENT_PORT; } @@ -2010,7 +1966,7 @@ ftpAcceptDataConnection(int fd, void *data) { FtpStateData *ftpState = data; - struct sockaddr_storage my_peer, me; + struct sockaddr_in my_peer, me; debug(9, 3) ("ftpAcceptDataConnection\n"); if (EBIT_TEST(ftpState->entry->flags, ENTRY_ABORTED)) { @@ -2019,9 +1975,9 @@ } fd = comm_accept(fd, &my_peer, &me); if (Config.Ftp.sanitycheck) { - char *ipaddr = sockaddr_ntoa(&my_peer); + char *ipaddr = inet_ntoa(my_peer.sin_addr); if (strcmp(fd_table[ftpState->ctrl.fd].ipaddr, ipaddr) != 0) { - debug(9, 1) ("FTP data connection from unexpected server (%s:%d), expecting %s\n", ipaddr, (int) 0/*ntohs(my_peer.sin_port)*/, fd_table[ftpState->ctrl.fd].ipaddr); + debug(9, 1) ("FTP data connection from unexpected server (%s:%d), expecting %s\n", ipaddr, (int) ntohs(my_peer.sin_port), fd_table[ftpState->ctrl.fd].ipaddr); comm_close(fd); commSetSelect(ftpState->data.fd, COMM_SELECT_READ, @@ -2041,10 +1997,8 @@ comm_close(ftpState->data.fd); debug(9, 3) ("ftpAcceptDataConnection: Connected data socket on FD %d\n", fd); ftpState->data.fd = fd; - ftpState->data.port = (my_peer.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&my_peer)->sin6_port) : - ntohs(((struct sockaddr_in *)&my_peer)->sin_port); - ftpState->data.host = xstrdup(sockaddr_ntoa(&my_peer)); + ftpState->data.port = ntohs(my_peer.sin_port); + ftpState->data.host = xstrdup(inet_ntoa(my_peer.sin_addr)); commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); commSetTimeout(ftpState->data.fd, Config.Timeout.read, ftpTimeout, ftpState); Index: squid/src/globals.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/globals.h,v retrieving revision 1.4.4.7 retrieving revision 1.4.4.8 diff -u -r1.4.4.7 -r1.4.4.8 --- squid/src/globals.h 1 Jul 2007 05:44:22 -0000 1.4.4.7 +++ squid/src/globals.h 2 Jul 2007 07:36:59 -0000 1.4.4.8 @@ -1,6 +1,6 @@ /* - * $Id: globals.h,v 1.4.4.7 2007/07/01 05:44:22 amosjeffries Exp $ + * $Id: globals.h,v 1.4.4.8 2007/07/02 07:36:59 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -97,9 +97,6 @@ extern int theInIcpConnection; /* -1 */ extern int theOutIcpConnection; /* -1 */ extern int DnsSocket; /* -1 */ -extern int theInIcpConnection6; /* -1 */ -extern int theOutIcpConnection6; /* -1 */ -extern int DnsSocket6; /* -1 */ #ifdef SQUID_SNMP extern int theInSnmpConnection; /* -1 */ extern int theOutSnmpConnection; /* -1 */ @@ -111,8 +108,7 @@ extern struct in_addr any_addr; extern struct in_addr local_addr; extern struct in_addr no_addr; -extern struct sockaddr_storage theOutICPAddr; -extern struct sockaddr_storage theOutICPAddr6; +extern struct in_addr theOutICPAddr; extern struct in_addr theOutSNMPAddr; extern struct timeval current_time; extern struct timeval squid_start; Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.5.2.7 retrieving revision 1.5.2.8 diff -u -r1.5.2.7 -r1.5.2.8 --- squid/src/http.c 1 Jul 2007 05:44:22 -0000 1.5.2.7 +++ squid/src/http.c 2 Jul 2007 07:36:59 -0000 1.5.2.8 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.5.2.7 2007/07/01 05:44:22 amosjeffries Exp $ + * $Id: http.c,v 1.5.2.8 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -804,11 +804,11 @@ clientPinConnection(orig_request->pinned_connection, fd, orig_request, httpState->peer, request->flags.connection_auth); } else if (httpState->peer) { if (httpState->peer->options.originserver) - pconnPush(fd, httpState->peer->name, httpState->peer->http_port, httpState->orig_request->host, client_addr); + pconnPush(fd, httpState->peer->name, httpState->peer->http_port, httpState->orig_request->host, client_addr, client_port); else - pconnPush(fd, httpState->peer->name, httpState->peer->http_port, NULL, client_addr); + pconnPush(fd, httpState->peer->name, httpState->peer->http_port, NULL, client_addr, client_port); } else { - pconnPush(fd, request->host, request->port, NULL, client_addr); + pconnPush(fd, request->host, request->port, NULL, client_addr, client_port); } fwdComplete(httpState->fwd); httpState->fd = -1; @@ -1211,18 +1211,10 @@ } /* append X-Forwarded-For */ if (opt_forwarded_for) { - char orig_forward[100] = "unknown"; - if (opt_forwarded_for) { - if ((orig_request->client_addr.ss_family == AF_INET) && - (((struct sockaddr_in *)&orig_request->client_addr)->sin_addr.s_addr != no_addr.s_addr) ) - strncpy(orig_forward, sockaddr_ntoa(&orig_request->client_addr), 100); - if ((orig_request->client_addr.ss_family == AF_INET6) && - !IN6_IS_ADDR_ALLF(&((struct sockaddr_in6 *)&orig_request->client_addr)->sin6_addr)) - strncpy(orig_forward, sockaddr_ntoa(&orig_request->client_addr), - 100); - } strFwd = httpHeaderGetList(hdr_in, HDR_X_FORWARDED_FOR); - strListAdd(&strFwd, orig_forward, ','); + strListAdd(&strFwd, + (((orig_request->client_addr.s_addr != no_addr.s_addr) && opt_forwarded_for) ? + inet_ntoa(orig_request->client_addr) : "unknown"), ','); httpHeaderPutStr(hdr_out, HDR_X_FORWARDED_FOR, strBuf(strFwd)); stringClean(&strFwd); } @@ -1544,7 +1536,7 @@ if (httpState->reply_hdr_state >= 2 && !httpState->flags.abuse_detected) { httpState->flags.abuse_detected = 1; debug(11, 1) ("httpSendRequestEntryDone: Likely proxy abuse detected '%s' -> '%s'\n", - sockaddr_ntoa(&httpState->orig_request->client_addr), + inet_ntoa(httpState->orig_request->client_addr), storeUrl(httpState->entry)); if (httpState->entry->mem_obj->reply->sline.status == HTTP_INVALID_HEADER) { memFree8K(buf); Index: squid/src/icp_v2.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/icp_v2.c,v retrieving revision 1.3.6.7 retrieving revision 1.3.6.8 diff -u -r1.3.6.7 -r1.3.6.8 --- squid/src/icp_v2.c 1 Jul 2007 08:34:28 -0000 1.3.6.7 +++ squid/src/icp_v2.c 2 Jul 2007 07:36:59 -0000 1.3.6.8 @@ -1,6 +1,6 @@ /* - * $Id: icp_v2.c,v 1.3.6.7 2007/07/01 08:34:28 amosjeffries Exp $ + * $Id: icp_v2.c,v 1.3.6.8 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -35,8 +35,8 @@ #include "squid.h" -static void icpLogIcp(struct sockaddr *, log_type, int, const char *, int); -static void icpHandleIcpV2(int, struct sockaddr *, char *, int); +static void icpLogIcp(struct in_addr, log_type, int, const char *, int); +static void icpHandleIcpV2(int, struct sockaddr_in, char *, int); static void icpCount(void *, int, size_t, int); /* @@ -46,7 +46,7 @@ static icpUdpData *IcpQueueTail = NULL; static void -icpLogIcp(struct sockaddr *caddr, log_type logcode, int len, const char *url, int delay) +icpLogIcp(struct in_addr caddr, log_type logcode, int len, const char *url, int delay) { AccessLogEntry al; if (LOG_TAG_NONE == logcode) @@ -59,7 +59,7 @@ memset(&al, '\0', sizeof(al)); al.icp.opcode = ICP_QUERY; al.url = url; - xmemcpy(&al.cache.caddr, caddr, SOCKLEN(caddr)); + al.cache.caddr = caddr; al.cache.size = len; al.cache.code = logcode; al.cache.msec = delay; @@ -106,7 +106,7 @@ headerp->reqnum = htonl(reqnum); headerp->flags = htonl(flags); headerp->pad = htonl(pad); - xmemcpy(&headerp->shostid, &theOutICPAddr, sizeof(struct sockaddr_storage)); + headerp->shostid = theOutICPAddr.s_addr; urloffset = buf + sizeof(icp_common_t); if (opcode == ICP_QUERY) urloffset += sizeof(u_num32); @@ -116,7 +116,7 @@ int icpUdpSend(int fd, - const struct sockaddr *to, + const struct sockaddr_in *to, icp_common_t * msg, log_type logcode, int delay) @@ -124,25 +124,23 @@ icpUdpData *queue; int x; int len; - char host[100], port[8]; len = (int) ntohs(msg->length); - getnameinfo(to, SOCKLEN(to), host, 100, port, 8, NI_NUMERICHOST|NI_NUMERICSERV); - debug(12, 5) ("icpUdpSend: FD %d sending %s, %d bytes to %s:%s\n", + debug(12, 5) ("icpUdpSend: FD %d sending %s, %d bytes to %s:%d\n", fd, icp_opcode_str[msg->opcode], len, - host, - port); - x = comm_udp_sendto(fd, to, SOCKLEN(to), msg, len); + inet_ntoa(to->sin_addr), + ntohs(to->sin_port)); + x = comm_udp_sendto(fd, to, sizeof(*to), msg, len); if (x >= 0) { /* successfully written */ - icpLogIcp(to, logcode, len, (char *) (msg + 1), delay); + icpLogIcp(to->sin_addr, 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 = xcalloc(1, sizeof(icpUdpData)); - xmemcpy(&queue->address, to, SOCKLEN(to)); + queue->address = *to; queue->msg = msg; queue->len = (int) ntohs(msg->length); queue->queue_time = current_time; @@ -181,7 +179,7 @@ } static void -icpHandleIcpV2(int fd, struct sockaddr *from, char *buf, int len) +icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len) { icp_common_t header; StoreEntry *entry = NULL; @@ -226,23 +224,22 @@ break; } memset(&checklist, '\0', sizeof(checklist)); - xmemcpy(&checklist.src_addr, from, SOCKLEN(from)); - memset(&checklist.my_addr, 0, sizeof(checklist.my_addr)); - checklist.my_addr.ss_family = checklist.src_addr.ss_family; + checklist.src_addr = from.sin_addr; + checklist.my_addr = no_addr; checklist.request = icp_request; allow = aclCheckFast(Config.accessList.icp, &checklist); if (!allow) { debug(12, 2) ("icpHandleIcpV2: Access Denied for %s by %s.\n", - sockaddr_ntoa(from), AclMatchedName); - if (clientdbCutoffDenied(from)) { + inet_ntoa(from.sin_addr), AclMatchedName); + if (clientdbCutoffDenied(from.sin_addr)) { /* * count this DENIED query in the clientdb, even though * we're not sending an ICP reply... */ - clientdbUpdate(from, LOG_UDP_DENIED, PROTO_ICP, 0); + clientdbUpdate(from.sin_addr, LOG_UDP_DENIED, PROTO_ICP, 0); } else { reply = icpCreateMessage(ICP_DENIED, 0, url, header.reqnum, 0); - icpUdpSend(fd, from, reply, LOG_UDP_DENIED, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_DENIED, 0); } break; } @@ -258,7 +255,7 @@ debug(12, 5) ("icpHandleIcpV2: OPCODE %s\n", icp_opcode_str[header.opcode]); if (icpCheckUdpHit(entry, icp_request)) { reply = icpCreateMessage(ICP_HIT, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, from, reply, LOG_UDP_HIT, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_HIT, 0); break; } if (Config.onoff.test_reachability && rtt == 0) { @@ -268,16 +265,16 @@ /* if store is rebuilding, return a UDP_HIT, but not a MISS */ if (store_dirs_rebuilding && opt_reload_hit_only) { reply = icpCreateMessage(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, from, reply, LOG_UDP_MISS_NOFETCH, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); } else if (hit_only_mode_until > squid_curtime) { reply = icpCreateMessage(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, from, reply, LOG_UDP_MISS_NOFETCH, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); } else if (Config.onoff.test_reachability && rtt == 0) { reply = icpCreateMessage(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, from, reply, LOG_UDP_MISS_NOFETCH, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); } else { reply = icpCreateMessage(ICP_MISS, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, from, reply, LOG_UDP_MISS, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_MISS, 0); } break; @@ -291,18 +288,18 @@ case ICP_MISS_NOFETCH: if (neighbors_do_private_keys && header.reqnum == 0) { debug(12, 0) ("icpHandleIcpV2: Neighbor %s returned reqnum = 0\n", - sockaddr_ntoa(from)); + inet_ntoa(from.sin_addr)); debug(12, 0) ("icpHandleIcpV2: Disabling use of private keys\n"); neighbors_do_private_keys = 0; } url = buf + sizeof(icp_common_t); debug(12, 3) ("icpHandleIcpV2: %s from %s for '%s'\n", icp_opcode_str[header.opcode], - sockaddr_ntoa(from), + inet_ntoa(from.sin_addr), url); key = icpGetCacheKey(url, (int) header.reqnum); /* call neighborsUdpAck even if ping_status != PING_WAITING */ - neighborsUdpAck(key, &header, from); + neighborsUdpAck(key, &header, &from); break; case ICP_INVALID: @@ -311,7 +308,7 @@ default: debug(12, 0) ("icpHandleIcpV2: UNKNOWN OPCODE: %d from %s\n", - header.opcode, sockaddr_ntoa(from)); + header.opcode, inet_ntoa(from.sin_addr)); break; } if (icp_request) @@ -341,7 +338,7 @@ icpHandleUdp(int sock, void *data) { int *N = &incoming_sockets_accepted; - struct sockaddr_storage from; + struct sockaddr_in from; socklen_t from_len; LOCAL_ARRAY(char, buf, SQUID_UDP_SO_RCVBUF); int len; @@ -380,7 +377,7 @@ debug(12, 4) ("icpHandleUdp: FD %d: received %d bytes from %s.\n", sock, len, - sockaddr_ntoa(&from)); + inet_ntoa(from.sin_addr)); #ifdef ICP_PACKET_DUMP icpPktDump(buf); #endif @@ -390,17 +387,14 @@ } icp_version = (int) buf[1]; /* cheat! */ if (icp_version == ICP_VERSION_2) - icpHandleIcpV2(sock, &from, buf, len); + icpHandleIcpV2(sock, from, buf, len); else if (icp_version == ICP_VERSION_3) - icpHandleIcpV3(sock, &from, buf, len); + icpHandleIcpV3(sock, from, buf, len); else debug(12, 1) ("WARNING: Unused ICP version %d received from %s:%d\n", icp_version, - sockaddr_ntoa(&from), - from.ss_family == AF_INET6 ? - ntohs(((struct sockaddr_in6 *)&from)->sin6_port) : - ntohs(((struct sockaddr_in *)&from)->sin_port) - ); + inet_ntoa(from.sin_addr), + ntohs(from.sin_port)); } } @@ -408,28 +402,20 @@ icpConnectionsOpen(void) { u_short port; - struct sockaddr_storage addr; - struct sockaddr_storage xaddr; + struct in_addr addr; + struct sockaddr_in xaddr; int x; socklen_t len; wordlist *s; if ((port = Config.Port.icp) <= 0) return; enter_suid(); - xmemcpy(&addr, &Config.Addrs.udp_incoming, sizeof(addr)); - ((struct sockaddr_in *)&addr)->sin_port = htons(port); theInIcpConnection = comm_open(SOCK_DGRAM, IPPROTO_UDP, - &addr, + Config.Addrs.udp_incoming, + port, COMM_NONBLOCKING, "ICP Socket"); - xmemcpy(&addr, &Config.Addrs.udp6_incoming, sizeof(addr)); - ((struct sockaddr_in6 *)&addr)->sin6_port = htons(port); - theInIcpConnection6 = comm_open(SOCK_DGRAM, - IPPROTO_UDP, - &addr, - COMM_NONBLOCKING, - "ICP Socket v6"); leave_suid(); if (theInIcpConnection < 0) fatal("Cannot open ICP Port"); @@ -438,29 +424,17 @@ icpHandleUdp, NULL, 0); - if (theInIcpConnection6 < 0) - fatal("Cannot open ICP Port v6"); - commSetSelect(theInIcpConnection6, - COMM_SELECT_READ, - icpHandleUdp, - NULL, - 0); for (s = Config.mcast_group_list; s; s = s->next) ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL); debug(12, 1) ("Accepting ICP messages at %s, port %d, FD %d.\n", - sockaddr_ntoa(&Config.Addrs.udp_incoming), + inet_ntoa(Config.Addrs.udp_incoming), (int) port, theInIcpConnection); - debug(12, 1) ("Accepting ICP messages v6 at %s, port %d, FD %d.\n", - sockaddr_ntoa(&Config.Addrs.udp6_incoming), - (int) port, theInIcpConnection6); - - if (((struct sockaddr_in *)&Config.Addrs.udp_outgoing)->sin_addr.s_addr != no_addr.s_addr) { - xmemcpy(&addr, &Config.Addrs.udp_outgoing, sizeof(addr)); - ((struct sockaddr_in *)&addr)->sin_port = htons(port); + if ((addr = Config.Addrs.udp_outgoing).s_addr != no_addr.s_addr) { enter_suid(); theOutIcpConnection = comm_open(SOCK_DGRAM, IPPROTO_UDP, - &addr, + addr, + port, COMM_NONBLOCKING, "ICP Port"); leave_suid(); @@ -478,33 +452,8 @@ } else { theOutIcpConnection = theInIcpConnection; } - if (!IN6_IS_ADDR_ALLF(&((struct sockaddr_in6 *)&Config.Addrs.udp6_outgoing)->sin6_addr) ) { - xmemcpy(&addr, &Config.Addrs.udp6_outgoing, sizeof(addr)); - ((struct sockaddr_in6 *)&addr)->sin6_port = htons(port); - enter_suid(); - theOutIcpConnection6 = comm_open(SOCK_DGRAM, - IPPROTO_UDP, - &addr, - COMM_NONBLOCKING, - "ICP Port v6"); - leave_suid(); - if (theOutIcpConnection6 < 0) - fatal("Cannot open Outgoing ICP Port v6"); - commSetSelect(theOutIcpConnection6, - COMM_SELECT_READ, - icpHandleUdp, - NULL, - 0); - debug(12, 1) ("Outgoing ICP messages v6 on port %d, FD %d.\n", - (int) port, theOutIcpConnection6); - fd_note(theOutIcpConnection6, "Outgoing ICP socket v6"); - fd_note(theInIcpConnection6, "Incoming ICP socket v6"); - } else { - theOutIcpConnection6 = theInIcpConnection6; - } - - memset(&theOutICPAddr, '\0', sizeof(struct sockaddr_storage)); - len = sizeof(struct sockaddr_storage); + memset(&theOutICPAddr, '\0', sizeof(struct in_addr)); + len = sizeof(struct sockaddr_in); memset(&xaddr, '\0', len); x = getsockname(theOutIcpConnection, (struct sockaddr *) &xaddr, &len); @@ -512,18 +461,7 @@ debug(12, 1) ("theOutIcpConnection FD %d: getsockname: %s\n", theOutIcpConnection, xstrerror()); else - xmemcpy(&theOutICPAddr, &xaddr, sizeof(xaddr)); - - memset(&theOutICPAddr6, '\0', sizeof(struct sockaddr_storage)); - len = sizeof(struct sockaddr_storage); - memset(&xaddr, '\0', len); - x = getsockname(theOutIcpConnection6, - (struct sockaddr *) &xaddr, &len); - if (x < 0) - debug(12, 1) ("theOutIcpConnection6 FD %d: getsockname: %s\n", - theOutIcpConnection6, xstrerror()); - else - xmemcpy(&theOutICPAddr6, &xaddr, sizeof(xaddr)); + theOutICPAddr = xaddr.sin_addr; } /* @@ -533,16 +471,12 @@ void icpConnectionShutdown(void) { - if (theInIcpConnection < 0 && theInIcpConnection6 < 0) + if (theInIcpConnection < 0) return; - if (theInIcpConnection > 0 && theInIcpConnection != theOutIcpConnection) { + if (theInIcpConnection != theOutIcpConnection) { debug(12, 1) ("FD %d Closing ICP connection\n", theInIcpConnection); comm_close(theInIcpConnection); } - if (theInIcpConnection6> 0 && theInIcpConnection6!=theOutIcpConnection6) { - debug(12, 1) ("FD %d Closing ICP connection6\n", theInIcpConnection6); - comm_close(theInIcpConnection6); - } /* * Here we set 'theInIcpConnection' to -1 even though the ICP 'in' * and 'out' sockets might be just one FD. This prevents this @@ -550,7 +484,6 @@ * exit or restart, main will comm_close the 'out' descriptor. */ theInIcpConnection = -1; - theInIcpConnection6 = -1; /* * Normally we only write to the outgoing ICP socket, but * we also have a read handler there to catch messages sent @@ -558,9 +491,7 @@ * disable reading on the outgoing socket. */ assert(theOutIcpConnection > -1); - assert(theOutIcpConnection6 > -1); commSetSelect(theOutIcpConnection, COMM_SELECT_READ, NULL, NULL, 0); - commSetSelect(theOutIcpConnection6, COMM_SELECT_READ, NULL, NULL, 0); } void @@ -572,11 +503,6 @@ comm_close(theOutIcpConnection); theOutIcpConnection = -1; } - if (theOutIcpConnection6 > -1) { - debug(12, 1) ("FD %d Closing ICP connection\n", theOutIcpConnection6); - comm_close(theOutIcpConnection6); - theOutIcpConnection6 = -1; - } } static void Index: squid/src/icp_v3.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/icp_v3.c,v retrieving revision 1.3.6.4 retrieving revision 1.3.6.5 diff -u -r1.3.6.4 -r1.3.6.5 --- squid/src/icp_v3.c 1 Jul 2007 05:44:22 -0000 1.3.6.4 +++ squid/src/icp_v3.c 2 Jul 2007 07:36:59 -0000 1.3.6.5 @@ -1,6 +1,6 @@ /* - * $Id: icp_v3.c,v 1.3.6.4 2007/07/01 05:44:22 amosjeffries Exp $ + * $Id: icp_v3.c,v 1.3.6.5 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -37,7 +37,7 @@ /* Currently Harvest cached-2.x uses ICP_VERSION_3 */ void -icpHandleIcpV3(int fd, struct sockaddr *from, char *buf, int len) +icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len) { icp_common_t header; icp_common_t *reply; @@ -69,32 +69,31 @@ if (strpbrk(url, w_space)) { url = rfc1738_escape(url); reply = icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0); - icpUdpSend(fd, from, reply, LOG_UDP_INVALID, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0); break; } if ((icp_request = urlParse(METHOD_GET, url)) == NULL) { reply = icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0); - icpUdpSend(fd, from, reply, LOG_UDP_INVALID, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0); break; } memset(&checklist, '\0', sizeof(checklist)); - xmemcpy(&checklist.src_addr, from, SOCKLEN(from)); - memset(&checklist.my_addr, '\0', sizeof(checklist.my_addr)); - checklist.my_addr.ss_family = from->sa_family; + checklist.src_addr = from.sin_addr; + checklist.my_addr = no_addr; checklist.request = icp_request; allow = aclCheckFast(Config.accessList.icp, &checklist); if (!allow) { debug(12, 2) ("icpHandleIcpV3: Access Denied for %s by %s.\n", - sockaddr_ntoa(from), AclMatchedName); - if (clientdbCutoffDenied(from)) { + inet_ntoa(from.sin_addr), AclMatchedName); + if (clientdbCutoffDenied(from.sin_addr)) { /* * count this DENIED query in the clientdb, even though * we're not sending an ICP reply... */ - clientdbUpdate(from, LOG_UDP_DENIED, PROTO_ICP, 0); + clientdbUpdate(from.sin_addr, LOG_UDP_DENIED, PROTO_ICP, 0); } else { reply = icpCreateMessage(ICP_DENIED, 0, url, header.reqnum, 0); - icpUdpSend(fd, from, reply, LOG_UDP_DENIED, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_DENIED, 0); } break; } @@ -104,19 +103,19 @@ icp_opcode_str[header.opcode]); if (icpCheckUdpHit(entry, icp_request)) { reply = icpCreateMessage(ICP_HIT, 0, url, header.reqnum, 0); - icpUdpSend(fd, from, reply, LOG_UDP_HIT, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_HIT, 0); break; } /* if store is rebuilding, return a UDP_HIT, but not a MISS */ if (opt_reload_hit_only && store_dirs_rebuilding) { reply = icpCreateMessage(ICP_MISS_NOFETCH, 0, url, header.reqnum, 0); - icpUdpSend(fd, from, reply, LOG_UDP_MISS_NOFETCH, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); } else if (hit_only_mode_until > squid_curtime) { reply = icpCreateMessage(ICP_MISS_NOFETCH, 0, url, header.reqnum, 0); - icpUdpSend(fd, from, reply, LOG_UDP_MISS_NOFETCH, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); } else { reply = icpCreateMessage(ICP_MISS, 0, url, header.reqnum, 0); - icpUdpSend(fd, from, reply, LOG_UDP_MISS, 0); + icpUdpSend(fd, &from, reply, LOG_UDP_MISS, 0); } break; @@ -130,18 +129,18 @@ case ICP_MISS_NOFETCH: if (neighbors_do_private_keys && header.reqnum == 0) { debug(12, 0) ("icpHandleIcpV3: Neighbor %s returned reqnum = 0\n", - sockaddr_ntoa(from)); + inet_ntoa(from.sin_addr)); debug(12, 0) ("icpHandleIcpV3: Disabling use of private keys\n"); neighbors_do_private_keys = 0; } url = buf + sizeof(icp_common_t); debug(12, 3) ("icpHandleIcpV3: %s from %s for '%s'\n", icp_opcode_str[header.opcode], - sockaddr_ntoa(from), + inet_ntoa(from.sin_addr), url); key = icpGetCacheKey(url, (int) header.reqnum); /* call neighborsUdpAck even if ping_status != PING_WAITING */ - neighborsUdpAck(key, &header, from); + neighborsUdpAck(key, &header, &from); break; case ICP_INVALID: @@ -150,7 +149,7 @@ default: debug(12, 0) ("icpHandleIcpV3: UNKNOWN OPCODE: %d from %s\n", - header.opcode, sockaddr_ntoa(from)); + header.opcode, inet_ntoa(from.sin_addr)); break; } if (icp_request) Index: squid/src/ident.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ident.c,v retrieving revision 1.4.6.6 retrieving revision 1.4.6.7 diff -u -r1.4.6.6 -r1.4.6.7 --- squid/src/ident.c 1 Jul 2007 05:44:23 -0000 1.4.6.6 +++ squid/src/ident.c 2 Jul 2007 07:36:59 -0000 1.4.6.7 @@ -1,6 +1,6 @@ /* - * $Id: ident.c,v 1.4.6.6 2007/07/01 05:44:23 amosjeffries Exp $ + * $Id: ident.c,v 1.4.6.7 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 30 Ident (RFC 931) * AUTHOR: Duane Wessels @@ -48,10 +48,9 @@ typedef struct _IdentStateData { hash_link hash; /* must be first */ - int ia_cur; /* dummy, for commConnectStart */ int fd; /* IDENT fd */ - struct sockaddr_storage me; - struct sockaddr_storage my_peer; + struct sockaddr_in me; + struct sockaddr_in my_peer; IdentClient *clients; } IdentStateData; @@ -95,7 +94,7 @@ { IdentStateData *state = data; debug(30, 3) ("identTimeout: FD %d, %s\n", fd, - sockaddr_ntoa(&state->my_peer)); + inet_ntoa(state->my_peer.sin_addr)); comm_close(fd); } @@ -124,12 +123,8 @@ } memBufDefInit(&mb); memBufPrintf(&mb, "%d, %d\r\n", - (state->my_peer.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&state->my_peer)->sin6_port): - ntohs(((struct sockaddr_in *)&state->my_peer)->sin_port), - (state->my_peer.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&state->me)->sin6_port): - ntohs(((struct sockaddr_in *)&state->me)->sin_port) ); + ntohs(state->my_peer.sin_port), + ntohs(state->me.sin_port)); comm_write_mbuf(fd, mb, NULL, state); commSetSelect(fd, COMM_SELECT_READ, identReadReply, state, 0); commSetTimeout(fd, Config.Timeout.ident, identTimeout, state); @@ -192,18 +187,19 @@ * start a TCP connection to the peer host on port 113 */ void -identStart(struct sockaddr *me, struct sockaddr *my_peer, IDCB * callback, void *data) +identStart(struct sockaddr_in *me, struct sockaddr_in *my_peer, IDCB * callback, void *data) { IdentStateData *state; int fd; char key1[IDENT_KEY_SZ]; char key2[IDENT_KEY_SZ]; char key[IDENT_KEY_SZ]; - char ahost[100], aport[8]; - getnameinfo(me, SOCKLEN(me), ahost, 100, aport, 8, NI_NUMERICHOST|NI_NUMERICSERV); - snprintf(key1, IDENT_KEY_SZ, "%s:%s", ahost, aport); - getnameinfo(my_peer, SOCKLEN(my_peer), ahost, 100, aport, 8, NI_NUMERICHOST|NI_NUMERICSERV); - snprintf(key2, IDENT_KEY_SZ, "%s:%s", ahost, aport); + snprintf(key1, IDENT_KEY_SZ, "%s:%d", + inet_ntoa(me->sin_addr), + ntohs(me->sin_port)); + snprintf(key2, IDENT_KEY_SZ, "%s:%d", + inet_ntoa(my_peer->sin_addr), + ntohs(my_peer->sin_port)); snprintf(key, IDENT_KEY_SZ, "%s,%s", key1, key2); if ((state = hash_lookup(ident_hash, key)) != NULL) { identClientAdd(state, callback, data); @@ -211,7 +207,8 @@ } fd = comm_open(SOCK_STREAM, IPPROTO_TCP, - me, + me->sin_addr, + 0, COMM_NONBLOCKING, "ident"); if (fd == COMM_ERROR) { @@ -223,8 +220,8 @@ state = cbdataAlloc(IdentStateData); state->hash.key = xstrdup(key); state->fd = fd; - xmemcpy(&state->me, me, SOCKLEN(me)); - xmemcpy(&state->my_peer, my_peer, SOCKLEN(my_peer)); + state->me = *me; + state->my_peer = *my_peer; identClientAdd(state, callback, data); hash_join(ident_hash, &state->hash); comm_add_close_handler(fd, @@ -232,7 +229,8 @@ state); commSetTimeout(fd, Config.Timeout.ident, identTimeout, state); commConnectStart(fd, - sockaddr_ntoa(my_peer), IDENT_PORT, + inet_ntoa(state->my_peer.sin_addr), + IDENT_PORT, identConnectDone, state, NULL); Index: squid/src/internal.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/internal.c,v retrieving revision 1.5.2.4 retrieving revision 1.5.2.5 diff -u -r1.5.2.4 -r1.5.2.5 --- squid/src/internal.c 1 Jul 2007 05:44:23 -0000 1.5.2.4 +++ squid/src/internal.c 2 Jul 2007 07:36:59 -0000 1.5.2.5 @@ -1,6 +1,6 @@ /* - * $Id: internal.c,v 1.5.2.4 2007/07/01 05:44:23 amosjeffries Exp $ + * $Id: internal.c,v 1.5.2.5 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 76 Internal Squid Object handling * AUTHOR: Duane, Alex, Henrik @@ -45,7 +45,7 @@ ErrorState *err; const char *upath = strBuf(request->urlpath); debug(76, 3) ("internalStart: %s requesting '%s'\n", - sockaddr_ntoa(&request->client_addr), upath); + inet_ntoa(request->client_addr), upath); if (0 == strcmp(upath, "/squid-internal-dynamic/netdb")) { netdbBinaryExchange(entry); } else if (0 == strcmp(upath, "/squid-internal-periodic/store_digest")) { @@ -90,17 +90,10 @@ /* convert host name to lower case */ xstrncpy(lc_host, host, SQUIDHOSTNAMELEN); Tolower(lc_host); - - /* - * host is IPv6 address - */ - if (strchr(lc_host, ':')) - snprintf(lc_host, SQUIDHOSTNAMELEN, "[%s]", host); /* * append the domain in order to mirror the requests with appended * domains */ - else if (Config.appendDomain && !strchr(lc_host, '.')) strncat(lc_host, Config.appendDomain, SQUIDHOSTNAMELEN - strlen(lc_host) - 1); Index: squid/src/ipc.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ipc.c,v retrieving revision 1.3.6.5 retrieving revision 1.3.6.6 diff -u -r1.3.6.5 -r1.3.6.6 --- squid/src/ipc.c 1 Jul 2007 05:44:23 -0000 1.3.6.5 +++ squid/src/ipc.c 2 Jul 2007 07:36:59 -0000 1.3.6.6 @@ -1,6 +1,6 @@ /* - * $Id: ipc.c,v 1.3.6.5 2007/07/01 05:44:23 amosjeffries Exp $ + * $Id: ipc.c,v 1.3.6.6 2007/07/02 07:36:59 amosjeffries Exp $ * * DEBUG: section 54 Interprocess Communication * AUTHOR: Duane Wessels @@ -87,32 +87,30 @@ if (hIpc) *hIpc = NULL; - CS.sin_family = AF_INET; -#if defined(_SQUID_FREEBSD_) || defined(_SQUID_NETBSD_) || defined(_SQUID_OPENBSD_) - CS.sin_len = sizeof(CS); -#endif - CS.sin_addr = local_addr; - CS.sin_port = 0; if (type == IPC_TCP_SOCKET) { crfd = cwfd = comm_open(SOCK_STREAM, IPPROTO_TCP, - &CS, + local_addr, + 0, COMM_NOCLOEXEC, name); prfd = pwfd = comm_open(SOCK_STREAM, IPPROTO_TCP, /* protocol */ - &CS, + local_addr, + 0, /* port */ 0, /* blocking */ name); } else if (type == IPC_UDP_SOCKET) { crfd = cwfd = comm_open(SOCK_DGRAM, IPPROTO_UDP, - &CS, + local_addr, + 0, COMM_NOCLOEXEC, name); prfd = pwfd = comm_open(SOCK_DGRAM, IPPROTO_UDP, - &CS, + local_addr, + 0, 0, name); } else if (type == IPC_FIFO) { Index: squid/src/ipcache.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ipcache.c,v retrieving revision 1.4.6.14 retrieving revision 1.4.6.15 diff -u -r1.4.6.14 -r1.4.6.15 --- squid/src/ipcache.c 1 Jul 2007 08:34:28 -0000 1.4.6.14 +++ squid/src/ipcache.c 2 Jul 2007 07:37:00 -0000 1.4.6.15 @@ -1,6 +1,6 @@ /* - * $Id: ipcache.c,v 1.4.6.14 2007/07/01 08:34:28 amosjeffries Exp $ + * $Id: ipcache.c,v 1.4.6.15 2007/07/02 07:37:00 amosjeffries Exp $ * * DEBUG: section 14 IP Cache * AUTHOR: Harvest Derived @@ -112,7 +112,7 @@ static void ipcacheRelease(ipcache_entry * i) { - debug(14, 3) ("ipcacheRelease: Releasing entry %x for '%s'\n", i, (const char *) i->hash.key); + debug(14, 3) ("ipcacheRelease: Releasing entry for '%s'\n", (const char *) i->hash.key); hash_remove_link(ip_table, (hash_link *) i); dlinkDelete(&i->lru, &lru_list); ipcacheFreeEntry(i); @@ -200,16 +200,7 @@ if (NULL != e) { /* avoid colission */ ipcache_entry *q = (ipcache_entry *) e; - if (i != q) - ipcacheRelease(q); - else { -/* - dlinkDelete(&i->lru, &lru_list); - dlinkAdd(i, &i->lru, &lru_list); -*/ - i->lastref = squid_curtime; - return; - } + ipcacheRelease(q); } hash_join(ip_table, &i->hash); dlinkAdd(i, &i->lru, &lru_list); @@ -294,7 +285,7 @@ if (ipcount <= 0) { debug(14, 1) ("ipcacheParse: No addresses in response to '%s'\n", name); } else { - i->addrs.in_addrs = xcalloc(ipcount, sizeof(struct sockaddr_storage)); + i->addrs.in_addrs = xcalloc(ipcount, sizeof(struct in_addr)); i->addrs.bad_mask = xcalloc(ipcount, sizeof(unsigned char)); for (j = 0, k = 0; k < ipcount; k++) { if (safe_inet_addr(A[k], &i->addrs.in_addrs[j])) @@ -320,12 +311,12 @@ int na = 0; int ttl = 0; const char *name = (const char *) i->hash.key; - - debug(14, 3) ("ipcacheParse: ipcache_entry %x\n", i); - if (!i->addrs.count) { - i->expires = squid_curtime + Config.negativeDnsTtl; - i->flags.negcached = 1; - } + i->expires = squid_curtime + Config.negativeDnsTtl; + i->flags.negcached = 1; + safe_free(i->addrs.in_addrs); + safe_free(i->addrs.bad_mask); + safe_free(i->error_message); + i->addrs.count = 0; if (nr < 0) { debug(14, 3) ("ipcacheParse: Lookup failed '%s' for '%s'\n", error_message, (const char *) i->hash.key); @@ -333,83 +324,47 @@ return i; } if (nr == 0) { - if (!i->addrs.count) { - debug(14, 3) ("ipcacheParse: No DNS records in response to '%s'\n", name); -/* - i->error_message = xstrdup("No DNS records"); -*/ - } + debug(14, 3) ("ipcacheParse: No DNS records in response to '%s'\n", name); + i->error_message = xstrdup("No DNS records"); return i; } assert(answers); for (k = 0; k < nr; k++) { - if ((answers[k].type != RFC1035_TYPE_A) && (answers[k].type != RFC1035_TYPE_AAAA)) + if (answers[k].type != RFC1035_TYPE_A) continue; if (answers[k].class != RFC1035_CLASS_IN) continue; - if ((answers[k].rdlength != 4) && (answers[k].rdlength != 16)) { + if (answers[k].rdlength != 4) { debug(14, 1) ("ipcacheParse: Invalid IP address in response to '%s'\n", name); continue; } na++; } if (na == 0) { - if (!i->addrs.count) { - debug(14, 1) ("ipcacheParse: No Address records in response to '%s'\n", name); - i->error_message = xstrdup("No Address records"); - } + debug(14, 1) ("ipcacheParse: No Address records in response to '%s'\n", name); + i->error_message = xstrdup("No Address records"); return i; } i->flags.negcached = 0; - if (i->addrs.count > 0) { - int total_cnt = i->addrs.count + na; - if (total_cnt > 255) total_cnt == 255; - i->addrs.in_addrs = xrealloc(i->addrs.in_addrs, total_cnt*sizeof(struct sockaddr_storage)); - i->addrs.bad_mask = xrealloc(i->addrs.bad_mask, total_cnt*sizeof(unsigned char)); - } - else { - i->addrs.in_addrs = xcalloc(na, sizeof(struct sockaddr_storage)); - i->addrs.bad_mask = xcalloc(na, sizeof(unsigned char)); - } + i->addrs.in_addrs = xcalloc(na, sizeof(struct in_addr)); + i->addrs.bad_mask = xcalloc(na, sizeof(unsigned char)); for (j = 0, k = 0; k < nr; k++) { if (answers[k].class != RFC1035_CLASS_IN) continue; if (answers[k].type == RFC1035_TYPE_A) { - struct sockaddr_in *this_answer = (struct sockaddr_in *)&i->addrs.in_addrs[j+i->addrs.count]; if (answers[k].rdlength != 4) continue; - this_answer->sin_family = AF_INET; -#if defined(_SQUID_FREEBSD_) || defined(_SQUID_NETBSD_) || defined(_SQUID_OPENBSD_) - this_answer->sin_len = sizeof(struct sockaddr_in); -#endif - xmemcpy(&this_answer->sin_addr, answers[k].rdata, 4); + xmemcpy(&i->addrs.in_addrs[j++], answers[k].rdata, 4); debug(14, 3) ("ipcacheParse: #%d %s\n", - j, - sockaddr_ntoa(&i->addrs.in_addrs[j+i->addrs.count])); - j++; - } else if (answers[k].type == RFC1035_TYPE_AAAA) { - struct sockaddr_in6 *this_answer = (struct sockaddr_in6 *)&i->addrs.in_addrs[j+i->addrs.count]; - if (answers[k].rdlength != 16) - continue; - this_answer->sin6_family = AF_INET6; -#if defined(_SQUID_FREEBSD_) || defined(_SQUID_NETBSD_) || defined(_SQUID_OPENBSD_) - this_answer->sin6_len = sizeof(struct sockaddr_in6); -#endif - xmemcpy(&this_answer->sin6_addr, answers[k].rdata, 16); - debug(14, 3) ("ipcacheParse: #%d %s\n", - j, - sockaddr_ntoa(&i->addrs.in_addrs[j+i->addrs.count])); - j++; - i->addrs.cur = i->addrs.count; - if (i->addrs.cur) - i->addrs.cur--; + j - 1, + inet_ntoa(i->addrs.in_addrs[j - 1])); } else if (answers[k].type != RFC1035_TYPE_CNAME) continue; if (ttl == 0 || ttl > answers[k].ttl) ttl = answers[k].ttl; } - if ((i->addrs.count + na) < 256) - i->addrs.count += (unsigned char) na; + if (na < 256) + i->addrs.count = (unsigned char) na; else i->addrs.count = 255; if (ttl == 0 || ttl > Config.positiveDnsTtl) @@ -429,22 +384,10 @@ ipcacheHandleReply(void *data, rfc1035_rr * answers, int na, const char *error_message) #endif { - int pairs = 0; generic_cbdata *c = data; ipcache_entry *i = c->data; - -#if !USE_DNSSERVERS - if (na > 5000) { - na = na - 10000; - pairs = 1; - } - if (!pairs) { -#endif - cbdataFree(c); - c = NULL; -#if !USE_DNSSERVERS - } -#endif + cbdataFree(c); + c = NULL; IpcacheStats.replies++; statHistCount(&statCounter.dns.svc_time, tvSubMsec(i->request_time, current_time)); @@ -453,15 +396,8 @@ #else ipcacheParse(i, answers, na, error_message); #endif -#if !USE_DNSSERVERS - if (!pairs) - { -#endif ipcacheAddEntry(i); ipcacheCallback(i); -#if !USE_DNSSERVERS - } -#endif } void @@ -514,8 +450,6 @@ i->request_time = current_time; c = cbdataAlloc(generic_cbdata); c->data = i; - ipcacheAddEntry(i); - debug(14, 5) ("ipcache_nbgethostbyname: create ipcacheEntry %x'\n", (void *)i); #if USE_DNSSERVERS dnsSubmit(hashKeyStr(&i->hash), ipcacheHandleReply, c); #else @@ -540,7 +474,7 @@ debug(14, 1) ("Successful DNS name lookup tests...\n"); } memset(&static_addrs, '\0', sizeof(ipcache_addrs)); - static_addrs.in_addrs = xcalloc(1, sizeof(struct sockaddr_storage)); + static_addrs.in_addrs = xcalloc(1, sizeof(struct in_addr)); static_addrs.bad_mask = xcalloc(1, sizeof(unsigned char)); ipcache_high = (long) (((float) Config.ipcache.size * (float) Config.ipcache.high) / (float) 100); @@ -601,7 +535,7 @@ (int) i->addrs.count, (int) i->addrs.badcount); for (k = 0; k < (int) i->addrs.count; k++) { - storeAppendPrintf(sentry, " %15s-%3s", sockaddr_ntoa(&i->addrs.in_addrs[k]), + storeAppendPrintf(sentry, " %15s-%3s", inet_ntoa(i->addrs.in_addrs[k]), i->addrs.bad_mask[k] ? "BAD" : "OK "); } storeAppendPrintf(sentry, "\n"); @@ -672,13 +606,13 @@ ipcache_addrs * ipcacheCheckNumeric(const char *name) { - struct sockaddr_storage ip; + struct in_addr ip; /* check if it's already a IP address in text form. */ if (!safe_inet_addr(name, &ip)) return NULL; static_addrs.count = 1; static_addrs.cur = 0; - xmemcpy(&static_addrs.in_addrs[0], &ip, sizeof(ip)); + static_addrs.in_addrs[0].s_addr = ip.s_addr; static_addrs.bad_mask[0] = FALSE; static_addrs.badcount = 0; return &static_addrs; @@ -730,10 +664,8 @@ ia->badcount = 0; ia->cur = 0; } -/* debug(14, 3) ("ipcacheCycleAddr: %s now at %s\n", name, - sockaddr_ntoa(&ia->in_addrs[ia->cur])); -*/ + inet_ntoa(ia->in_addrs[ia->cur])); } /* @@ -741,7 +673,7 @@ * advance the current pointer to the next OK address. */ void -ipcacheMarkBadAddr(const char *name, struct sockaddr *addr) +ipcacheMarkBadAddr(const char *name, struct in_addr addr) { ipcache_entry *i; ipcache_addrs *ia; @@ -750,17 +682,7 @@ return; ia = &i->addrs; for (k = 0; k < (int) ia->count; k++) { - if (ia->in_addrs->ss_family != addr->sa_family) - continue; - if ((ia->in_addrs->ss_family == AF_INET) && - memcmp(&((struct sockaddr_in *)ia->in_addrs)->sin_addr, - &((struct sockaddr_in *)addr)->sin_addr, - sizeof(struct in_addr)) ) - break; - if ((ia->in_addrs->ss_family == AF_INET6) && - memcmp(&((struct sockaddr_in6 *)ia->in_addrs)->sin6_addr, - &((struct sockaddr_in6 *)addr)->sin6_addr, - sizeof(struct in6_addr)) ) + if (ia->in_addrs[k].s_addr == addr.s_addr) break; } if (k == (int) ia->count) /* not found */ @@ -769,13 +691,13 @@ ia->bad_mask[k] = TRUE; ia->badcount++; i->expires = XMIN(squid_curtime + XMAX(60, Config.negativeDnsTtl), i->expires); - debug(14, 2) ("ipcacheMarkBadAddr: %s [%s]\n", name, sockaddr_ntoa(addr)); + debug(14, 2) ("ipcacheMarkBadAddr: %s [%s]\n", name, inet_ntoa(addr)); } ipcacheCycleAddr(name, ia); } void -ipcacheMarkGoodAddr(const char *name, struct sockaddr *addr) +ipcacheMarkGoodAddr(const char *name, struct in_addr addr) { ipcache_entry *i; ipcache_addrs *ia; @@ -784,17 +706,7 @@ return; ia = &i->addrs; for (k = 0; k < (int) ia->count; k++) { - if (ia->in_addrs->ss_family != addr->sa_family) - continue; - if ((ia->in_addrs->ss_family == AF_INET) && - memcmp(&((struct sockaddr_in *)ia->in_addrs)->sin_addr, - &((struct sockaddr_in *)addr)->sin_addr, - sizeof(struct in_addr)) ) - break; - if ((ia->in_addrs->ss_family == AF_INET6) && - memcmp(&((struct sockaddr_in6 *)ia->in_addrs)->sin6_addr, - &((struct sockaddr_in6 *)addr)->sin6_addr, - sizeof(struct in6_addr)) ) + if (ia->in_addrs[k].s_addr == addr.s_addr) break; } if (k == (int) ia->count) /* not found */ @@ -803,7 +715,7 @@ return; ia->bad_mask[k] = FALSE; ia->badcount--; - debug(14, 2) ("ipcacheMarkGoodAddr: %s [%s]\n", name, sockaddr_ntoa(addr)); + debug(14, 2) ("ipcacheMarkGoodAddr: %s [%s]\n", name, inet_ntoa(addr)); } static void @@ -844,7 +756,7 @@ ipcacheAddEntryFromHosts(const char *name, const char *ipaddr) { ipcache_entry *i; - struct sockaddr_storage ip; + struct in_addr ip; if (!safe_inet_addr(ipaddr, &ip)) { if (strchr(ipaddr, ':') && strspn(ipaddr, "0123456789abcdefABCDEF:") == strlen(ipaddr)) { debug(14, 3) ("ipcacheAddEntryFromHosts: Skipping IPv6 address '%s'\n", ipaddr); @@ -869,9 +781,9 @@ i->addrs.count = 1; i->addrs.cur = 0; i->addrs.badcount = 0; - i->addrs.in_addrs = xcalloc(1, sizeof(struct sockaddr_storage)); + i->addrs.in_addrs = xcalloc(1, sizeof(struct in_addr)); i->addrs.bad_mask = xcalloc(1, sizeof(unsigned char)); - xmemcpy(&i->addrs.in_addrs[0], &ip, sizeof(ip)); + i->addrs.in_addrs[0].s_addr = ip.s_addr; i->addrs.bad_mask[0] = FALSE; i->flags.fromhosts = 1; ipcacheAddEntry(i); Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/main.c,v retrieving revision 1.5.4.8 retrieving revision 1.5.4.9 diff -u -r1.5.4.8 -r1.5.4.9 --- squid/src/main.c 1 Jul 2007 05:44:23 -0000 1.5.4.8 +++ squid/src/main.c 2 Jul 2007 07:37:00 -0000 1.5.4.9 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.5.4.8 2007/07/01 05:44:23 amosjeffries Exp $ + * $Id: main.c,v 1.5.4.9 2007/07/02 07:37:00 amosjeffries Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -663,7 +663,6 @@ { int errcount = 0; int loop_delay; - struct sockaddr_storage curaddr; #ifdef _SQUID_WIN32_ int WIN32_init_err; #endif @@ -696,15 +695,11 @@ #endif /* HAVE_MALLOPT */ memset(&local_addr, '\0', sizeof(struct in_addr)); - memset(&curaddr, '\0', sizeof(curaddr)); - safe_inet_addr(localhost, &curaddr); - local_addr.s_addr = ((struct sockaddr_in *)&curaddr)->sin_addr.s_addr; + safe_inet_addr(localhost, &local_addr); memset(&any_addr, '\0', sizeof(struct in_addr)); - safe_inet_addr("0.0.0.0", &curaddr); - any_addr.s_addr = ((struct sockaddr_in *)&curaddr)->sin_addr.s_addr; + safe_inet_addr("0.0.0.0", &any_addr); memset(&no_addr, '\0', sizeof(struct in_addr)); - safe_inet_addr("255.255.255.255", &curaddr); - no_addr.s_addr = ((struct sockaddr_in *)&curaddr)->sin_addr.s_addr; + safe_inet_addr("255.255.255.255", &no_addr); squid_srandom(time(NULL)); getCurrentTime(); Index: squid/src/multicast.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/multicast.c,v retrieving revision 1.3.6.5 retrieving revision 1.3.6.6 diff -u -r1.3.6.5 -r1.3.6.6 --- squid/src/multicast.c 1 Jul 2007 05:44:24 -0000 1.3.6.5 +++ squid/src/multicast.c 2 Jul 2007 07:37:00 -0000 1.3.6.6 @@ -1,6 +1,6 @@ /* - * $Id: multicast.c,v 1.3.6.5 2007/07/01 05:44:24 amosjeffries Exp $ + * $Id: multicast.c,v 1.3.6.6 2007/07/02 07:37:00 amosjeffries Exp $ * * DEBUG: section 7 Multicast * AUTHOR: Martin Hamilton @@ -62,16 +62,14 @@ } for (i = 0; i < (int) ia->count; i++) { debug(7, 10) ("Listening for ICP requests on %s\n", - sockaddr_ntoa((ia->in_addrs + i))); - if (ia->in_addrs->ss_family != AF_INET) - continue; - mr.imr_multiaddr.s_addr = ((struct sockaddr_in *)(ia->in_addrs + i))->sin_addr.s_addr; + inet_ntoa(*(ia->in_addrs + i))); + mr.imr_multiaddr.s_addr = (ia->in_addrs + i)->s_addr; mr.imr_interface.s_addr = INADDR_ANY; x = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mr, sizeof(struct ip_mreq)); if (x < 0) debug(7, 1) ("comm_join_mcast_groups: FD %d, [%s]\n", - fd, sockaddr_ntoa((ia->in_addrs + i))); + fd, inet_ntoa(*(ia->in_addrs + i))); x = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &c, 1); if (x < 0) debug(7, 1) ("Can't disable multicast loopback: %s\n", xstrerror()); Index: squid/src/neighbors.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/neighbors.c,v retrieving revision 1.5.4.10 retrieving revision 1.5.4.11 diff -u -r1.5.4.10 -r1.5.4.11 --- squid/src/neighbors.c 1 Jul 2007 08:34:29 -0000 1.5.4.10 +++ squid/src/neighbors.c 2 Jul 2007 07:37:00 -0000 1.5.4.11 @@ -1,6 +1,6 @@ /* - * $Id: neighbors.c,v 1.5.4.10 2007/07/01 08:34:29 amosjeffries Exp $ + * $Id: neighbors.c,v 1.5.4.11 2007/07/02 07:37:00 amosjeffries Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -53,7 +53,7 @@ static void peerCountMcastPeersStart(void *data); static void peerCountMcastPeersSchedule(peer * p, time_t when); static IRCB peerCountHandleIcpReply; -static void neighborIgnoreNonPeer(const struct sockaddr *, icp_opcode); +static void neighborIgnoreNonPeer(const struct sockaddr_in *, icp_opcode); static OBJH neighborDumpPeers; static OBJH neighborDumpNonPeers; static void dump_peers(StoreEntry * sentry, peer * peers); @@ -78,30 +78,17 @@ peer * -whichPeer(const struct sockaddr * from) +whichPeer(const struct sockaddr_in * from) { int j; - u_short port; + u_short port = ntohs(from->sin_port); + struct in_addr ip = from->sin_addr; peer *p = NULL; - char hbuf[80], sbuf[8]; - getnameinfo(from, SOCKLEN(from), hbuf, 80, sbuf, 8, - NI_NUMERICHOST|NI_NUMERICSERV); - debug(15, 3) ("whichPeer: from %s port %s\n", hbuf, sbuf); + debug(15, 3) ("whichPeer: from %s port %d\n", inet_ntoa(ip), port); for (p = Config.peers; p; p = p->next) { for (j = 0; j < p->n_addresses; j++) { - if (from->sa_family != p->addresses[j].ss_family) - continue; - switch (from->sa_family) { - case AF_INET6: - if ( IN6_ARE_ADDR_EQUAL(&((struct sockaddr_in6 *)&p->addresses[j])->sin6_addr, &((struct sockaddr_in6 *)from)->sin6_addr) && - (p->icp.port == ntohs(((struct sockaddr_in6 *)from)->sin6_port))) - return p; - break; - case AF_INET: - if ( (((struct sockaddr_in *)&p->addresses[j])->sin_addr.s_addr == ((struct sockaddr_in *)from)->sin_addr.s_addr) && - (p->icp.port == ntohs(((struct sockaddr_in *)from)->sin_port))) - return p; - break; + if (ip.s_addr == p->addresses[j].s_addr && port == p->icp.port) { + return p; } } } @@ -365,15 +352,15 @@ void neighbors_init(void) { - struct sockaddr_storage name; - socklen_t len = sizeof(struct sockaddr_storage); + struct sockaddr_in name; + socklen_t len = sizeof(struct sockaddr_in); struct servent *sep = NULL; const char *me = getMyHostname(); peer *this; peer *next; int fd = theInIcpConnection; if (fd >= 0) { - memset(&name, '\0', sizeof(struct sockaddr_storage)); + memset(&name, '\0', sizeof(struct sockaddr_in)); if (getsockname(fd, (struct sockaddr *) &name, &len) < 0) debug(15, 1) ("getsockname(%d,%p,%p) failed.\n", fd, &name, &len); for (this = Config.peers; this; this = next) { @@ -382,9 +369,7 @@ if (0 != strcmp(this->host, me)) continue; for (s = Config.Sockaddr.http; s; s = s->next) { - if (this->http_port != ((s->s.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *)&s->s)->sin6_port) : - ntohs(((struct sockaddr_in *)&s->s)->sin_port)) ) + if (this->http_port != ntohs(s->s.sin_port)) continue; debug(15, 1) ("WARNING: Peer looks like this host\n"); debug(15, 1) (" Ignoring %s %s/%d/%d\n", @@ -402,7 +387,7 @@ echo_hdr.reqnum = 0; echo_hdr.flags = 0; echo_hdr.pad = 0; - xmemcpy(&echo_hdr.shostid, &name, len); + echo_hdr.shostid = name.sin_addr.s_addr; sep = getservbyname("echo", "udp"); echo_port = sep ? ntohs((u_short) sep->s_port) : 7; } @@ -471,36 +456,22 @@ debug(15, 4) ("neighborsUdpPing: Looks like a dumb cache, send DECHO ping\n"); echo_hdr.reqnum = reqnum; query = icpCreateMessage(ICP_DECHO, 0, url, reqnum, 0); - if (p->in_addr.ss_family == AF_INET6) - icpUdpSend(theOutIcpConnection6, - &p->in_addr, - query, - LOG_ICP_QUERY, - 0); - else - icpUdpSend(theOutIcpConnection, - &p->in_addr, - query, - LOG_ICP_QUERY, - 0); + icpUdpSend(theOutIcpConnection, + &p->in_addr, + query, + LOG_ICP_QUERY, + 0); } else { flags = 0; if (Config.onoff.query_icmp) if (p->icp.version == ICP_VERSION_2) flags |= ICP_FLAG_SRC_RTT; query = icpCreateMessage(ICP_QUERY, flags, url, reqnum, 0); - if (p->in_addr.ss_family == AF_INET6) - icpUdpSend(theOutIcpConnection6, - &p->in_addr, - query, - LOG_ICP_QUERY, - 0); - else - icpUdpSend(theOutIcpConnection, - &p->in_addr, - query, - LOG_ICP_QUERY, - 0); + icpUdpSend(theOutIcpConnection, + &p->in_addr, + query, + LOG_ICP_QUERY, + 0); } queries_sent++; @@ -756,31 +727,23 @@ static peer *non_peers = NULL; static void -neighborIgnoreNonPeer(const struct sockaddr *from, icp_opcode opcode) +neighborIgnoreNonPeer(const struct sockaddr_in *from, icp_opcode opcode) { peer *np; for (np = non_peers; np; np = np->next) { - if (from->sa_family != np->in_addr.ss_family) + if (np->in_addr.sin_addr.s_addr != from->sin_addr.s_addr) continue; - if ((from->sa_family == AF_INET6) && - IN6_ARE_ADDR_EQUAL(&((struct sockaddr_in6 *)&np->in_addr)->sin6_addr, &((struct sockaddr_in6 *)from)->sin6_addr) && - (((struct sockaddr_in6 *)&np->in_addr)->sin6_port == ntohs(((struct sockaddr_in6 *)from)->sin6_port))) - continue; - else - if ((from->sa_family == AF_INET) && - (((struct sockaddr_in *)&np->in_addr)->sin_addr.s_addr == ((struct sockaddr_in *)from)->sin_addr.s_addr) && - (((struct sockaddr_in *)&np->in_addr)->sin_port == ntohs(((struct sockaddr_in *)from)->sin_port))) + if (np->in_addr.sin_port != from->sin_port) continue; break; } if (np == NULL) { np = xcalloc(1, sizeof(peer)); - xmemcpy(&np->in_addr, &from, sizeof(struct sockaddr_storage)); - np->icp.port = ntohs( (from->sa_family == AF_INET6) ? - ((struct sockaddr_in6 *)from)->sin6_port : - ((struct sockaddr_in *)from)->sin_port ); + np->in_addr.sin_addr = from->sin_addr; + np->in_addr.sin_port = from->sin_port; + np->icp.port = ntohl(from->sin_port); np->type = PEER_NONE; - np->host = xstrdup(sockaddr_ntoa(from)); + np->host = xstrdup(inet_ntoa(from->sin_addr)); np->next = non_peers; non_peers = np; } @@ -815,7 +778,7 @@ * If a hit process is already started, then sobeit */ void -neighborsUdpAck(const cache_key * key, icp_common_t * header, const struct sockaddr *from) +neighborsUdpAck(const cache_key * key, icp_common_t * header, const struct sockaddr_in *from) { peer *p = NULL; StoreEntry *entry; @@ -905,7 +868,7 @@ mem->ping_reply_callback(NULL, ntype, PROTO_ICP, header, mem->ircb_data); #endif } else { - debug(15, 1) ("Unsolicited SECHO from %s\n", sockaddr_ntoa(from)); + debug(15, 1) ("Unsolicited SECHO from %s\n", inet_ntoa(from->sin_addr)); } } else if (opcode == ICP_DENIED) { if (p == NULL) { @@ -1019,7 +982,7 @@ peerDNSConfigure(const ipcache_addrs * ia, void *data) { peer *p = data; - struct sockaddr_storage *ap; + struct sockaddr_in *ap; int j; if (p->n_addresses == 0) { debug(15, 1) ("Configuring %s %s/%d/%d\n", neighborTypeStr(p), @@ -1038,17 +1001,15 @@ } p->tcp_up = PEER_TCP_MAGIC_COUNT; for (j = 0; j < (int) ia->count && j < PEER_MAX_ADDRESSES; j++) { - xmemcpy(&p->addresses[j], &ia->in_addrs[j], sizeof(struct sockaddr_storage)); - debug(15, 2) ("--> IP address #%d: %s\n", j, sockaddr_ntoa(&p->addresses[j])); + p->addresses[j] = ia->in_addrs[j]; + debug(15, 2) ("--> IP address #%d: %s\n", j, inet_ntoa(p->addresses[j])); p->n_addresses++; } - ap = (struct sockaddr_storage *)&p->in_addr; - memset(ap, '\0', sizeof(struct sockaddr_storage)); - xmemcpy(ap, &p->addresses[0], sizeof(struct sockaddr_storage)); - if (ap->ss_family == AF_INET6) - ((struct sockaddr_in6 *)ap)->sin6_port = htons(p->icp.port); - else - ((struct sockaddr_in *)ap)->sin_port = htons(p->icp.port); + 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); if (p->type == PEER_MULTICAST) peerCountMcastPeersSchedule(p, 10); if (p->type != PEER_MULTICAST) @@ -1128,7 +1089,6 @@ peerProbeConnect(peer * p) { int fd; - struct sockaddr_storage outsock; time_t ctimeout = p->connect_timeout > 0 ? p->connect_timeout : Config.Timeout.peer_connect; int ret = squid_curtime - p->stats.last_connect_failure > ctimeout * 10; @@ -1136,18 +1096,16 @@ return ret; /* probe already running */ if (squid_curtime - p->stats.last_connect_probe == 0) return ret; /* don't probe to often */ - memset(&outsock, '\0', sizeof(outsock)); - outsock.ss_family = p->in_addr.ss_family; - fd = comm_open(SOCK_STREAM, IPPROTO_TCP, &outsock, - COMM_NONBLOCKING, p->host); + fd = comm_open(SOCK_STREAM, IPPROTO_TCP, getOutgoingAddr(NULL), + 0, COMM_NONBLOCKING, p->host); if (fd < 0) return ret; commSetTimeout(fd, ctimeout, peerProbeConnectTimeout, p); p->test_fd = fd; p->stats.last_connect_probe = squid_curtime; - p->ia_cur = -1; commConnectStart(p->test_fd, - p->host, p->http_port, + p->host, + p->http_port, peerProbeConnectDone, p, NULL); @@ -1192,7 +1150,7 @@ LOCAL_ARRAY(char, url, MAX_URL); assert(p->type == PEER_MULTICAST); p->mcast.flags.count_event_pending = 0; - snprintf(url, MAX_URL, "http://%s/", sockaddr_ntoa(&p->in_addr)); + snprintf(url, MAX_URL, "http://%s/", inet_ntoa(p->in_addr.sin_addr)); fake = storeCreateEntry(url, null_request_flags, METHOD_GET); psstate = cbdataAlloc(ps_state); psstate->request = requestLink(urlParse(METHOD_GET, url)); @@ -1364,7 +1322,7 @@ dump_peer_options(sentry, e); for (i = 0; i < e->n_addresses; i++) { storeAppendPrintf(sentry, "Address[%d] : %s\n", i, - sockaddr_ntoa(&e->addresses[i])); + inet_ntoa(e->addresses[i])); } storeAppendPrintf(sentry, "Status : %s\n", neighborUp(e) ? "Up" : "Down"); @@ -1432,7 +1390,7 @@ #if USE_HTCP void -neighborsHtcpReply(const cache_key * key, htcpReplyData * htcp, const struct sockaddr *from) +neighborsHtcpReply(const cache_key * key, htcpReplyData * htcp, const struct sockaddr_in *from) { StoreEntry *e = storeGet(key); MemObject *mem = NULL; Index: squid/src/net_db.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/net_db.c,v retrieving revision 1.6.2.7 retrieving revision 1.6.2.8 diff -u -r1.6.2.7 -r1.6.2.8 --- squid/src/net_db.c 1 Jul 2007 05:44:24 -0000 1.6.2.7 +++ squid/src/net_db.c 2 Jul 2007 07:37:01 -0000 1.6.2.8 @@ -1,6 +1,6 @@ /* - * $Id: net_db.c,v 1.6.2.7 2007/07/01 05:44:24 amosjeffries Exp $ + * $Id: net_db.c,v 1.6.2.8 2007/07/02 07:37:01 amosjeffries Exp $ * * DEBUG: section 38 Network Measurement Database * AUTHOR: Duane Wessels @@ -700,7 +700,7 @@ } void -netdbHandlePingReply(const struct sockaddr *from, int hops, int rtt) +netdbHandlePingReply(const struct sockaddr_in *from, int hops, int rtt) { #if USE_ICMP netdbEntry *n; @@ -738,7 +738,7 @@ } int -netdbHops(struct sockaddr *addr) +netdbHops(struct in_addr addr) { #if USE_ICMP netdbEntry *n = netdbLookupAddr(addr); @@ -898,7 +898,7 @@ } void -netdbDeleteAddrNetwork(struct sockaddr *addr) +netdbDeleteAddrNetwork(struct in_addr addr) { #if USE_ICMP netdbEntry *n = netdbLookupAddr(addr); Index: squid/src/pconn.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/pconn.c,v retrieving revision 1.4.6.5 retrieving revision 1.4.6.6 diff -u -r1.4.6.5 -r1.4.6.6 --- squid/src/pconn.c 1 Jul 2007 05:44:24 -0000 1.4.6.5 +++ squid/src/pconn.c 2 Jul 2007 07:37:01 -0000 1.4.6.6 @@ -1,6 +1,6 @@ /* - * $Id: pconn.c,v 1.4.6.5 2007/07/01 05:44:24 amosjeffries Exp $ + * $Id: pconn.c,v 1.4.6.6 2007/07/02 07:37:01 amosjeffries Exp $ * * DEBUG: section 48 Persistent Connections * AUTHOR: Duane Wessels @@ -49,7 +49,7 @@ static PF pconnRead; static PF pconnTimeout; -static int pconnKey(char *buf, const char *host, u_short port, const char *domain, struct sockaddr *client_address); +static int pconnKey(char *buf, const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port); static hash_table *table = NULL; static struct _pconn *pconnNew(const char *key); static void pconnDelete(struct _pconn *p); @@ -62,16 +62,16 @@ static int pconnKey(char *buf, const char *host, u_short port, const char *domain, - struct sockaddr *client_address) + struct in_addr *client_address, u_short client_port) { if (domain && client_address) - return snprintf(buf, PCONN_KEYLEN, "%s.%d:%s./%s", host, (int) port, - sockaddr_ntoa(client_address), domain); + return snprintf(buf, PCONN_KEYLEN, "%s.%d:%s.%d/%s", host, (int) port, + inet_ntoa(*client_address), (int) client_port, domain); else if (domain && (!client_address)) return snprintf(buf, PCONN_KEYLEN, "%s.%d/%s", host, (int) port, domain); else if ((!domain) && client_address) - return snprintf(buf, PCONN_KEYLEN, "%s.%d:%s.", host, (int) port, - sockaddr_ntoa(client_address)); + return snprintf(buf, PCONN_KEYLEN, "%s.%d:%s.%d", host, (int) port, + inet_ntoa(*client_address), (int) client_port); else return snprintf(buf, PCONN_KEYLEN, "%s:%d", host, (int) port); } @@ -194,7 +194,7 @@ } void -pconnPush(int fd, const char *host, u_short port, const char *domain, struct sockaddr *client_address) +pconnPush(int fd, const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port) { struct _pconn *p; int *old; @@ -209,7 +209,7 @@ return; } assert(table != NULL); - pconnKey(key, host, port, domain, client_address); + pconnKey(key, host, port, domain, client_address, client_port); p = (struct _pconn *) hash_lookup(table, key); if (p == NULL) p = pconnNew(key); @@ -233,13 +233,13 @@ } int -pconnPop(const char *host, u_short port, const char *domain, struct sockaddr *client_address) +pconnPop(const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port) { struct _pconn *p; hash_link *hptr; int fd = -1; assert(table != NULL); - hptr = pconnLookup(host, port, domain, client_address); + hptr = pconnLookup(host, port, domain, client_address, client_port); if (hptr != NULL) { p = (struct _pconn *) hptr; assert(p->nfds > 0); @@ -252,11 +252,11 @@ } hash_link * -pconnLookup(const char *peer, u_short port, const char *domain, struct sockaddr *client_address) +pconnLookup(const char *peer, u_short port, const char *domain, struct in_addr * client_address, u_short client_port) { LOCAL_ARRAY(char, key, PCONN_KEYLEN); assert(table != NULL); - pconnKey(key, peer, port, domain, client_address); + pconnKey(key, peer, port, domain, client_address, client_port); return hash_lookup(table, key); } Index: squid/src/peer_select.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/peer_select.c,v retrieving revision 1.3.6.8 retrieving revision 1.3.6.9 diff -u -r1.3.6.8 -r1.3.6.9 --- squid/src/peer_select.c 1 Jul 2007 05:44:24 -0000 1.3.6.8 +++ squid/src/peer_select.c 2 Jul 2007 07:37:01 -0000 1.3.6.9 @@ -1,6 +1,6 @@ /* - * $Id: peer_select.c,v 1.3.6.8 2007/07/01 05:44:24 amosjeffries Exp $ + * $Id: peer_select.c,v 1.3.6.9 2007/07/02 07:37:01 amosjeffries Exp $ * * DEBUG: section 44 Peer Selection Algorithm * AUTHOR: Duane Wessels @@ -425,20 +425,10 @@ code = SOURCE_FASTEST; } else #endif - if ((ps->closest_parent_miss.ss_family == AF_INET6) && - !IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)&ps->closest_parent_miss)->sin6_addr)) { + if (ps->closest_parent_miss.sin_addr.s_addr != any_addr.s_addr) { p = whichPeer(&ps->closest_parent_miss); code = CLOSEST_PARENT_MISS; - } else if ((ps->closest_parent_miss.ss_family == AF_INET) && - (((struct sockaddr_in *)&ps->closest_parent_miss)->sin_addr.s_addr != any_addr.s_addr)) { - p = whichPeer(&ps->closest_parent_miss); - code = CLOSEST_PARENT_MISS; - } else if ((ps->first_parent_miss.ss_family == AF_INET6) && - !IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)&ps->first_parent_miss)->sin6_addr)) { - p = whichPeer(&ps->first_parent_miss); - code = FIRST_PARENT_MISS; - } else if ((ps->first_parent_miss.ss_family == AF_INET) && - (((struct sockaddr_in *)&ps->first_parent_miss)->sin_addr.s_addr != any_addr.s_addr)) { + } else if (ps->first_parent_miss.sin_addr.s_addr != any_addr.s_addr) { p = whichPeer(&ps->first_parent_miss); code = FIRST_PARENT_MISS; } @@ -533,11 +523,6 @@ { ps_state *psstate = data; StoreEntry *entry = psstate->entry; - if (!psstate->request) { - debug(44, 3) ("peerPingTimeout: null request\n"); - peerSelectStateFree(psstate); - return; - } if (entry) debug(44, 3) ("peerPingTimeout: '%s'\n", storeUrl(entry)); if (!cbdataValid(psstate->callback_data)) { @@ -580,21 +565,12 @@ if (p->options.closest_only) return; /* set FIRST_MISS if there is no CLOSEST parent */ - if ((ps->closest_parent_miss.ss_family == AF_INET6) && - !IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)&ps->closest_parent_miss)->sin6_addr)) - return; - else if ((ps->closest_parent_miss.ss_family == AF_INET) && - (((struct sockaddr_in *)&ps->closest_parent_miss)->sin_addr.s_addr != any_addr.s_addr)) + if (ps->closest_parent_miss.sin_addr.s_addr != any_addr.s_addr) return; rtt = tvSubMsec(ps->ping.start, current_time) / p->weight; - if (( - ((ps->first_parent_miss.ss_family == AF_INET6) && - IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)&ps->first_parent_miss)->sin6_addr)) || - ((ps->first_parent_miss.ss_family == AF_INET) && - (((struct sockaddr_in *)&ps->first_parent_miss)->sin_addr.s_addr != any_addr.s_addr)) - ) - || rtt < ps->ping.w_rtt) { - xmemcpy(&ps->first_parent_miss, &p->in_addr, sizeof(&p->in_addr)); + 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; ps->ping.w_rtt = rtt; } } Index: squid/src/peer_sourcehash.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/peer_sourcehash.c,v retrieving revision 1.3.42.3 retrieving revision 1.3.42.4 diff -u -r1.3.42.3 -r1.3.42.4 --- squid/src/peer_sourcehash.c 1 Jul 2007 05:44:24 -0000 1.3.42.3 +++ squid/src/peer_sourcehash.c 2 Jul 2007 07:37:01 -0000 1.3.42.4 @@ -1,6 +1,6 @@ /* - * $Id: peer_sourcehash.c,v 1.3.42.3 2007/07/01 05:44:24 amosjeffries Exp $ + * $Id: peer_sourcehash.c,v 1.3.42.4 2007/07/02 07:37:01 amosjeffries Exp $ * * DEBUG: section 44 Peer user hash based selection * AUTHOR: Henrik Nordstrom @@ -136,7 +136,7 @@ double high_score = 0; char *key = NULL; - key = sockaddr_ntoa(&request->client_addr); + key = inet_ntoa(request->client_addr); /* calculate hash key */ debug(39, 2) ("peerSourceHashSelectParent: Calculating hash for %s\n", key); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.5.2.14 retrieving revision 1.5.2.15 diff -u -r1.5.2.14 -r1.5.2.15 --- squid/src/protos.h 1 Jul 2007 08:34:29 -0000 1.5.2.14 +++ squid/src/protos.h 2 Jul 2007 07:37:01 -0000 1.5.2.15 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.5.2.14 2007/07/01 08:34:29 amosjeffries Exp $ + * $Id: protos.h,v 1.5.2.15 2007/07/02 07:37:01 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -109,7 +109,7 @@ extern void parse_time_t(time_t * var); extern void parse_cachedir_options(SwapDir * sd, struct cache_dir_option *options, int reconfiguring); extern void dump_cachedir_options(StoreEntry * e, struct cache_dir_option *options, SwapDir * sd); -extern void parse_sockaddr_storage_list_token(sockaddr_storage_list **, char *); +extern void parse_sockaddr_in_list_token(sockaddr_in_list **, char *); /* @@ -133,11 +133,11 @@ extern int cbdataLocked(const void *p); extern void clientdbInit(void); -extern void clientdbUpdate(struct sockaddr *, log_type, protocol_t, squid_off_t); -extern int clientdbCutoffDenied(struct sockaddr *); +extern void clientdbUpdate(struct in_addr, log_type, protocol_t, squid_off_t); +extern int clientdbCutoffDenied(struct in_addr); extern void clientdbDump(StoreEntry *); extern void clientdbFreeMemory(void); -extern int clientdbEstablished(struct sockaddr *, int); +extern int clientdbEstablished(struct in_addr, int); extern char *clientConstructTraceEcho(clientHttpRequest *); extern int checkNegativeHit(StoreEntry *); @@ -151,18 +151,18 @@ extern int commSetNonBlocking(int fd); extern int commUnsetNonBlocking(int fd); extern void commSetCloseOnExec(int fd); -extern int comm_accept(int fd, struct sockaddr *, struct sockaddr *); +extern int comm_accept(int fd, struct sockaddr_in *, struct sockaddr_in *); extern void comm_close(int fd); extern void comm_reset_close(int fd); #if LINGERING_CLOSE extern void comm_lingering_close(int fd); #endif -extern void commConnectStart(int fd, const char *, u_short, CNCB *, void *, struct sockaddr *addr); -extern int comm_connect_addr(int sock, const struct sockaddr *); +extern void commConnectStart(int fd, const char *, u_short, CNCB *, void *, struct in_addr *addr); +extern int comm_connect_addr(int sock, const struct sockaddr_in *); extern void comm_init(void); extern int comm_listen(int sock); -extern int comm_open(int, int, struct sockaddr *, int, const char *note); -extern int comm_openex(int, int, struct sockaddr *, int, unsigned char TOS, const char *); +extern int comm_open(int, int, struct in_addr, u_short port, int, const char *note); +extern int comm_openex(int, int, struct in_addr, u_short, int, unsigned char TOS, const char *); extern u_short comm_local_port(int fd); extern void commDeferFD(int fd); @@ -171,7 +171,7 @@ extern void commRemoveSlow(int fd); extern void comm_add_close_handler(int fd, PF *, void *); extern void comm_remove_close_handler(int fd, PF *, void *); -extern int comm_udp_sendto(int, const struct sockaddr *, int, const void *, int); +extern int comm_udp_sendto(int, const struct sockaddr_in *, int, const void *, int); extern void comm_write(int fd, const char *buf, int size, @@ -251,7 +251,7 @@ extern void idnsInit(void); extern void idnsShutdown(void); extern void idnsALookup(const char *, IDNSCB *, void *); -extern void idnsPTRLookup(const struct sockaddr *, IDNSCB *, void *); +extern void idnsPTRLookup(const struct in_addr, IDNSCB *, void *); extern void eventAdd(const char *name, EVH * func, void *arg, double when, int); extern void eventAddIsh(const char *name, EVH * func, void *arg, double delta_ish, int); @@ -283,12 +283,12 @@ extern void filemapFreeMemory(fileMap *); -extern void fqdncache_nbgethostbyaddr(struct sockaddr *, FQDNH *, void *); -extern const char *fqdncache_gethostbyaddr(struct sockaddr *, int flags); +extern void fqdncache_nbgethostbyaddr(struct in_addr, FQDNH *, void *); +extern const char *fqdncache_gethostbyaddr(struct in_addr, int flags); extern void fqdncache_init(void); extern void fqdnStats(StoreEntry *); extern void fqdncacheReleaseInvalid(const char *); -extern const char *fqdnFromAddr(struct sockaddr *); +extern const char *fqdnFromAddr(struct in_addr); extern int fqdncacheQueueDrain(void); extern void fqdncacheFreeMemory(void); extern void fqdncache_restart(void); @@ -535,7 +535,7 @@ const char *url, int reqnum, int pad); -extern int icpUdpSend(int, const struct sockaddr *, icp_common_t *, log_type, int); +extern int icpUdpSend(int, const struct sockaddr_in *, icp_common_t *, log_type, int); extern PF icpHandleUdp; extern PF icpUdpSendQueue; extern PF httpAccept; @@ -579,7 +579,7 @@ extern void wccp2ConnectionClose(void); #endif /* USE_WCCPv2 */ -extern void icpHandleIcpV3(int, struct sockaddr *, char *, int); +extern void icpHandleIcpV3(int, struct sockaddr_in, char *, int); extern int icpCheckUdpHit(StoreEntry *, request_t * request); extern void icpConnectionsOpen(void); extern void icpConnectionShutdown(void); @@ -597,8 +597,8 @@ extern void ipcache_init(void); extern void stat_ipcache_get(StoreEntry *); extern void ipcacheCycleAddr(const char *name, ipcache_addrs *); -extern void ipcacheMarkBadAddr(const char *name, struct sockaddr *); -extern void ipcacheMarkGoodAddr(const char *name, struct sockaddr *); +extern void ipcacheMarkBadAddr(const char *name, struct in_addr); +extern void ipcacheMarkGoodAddr(const char *name, struct in_addr); extern void ipcacheFreeMemory(void); extern ipcache_addrs *ipcacheCheckNumeric(const char *name); extern void ipcache_restart(void); @@ -665,7 +665,7 @@ int *exprep, int *timeout); extern void neighborAddAcl(const char *, const char *); -extern void neighborsUdpAck(const cache_key *, icp_common_t *, const struct sockaddr *); +extern void neighborsUdpAck(const cache_key *, icp_common_t *, const struct sockaddr_in *); extern void neighborAdd(const char *, const char *, int, int, int, int, int); extern void neighbors_init(void); extern peer *peerFindByName(const char *); @@ -686,22 +686,22 @@ extern void peerConnectSucceded(peer *); extern void dump_peer_options(StoreEntry *, peer *); extern int peerHTTPOkay(const peer *, request_t *); -extern peer *whichPeer(const struct sockaddr *from); +extern peer *whichPeer(const struct sockaddr_in *from); #if USE_HTCP -extern void neighborsHtcpReply(const cache_key *, htcpReplyData *, const struct sockaddr *); +extern void neighborsHtcpReply(const cache_key *, htcpReplyData *, const struct sockaddr_in *); #endif extern void peerAddFwdServer(FwdServer ** FS, peer * p, hier_code code); extern int peerAllowedToUse(const peer *, request_t *); extern void netdbInit(void); -extern void netdbHandlePingReply(const struct sockaddr *from, int hops, int rtt); +extern void netdbHandlePingReply(const struct sockaddr_in *from, int hops, int rtt); extern void netdbPingSite(const char *hostname); -extern int netdbHops(struct sockaddr *); +extern int netdbHops(struct in_addr); extern void netdbFreeMemory(void); extern int netdbHostHops(const char *host); extern int netdbHostRtt(const char *host); extern void netdbUpdatePeer(request_t *, peer * e, int rtt, int hops); -extern void netdbDeleteAddrNetwork(struct sockaddr *addr); +extern void netdbDeleteAddrNetwork(struct in_addr addr); extern void netdbBinaryExchange(StoreEntry *); extern EVH netdbExchangeStart; extern void netdbExchangeUpdatePeer(struct in_addr, peer *, double, double); @@ -736,7 +736,7 @@ extern void fwdLogRotate(void); extern void fwdStatus(FwdState *, http_status); #endif -struct sockaddr_storage *getOutgoingAddr(request_t * request); +struct in_addr getOutgoingAddr(request_t * request); unsigned long getOutgoingTOS(request_t * request); extern void urnStart(request_t *, StoreEntry *); @@ -763,14 +763,14 @@ extern void authenticateShutdown(void); extern void authenticateFixHeader(HttpReply *, auth_user_request_t *, request_t *, int, int); extern void authenticateAddTrailer(HttpReply *, auth_user_request_t *, request_t *, int); -extern auth_acl_t authenticateTryToAuthenticateAndSetAuthUser(auth_user_request_t **, http_hdr_type, request_t *, ConnStateData *, struct sockaddr *); +extern auth_acl_t authenticateTryToAuthenticateAndSetAuthUser(auth_user_request_t **, http_hdr_type, request_t *, ConnStateData *, struct in_addr); extern void authenticateAuthUserUnlock(auth_user_t * auth_user); extern void authenticateAuthUserLock(auth_user_t * auth_user); extern void authenticateAuthUserRequestUnlock(auth_user_request_t *); extern void authenticateAuthUserRequestLock(auth_user_request_t *); extern char *authenticateAuthUserRequestMessage(auth_user_request_t *); extern int authenticateAuthUserInuse(auth_user_t * auth_user); -extern void authenticateAuthUserRequestRemoveIp(auth_user_request_t *, struct sockaddr *); +extern void authenticateAuthUserRequestRemoveIp(auth_user_request_t *, struct in_addr); extern void authenticateAuthUserRequestClearIp(auth_user_request_t *); extern int authenticateAuthUserRequestIPCount(auth_user_request_t *); extern int authenticateDirection(auth_user_request_t *); @@ -812,7 +812,7 @@ /* ident.c */ #if USE_IDENT -extern void identStart(struct sockaddr *me, struct sockaddr *my_peer, +extern void identStart(struct sockaddr_in *me, struct sockaddr_in *my_peer, IDCB * callback, void *cbdata); extern void identInit(void); #endif @@ -1172,12 +1172,12 @@ extern ErrorState *errorCon(err_type type, http_status, request_t * request); extern int errorPageId(const char *page_name); -extern void pconnPush(int, const char *host, u_short port, const char *domain, struct sockaddr *client_address); -extern int pconnPop(const char *host, u_short port, const char *domain, struct sockaddr *client_address); -extern hash_link *pconnLookup(const char *peer, u_short port, const char *domain, struct sockaddr *client_address); +extern void pconnPush(int, const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port); +extern int pconnPop(const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port); +extern hash_link *pconnLookup(const char *peer, u_short port, const char *domain, struct in_addr *client_address, u_short client_port); extern void pconnInit(void); -extern int asnMatchIp(void *, struct sockaddr *); +extern int asnMatchIp(void *, struct in_addr); extern void asnInit(void); extern void asnFreeMemory(void); @@ -1208,8 +1208,6 @@ int xusleep(unsigned int usec); void keepCapabilities(void); -extern char *sockaddr_ntoa(struct sockaddr_storage *); - #if USE_HTCP extern void htcpInit(void); extern void htcpQuery(StoreEntry * e, request_t * req, peer * p); Index: squid/src/redirect.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/redirect.c,v retrieving revision 1.3.6.6 retrieving revision 1.3.6.7 diff -u -r1.3.6.6 -r1.3.6.7 --- squid/src/redirect.c 1 Jul 2007 05:44:24 -0000 1.3.6.6 +++ squid/src/redirect.c 2 Jul 2007 07:37:02 -0000 1.3.6.7 @@ -1,6 +1,6 @@ /* - * $Id: redirect.c,v 1.3.6.6 2007/07/01 05:44:24 amosjeffries Exp $ + * $Id: redirect.c,v 1.3.6.7 2007/07/02 07:37:02 amosjeffries Exp $ * * DEBUG: section 61 Redirector * AUTHOR: Duane Wessels @@ -38,7 +38,7 @@ typedef struct { void *data; char *orig_url; - struct sockaddr_storage client_addr; + struct in_addr client_addr; const char *client_ident; const char *method_s; RH *handler; @@ -109,7 +109,7 @@ } r = cbdataAlloc(redirectStateData); r->orig_url = xstrdup(http->uri); - xmemcpy(&r->client_addr, &conn->log_addr, sizeof(struct sockaddr_storage)); + r->client_addr = conn->log_addr; r->client_ident = NULL; if (http->request->auth_user_request) r->client_ident = authenticateUserRequestUsername(http->request->auth_user_request); @@ -128,11 +128,11 @@ r->handler = handler; r->data = data; cbdataLock(r->data); - if ((fqdn = fqdncache_gethostbyaddr(&r->client_addr, 0)) == NULL) + if ((fqdn = fqdncache_gethostbyaddr(r->client_addr, 0)) == NULL) fqdn = dash_str; snprintf(buf, 8191, "%s %s/%s %s %s %s", r->orig_url, - sockaddr_ntoa(&r->client_addr), + inet_ntoa(r->client_addr), fqdn, r->client_ident[0] ? rfc1738_escape(r->client_ident) : dash_str, r->method_s, Index: squid/src/send-announce.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/send-announce.c,v retrieving revision 1.3.6.5 retrieving revision 1.3.6.6 diff -u -r1.3.6.5 -r1.3.6.6 --- squid/src/send-announce.c 1 Jul 2007 05:44:24 -0000 1.3.6.5 +++ squid/src/send-announce.c 2 Jul 2007 07:37:02 -0000 1.3.6.6 @@ -1,6 +1,6 @@ /* - * $Id: send-announce.c,v 1.3.6.5 2007/07/01 05:44:24 amosjeffries Exp $ + * $Id: send-announce.c,v 1.3.6.6 2007/07/02 07:37:02 amosjeffries Exp $ * * DEBUG: section 27 Cache Announcer * AUTHOR: Duane Wessels @@ -53,7 +53,7 @@ { LOCAL_ARRAY(char, tbuf, 256); LOCAL_ARRAY(char, sndbuf, BUFSIZ); - struct sockaddr_storage S; + struct sockaddr_in S; char *host = Config.Announce.host; char *file = NULL; u_short port = Config.Announce.port; @@ -96,11 +96,9 @@ } } memset(&S, '\0', sizeof(S)); - xmemcpy(&S, &ia->in_addrs[0], sizeof(S)); - if (S.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&S)->sin6_port = htons(port); - if (S.ss_family == AF_INET) - ((struct sockaddr_in *)&S)->sin_port = htons(port); + S.sin_family = AF_INET; + S.sin_port = htons(port); + S.sin_addr = ia->in_addrs[0]; assert(theOutIcpConnection > 0); x = comm_udp_sendto(theOutIcpConnection, &S, sizeof(S), Index: squid/src/snmp_agent.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/snmp_agent.c,v retrieving revision 1.3.6.5 retrieving revision 1.3.6.6 diff -u -r1.3.6.5 -r1.3.6.6 --- squid/src/snmp_agent.c 1 Jul 2007 05:44:24 -0000 1.3.6.5 +++ squid/src/snmp_agent.c 2 Jul 2007 07:37:02 -0000 1.3.6.6 @@ -1,6 +1,6 @@ /* - * $Id: snmp_agent.c,v 1.3.6.5 2007/07/01 05:44:24 amosjeffries Exp $ + * $Id: snmp_agent.c,v 1.3.6.6 2007/07/02 07:37:02 amosjeffries Exp $ * * DEBUG: section 49 SNMP Interface * AUTHOR: Kostas Anagnostakis @@ -164,7 +164,7 @@ laddr = oid2addr(&Var->name[LEN_SQ_MESH + 3]); for (p = Config.peers; p != NULL; p = p->next, cnt++) { index++; - if (((struct sockaddr_in *)&p->in_addr)->sin_addr.s_addr == laddr->s_addr) + if (p->in_addr.sin_addr.s_addr == laddr->s_addr) break; } break; @@ -201,7 +201,7 @@ break; case MESH_PTBL_IP: Answer = snmp_var_new_integer(Var->name, Var->name_length, - (snint) ((struct sockaddr_in *)&p->in_addr)->sin_addr.s_addr, + (snint) p->in_addr.sin_addr.s_addr, SMI_IPADDRESS); break; case MESH_PTBL_HTTP: Index: squid/src/snmp_core.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/snmp_core.c,v retrieving revision 1.3.6.9 retrieving revision 1.3.6.10 diff -u -r1.3.6.9 -r1.3.6.10 --- squid/src/snmp_core.c 1 Jul 2007 05:44:24 -0000 1.3.6.9 +++ squid/src/snmp_core.c 2 Jul 2007 07:37:03 -0000 1.3.6.10 @@ -1,6 +1,6 @@ /* - * $Id: snmp_core.c,v 1.3.6.9 2007/07/01 05:44:24 amosjeffries Exp $ + * $Id: snmp_core.c,v 1.3.6.10 2007/07/02 07:37:03 amosjeffries Exp $ * * DEBUG: section 49 SNMP support * AUTHOR: Glenn Chisholm @@ -390,21 +390,17 @@ snmpConnectionOpen(void) { u_short port; - struct sockaddr_storage xaddr; + struct sockaddr_in xaddr; socklen_t len; int x; debug(49, 5) ("snmpConnectionOpen: Called\n"); if ((port = Config.Port.snmp) > (u_short) 0) { enter_suid(); - - if (Config.Addrs.snmp_incoming.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&Config.Addrs.snmp_incoming)->sin6_port = ntohs(port); - else - ((struct sockaddr_in *)&Config.Addrs.snmp_incoming)->sin_port = ntohs(port); theInSnmpConnection = comm_open(SOCK_DGRAM, IPPROTO_UDP, - &Config.Addrs.snmp_incoming, + Config.Addrs.snmp_incoming, + port, COMM_NONBLOCKING, "SNMP Port"); leave_suid(); @@ -413,18 +409,12 @@ commSetSelect(theInSnmpConnection, COMM_SELECT_READ, snmpHandleUdp, NULL, 0); debug(1, 1) ("Accepting SNMP messages on port %d, FD %d.\n", (int) port, theInSnmpConnection); - if ((Config.Addrs.snmp_outgoing.ss_family == AF_INET6 && - !IN6_IS_ADDR_ALLF(&(((struct sockaddr_in6 *)&Config.Addrs.snmp_outgoing)->sin6_addr))) || - (Config.Addrs.snmp_outgoing.ss_family == AF_INET && - ((struct sockaddr_in *)&Config.Addrs.snmp_outgoing)->sin_addr.s_addr != no_addr.s_addr)) { + if (Config.Addrs.snmp_outgoing.s_addr != no_addr.s_addr) { enter_suid(); - if (Config.Addrs.snmp_outgoing.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&Config.Addrs.snmp_outgoing)->sin6_port = ntohs(port); - else - ((struct sockaddr_in *)&Config.Addrs.snmp_outgoing)->sin_port = ntohs(port); theOutSnmpConnection = comm_open(SOCK_DGRAM, IPPROTO_UDP, - &Config.Addrs.snmp_outgoing, + Config.Addrs.snmp_outgoing, + port, COMM_NONBLOCKING, "SNMP Port"); leave_suid(); @@ -441,8 +431,8 @@ } else { theOutSnmpConnection = theInSnmpConnection; } - memset(&theOutSNMPAddr, '\0', sizeof(struct sockaddr_storage)); - len = sizeof(struct sockaddr_storage); + memset(&theOutSNMPAddr, '\0', sizeof(struct in_addr)); + len = sizeof(struct sockaddr_in); memset(&xaddr, '\0', len); x = getsockname(theOutSnmpConnection, (struct sockaddr *) &xaddr, &len); @@ -450,7 +440,7 @@ debug(51, 1) ("theOutSnmpConnection FD %d: getsockname: %s\n", theOutSnmpConnection, xstrerror()); else - xmemcpy(&theOutSNMPAddr, &xaddr, sizeof(xaddr)); + theOutSNMPAddr = xaddr.sin_addr; } } @@ -500,7 +490,7 @@ snmpHandleUdp(int sock, void *not_used) { LOCAL_ARRAY(char, buf, SNMP_REQUEST_SIZE); - struct sockaddr_storage from; + struct sockaddr_in from; socklen_t from_len; snmp_request_t *snmp_rq; int len; @@ -508,7 +498,7 @@ debug(49, 5) ("snmpHandleUdp: Called.\n"); commSetSelect(sock, COMM_SELECT_READ, snmpHandleUdp, NULL, 0); - from_len = sizeof(struct sockaddr_storage); + from_len = sizeof(struct sockaddr_in); memset(&from, '\0', from_len); memset(buf, '\0', SNMP_REQUEST_SIZE); @@ -526,14 +516,14 @@ debug(49, 3) ("snmpHandleUdp: FD %d: received %d bytes from %s.\n", sock, len, - sockaddr_ntoa(&from)); + inet_ntoa(from.sin_addr)); snmp_rq = xcalloc(1, sizeof(snmp_request_t)); snmp_rq->buf = (u_char *) buf; snmp_rq->len = len; snmp_rq->sock = sock; snmp_rq->outbuf = xmalloc(snmp_rq->outlen = SNMP_REQUEST_SIZE); - xmemcpy(&snmp_rq->from, &from, sizeof(struct sockaddr_storage)); + xmemcpy(&snmp_rq->from, &from, sizeof(struct sockaddr_in)); snmpDecodePacket(snmp_rq); xfree(snmp_rq->outbuf); xfree(snmp_rq); @@ -561,7 +551,7 @@ rq->session.Version = SNMP_VERSION_1; Community = snmp_parse(&rq->session, PDU, buf, len); memset(&checklist, '\0', sizeof(checklist)); - xmemcpy(&checklist.src_addr, &rq->from, SOCKLEN(&rq->from)); + checklist.src_addr = rq->from.sin_addr; checklist.snmp_community = (char *) Community; if (Community) @@ -573,7 +563,7 @@ snmpConstructReponse(rq); } else { debug(49, 1) ("Failed SNMP agent query from : %s.\n", - sockaddr_ntoa(&rq->from)); + inet_ntoa(rq->from.sin_addr)); snmp_free_pdu(PDU); } if (Community) @@ -593,7 +583,7 @@ snmp_free_pdu(rq->PDU); if (RespPDU != NULL) { snmp_build(&rq->session, RespPDU, rq->outbuf, &rq->outlen); - comm_udp_sendto(rq->sock, &rq->from, SOCKLEN(&rq->from), rq->outbuf, rq->outlen); + comm_udp_sendto(rq->sock, &rq->from, sizeof(rq->from), rq->outbuf, rq->outlen); snmp_free_pdu(RespPDU); } } @@ -827,46 +817,24 @@ if (peerptr == NULL) { /* Do nothing */ } else if (*len <= current->len) { - if (peerptr->in_addr.ss_family == AF_INET6) - instance = xmalloc(sizeof(name) * (*len + 16)); - else - instance = xmalloc(sizeof(name) * (*len + 4)); + instance = xmalloc(sizeof(name) * (*len + 4)); xmemcpy(instance, name, (sizeof(name) * *len)); - if (peerptr->in_addr.ss_family == AF_INET6) - cp = (u_char *) & (((struct sockaddr_in6 *)&peerptr->in_addr)->sin6_addr.s6_addr); - else - cp = (u_char *) & (((struct sockaddr_in *)&peerptr->in_addr)->sin_addr.s_addr); + cp = (u_char *) & (peerptr->in_addr.sin_addr.s_addr); instance[*len] = *cp++; instance[*len + 1] = *cp++; instance[*len + 2] = *cp++; instance[*len + 3] = *cp++; - if (peerptr->in_addr.ss_family == AF_INET6) { - instance[*len + 4] = *cp++; - instance[*len + 5] = *cp++; - instance[*len + 6] = *cp++; - instance[*len + 7] = *cp++; - instance[*len + 8] = *cp++; - instance[*len + 9] = *cp++; - instance[*len + 10] = *cp++; - instance[*len + 11] = *cp++; - instance[*len + 12] = *cp++; - instance[*len + 13] = *cp++; - instance[*len + 14] = *cp++; - instance[*len + 15] = *cp++; - *len += 16; - } - else - *len += 4; + *len += 4; } else { laddr = oid2addr(&name[*len - 4]); host_addr = inet_ntoa(*laddr); last_addr = xstrdup(host_addr); skip_duplicate: - current_addr = sockaddr_ntoa(&peerptr->in_addr); + current_addr = inet_ntoa(peerptr->in_addr.sin_addr); while (peerptr && strcmp(last_addr, current_addr) != 0) { peerptr = peerptr->next; if (peerptr) - current_addr = sockaddr_ntoa(&peerptr->in_addr); + current_addr = inet_ntoa(peerptr->in_addr.sin_addr); } /* Find the next peer */ @@ -875,7 +843,7 @@ /* watch out for duplicate addresses */ for (peerptr2 = Config.peers; peerptr && peerptr2 != peerptr; peerptr2 = peerptr2->next) { - if (memcmp(&peerptr2->in_addr, &peerptr->in_addr, SOCKLEN(&peerptr->in_addr))) { + if (peerptr2->in_addr.sin_addr.s_addr == peerptr->in_addr.sin_addr.s_addr) { /* ouch.. there are more than one peer on this IP. Skip the second one */ peerptr = peerptr->next; if (peerptr) @@ -888,23 +856,7 @@ if (peerptr) { instance = xmalloc(sizeof(name) * (*len)); xmemcpy(instance, name, (sizeof(name) * *len)); - if (peerptr->in_addr.ss_family == AF_INET6) { - cp = (u_char *) & (((struct sockaddr_in6 *)&peerptr->in_addr)->sin6_addr.s6_addr); - instance[*len - 16] = *cp++; - instance[*len - 15] = *cp++; - instance[*len - 14] = *cp++; - instance[*len - 13] = *cp++; - instance[*len - 12] = *cp++; - instance[*len - 11] = *cp++; - instance[*len - 10] = *cp++; - instance[*len - 9] = *cp++; - instance[*len - 8] = *cp++; - instance[*len - 7] = *cp++; - instance[*len - 6] = *cp++; - instance[*len - 5] = *cp++; - } - else - cp = (u_char *) & (((struct sockaddr_in *)&peerptr->in_addr)->sin_addr.s_addr); + cp = (u_char *) & (peerptr->in_addr.sin_addr.s_addr); instance[*len - 4] = *cp++; instance[*len - 3] = *cp++; instance[*len - 2] = *cp++; Index: squid/src/ssl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ssl.c,v retrieving revision 1.3.6.9 retrieving revision 1.3.6.10 diff -u -r1.3.6.9 -r1.3.6.10 --- squid/src/ssl.c 1 Jul 2007 08:34:29 -0000 1.3.6.9 +++ squid/src/ssl.c 2 Jul 2007 07:37:03 -0000 1.3.6.10 @@ -1,6 +1,6 @@ /* - * $Id: ssl.c,v 1.3.6.9 2007/07/01 08:34:29 amosjeffries Exp $ + * $Id: ssl.c,v 1.3.6.10 2007/07/02 07:37:03 amosjeffries Exp $ * * DEBUG: section 26 Secure Sockets Layer Proxy * AUTHOR: Duane Wessels @@ -36,8 +36,6 @@ #include "squid.h" typedef struct { - hash_link hash; /* dummy, must be first */ - int ia_cur; char *url; char *host; /* either request->host or proxy host */ u_short port; @@ -65,7 +63,6 @@ static PF sslReadClient; static PF sslReadServer; static PF sslTimeout; -static void sslConnectTimeout(int fd, void *data); static PF sslWriteClient; static PF sslWriteServer; static PSC sslPeerSelectComplete; @@ -408,6 +405,7 @@ comm_close(sslState->client.fd); } + static void sslConnectDone(int fd, int status, void *data) { @@ -432,50 +430,6 @@ err->callback = sslErrorComplete; err->callback_data = sslState; errorSend(sslState->client.fd, err); - } else if (status == COMM_ERR_INV_ARGS) { - int newsock; - struct sockaddr_storage cursockaddr, newsockaddr; - socklen_t cursocklen = sizeof(cursockaddr); - - getsockname(fd, (struct sockaddr *)&cursockaddr, &cursocklen); - memset(&newsockaddr, '\0', sizeof(newsockaddr)); - if (cursockaddr.ss_family == AF_INET6) - newsockaddr.ss_family = AF_INET; - else - newsockaddr.ss_family = AF_INET6; - newsock = comm_openex(SOCK_STREAM, - IPPROTO_TCP, - (struct sockaddr*)&newsockaddr, - COMM_NONBLOCKING, - 0, - sslState->url); - if (newsock == COMM_ERROR) { - debug(26, 4) ("sslStart: Failed because we're out of sockets.\n"); - err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR, request); - err->xerrno = errno; - err->callback = sslErrorComplete; - err->callback_data = sslState; - errorSend(sslState->client.fd, err); - return; - } - comm_remove_close_handler(sslState->server.fd, - sslServerClosed, - sslState); - comm_close(sslState->server.fd); - sslState->server.fd = newsock; - comm_add_close_handler(sslState->server.fd, - sslServerClosed, - sslState); - sslSetSelect(sslState); - commSetTimeout(sslState->server.fd, - Config.Timeout.connect, - sslConnectTimeout, - sslState); - commConnectStart(sslState->server.fd, - sslState->host, sslState->port, - sslConnectDone, - sslState, - &newsockaddr); } else if (status != COMM_OK) { comm_close(fd); err = errorCon(ERR_CONNECT_FAIL, HTTP_SERVICE_UNAVAILABLE, request); @@ -536,18 +490,14 @@ int fd = http->conn->fd; request_t *request = http->request; char *url = http->uri; - struct sockaddr_storage outgoing; + struct in_addr outgoing; unsigned long tos; - struct sockaddr_storage addr; /* * client_addr == no_addr indicates this is an "internal" request * from peer_digest.c, asn.c, netdb.c, etc and should always * be allowed. yuck, I know. */ - if ( ((request->client_addr.ss_family == AF_INET6) && - !IN6_IS_ADDR_ALLF(&((struct sockaddr_in6 *)&request->client_addr)->sin6_addr)) || - ((request->client_addr.ss_family == AF_INET) && - (((struct sockaddr_in *)&request->client_addr)->sin_addr.s_addr != no_addr.s_addr))) { + if (request->client_addr.s_addr != no_addr.s_addr) { /* * Check if this host is allowed to fetch MISSES from us (miss_access) */ @@ -563,13 +513,15 @@ RequestMethods[request->method].str, url); statCounter.server.all.requests++; statCounter.server.other.requests++; + outgoing = getOutgoingAddr(request); + tos = getOutgoingTOS(request); /* Create socket. */ - memset(&addr, '\0', sizeof(addr)); - addr.ss_family = AF_INET; - sock = comm_open(SOCK_STREAM, + sock = comm_openex(SOCK_STREAM, IPPROTO_TCP, - &addr, + outgoing, + 0, COMM_NONBLOCKING, + tos, url); if (sock == COMM_ERROR) { debug(26, 4) ("sslStart: Failed because we're out of sockets.\n"); @@ -595,8 +547,7 @@ sslState->client.buf = xmalloc(SQUID_TCP_SO_RCVBUF); /* Copy any pending data from the client connection */ sslState->client.len = http->conn->in.offset; -// AYJ: 'outgoing' in uninitialised local variable. sslState->request->out_ip = outgoing; - sslState->ia_cur = -1; + sslState->request->out_ip = outgoing; if (sslState->client.len > 0) { if (sslState->client.len > SQUID_TCP_SO_RCVBUF) { safe_free(sslState->client.buf); @@ -655,13 +606,9 @@ static void sslPeerSelectComplete(FwdServer * fs, void *data) { - struct sockaddr_storage sslsock, cursockaddr; - ErrorState *err = NULL; - int newsock = -1; SslStateData *sslState = data; request_t *request = sslState->request; peer *g = NULL; - socklen_t cursocklen = sizeof(cursockaddr); if (fs == NULL) { ErrorState *err; err = errorCon(ERR_CANNOT_FORWARD, HTTP_SERVICE_UNAVAILABLE, sslState->request); @@ -672,14 +619,7 @@ return; } sslState->servers = fs; - sslState->host = fs->peer ? NULL : request->host; - if (fs->peer) - xmemcpy(&sslsock, &fs->peer->in_addr, sizeof(struct sockaddr_storage)); - else - memset(&sslsock, '\0', sizeof(struct sockaddr_storage)); -/* - xmemcpy(&sslsock, &request->client_addr, sizeof(struct sockaddr_storage)); -*/ + sslState->host = fs->peer ? fs->peer->host : request->host; if (fs->peer == NULL) { sslState->port = request->port; } else if (fs->peer->http_port != 0) { @@ -703,44 +643,13 @@ sslState->delay_id = 0; } #endif - if (sslsock.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&sslsock)->sin6_port = sslState->port; - else - ((struct sockaddr_in *)&sslsock)->sin_port = sslState->port; - getsockname(sslState->server.fd, (struct sockaddr *)&cursockaddr, &cursocklen); - if (!sslState->host && cursockaddr.ss_family != sslsock.ss_family) { - memset(&cursockaddr, '\0', sizeof(cursockaddr)); - cursockaddr.ss_family = sslsock.ss_family; - newsock = comm_openex(SOCK_STREAM, - IPPROTO_TCP, - &cursockaddr, - COMM_NONBLOCKING, - 0, - sslState->url); - if (newsock == COMM_ERROR) { - debug(26, 4) ("sslStart: Failed because we're out of sockets.\n"); - err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR, request); - err->xerrno = errno; - errorSend(sslState->client.fd, err); - return; - } - comm_remove_close_handler(sslState->server.fd, - sslServerClosed, - sslState); - comm_close(sslState->server.fd); - - sslState->server.fd = newsock; - comm_add_close_handler(sslState->server.fd, - sslServerClosed, - sslState); - sslSetSelect(sslState); - } commSetTimeout(sslState->server.fd, Config.Timeout.connect, sslConnectTimeout, sslState); commConnectStart(sslState->server.fd, - sslState->host, sslState->port, + sslState->host, + sslState->port, sslConnectDone, sslState, NULL); Index: squid/src/stat.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/stat.c,v retrieving revision 1.4.6.7 retrieving revision 1.4.6.8 diff -u -r1.4.6.7 -r1.4.6.8 --- squid/src/stat.c 1 Jul 2007 05:44:24 -0000 1.4.6.7 +++ squid/src/stat.c 2 Jul 2007 07:37:03 -0000 1.4.6.8 @@ -1,6 +1,6 @@ /* - * $Id: stat.c,v 1.4.6.7 2007/07/01 05:44:24 amosjeffries Exp $ + * $Id: stat.c,v 1.4.6.8 2007/07/02 07:37:03 amosjeffries Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -1460,7 +1460,6 @@ ConnStateData *conn; StoreEntry *e; int fd; - char host[100], port[8]; for (i = ClientActiveRequests.head; i; i = i->next) { const char *p = NULL; http = i->data; @@ -1474,12 +1473,12 @@ storeAppendPrintf(s, "\tFD desc: %s\n", fd_table[fd].desc); storeAppendPrintf(s, "\tin: buf %p, offset %ld, size %ld\n", conn->in.buf, (long int) conn->in.offset, (long int) conn->in.size); - getnameinfo(&conn->peer, sizeof(struct sockaddr_storage), - host, 100, port, 8, NI_NUMERICHOST|NI_NUMERICSERV); - storeAppendPrintf(s, "\tpeer: %s:%s\n", host, port); - getnameinfo(&conn->me, sizeof(struct sockaddr_storage), - host, 100, port, 8, NI_NUMERICHOST|NI_NUMERICSERV); - storeAppendPrintf(s, "\tme: %s:%s\n", host, port); + storeAppendPrintf(s, "\tpeer: %s:%d\n", + inet_ntoa(conn->peer.sin_addr), + ntohs(conn->peer.sin_port)); + storeAppendPrintf(s, "\tme: %s:%d\n", + inet_ntoa(conn->me.sin_addr), + ntohs(conn->me.sin_port)); storeAppendPrintf(s, "\tnrequests: %d\n", conn->nrequests); storeAppendPrintf(s, "\tdefer: n %d, until %ld\n", Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.7.2.12 retrieving revision 1.7.2.13 diff -u -r1.7.2.12 -r1.7.2.13 --- squid/src/structs.h 1 Jul 2007 08:34:29 -0000 1.7.2.12 +++ squid/src/structs.h 2 Jul 2007 07:37:03 -0000 1.7.2.13 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.7.2.12 2007/07/01 08:34:29 amosjeffries Exp $ + * $Id: structs.h,v 1.7.2.13 2007/07/02 07:37:03 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -72,9 +72,9 @@ }; struct _acl_ip_data { - struct sockaddr_storage addr1; /* if addr2 non-zero then its a range */ - struct sockaddr_storage addr2; - int masklen; + struct in_addr addr1; /* if addr2 non-zero then its a range */ + struct in_addr addr2; + struct in_addr mask; acl_ip_data *next; /* used for parsing, not for storing */ }; @@ -114,7 +114,7 @@ struct _auth_user_ip_t { dlink_node node; /* IP addr this user authenticated from */ - struct sockaddr_storage ipaddr; + struct in_addr ipaddr; time_t ip_expiretime; }; @@ -254,7 +254,7 @@ int sock; long reqid; int outlen; - struct in_addr from; + struct sockaddr_in from; struct snmp_pdu *PDU; aclCheck_t *acl_checklist; u_char *community; @@ -287,7 +287,7 @@ struct _acl_address { acl_address *next; acl_list *acl_list; - struct sockaddr_storage addr; + struct in_addr addr; }; struct _acl_tos { @@ -298,9 +298,9 @@ struct _aclCheck_t { const acl_access *access_list; - struct sockaddr_storage src_addr; - struct sockaddr_storage dst_addr; - struct sockaddr_storage my_addr; + struct in_addr src_addr; + struct in_addr dst_addr; + struct in_addr my_addr; unsigned short my_port; request_t *request; /* for acls that look at reply data */ @@ -351,14 +351,14 @@ unsigned int internal:1; }; -struct _sockaddr_storage_list { - struct sockaddr_storage s; - sockaddr_storage_list *next; +struct _sockaddr_in_list { + struct sockaddr_in s; + sockaddr_in_list *next; }; struct _http_port_list { http_port_list *next; - struct sockaddr_storage s; + struct sockaddr_in s; char *protocol; /* protocol name */ char *name; /* visible name */ char *defaultsite; /* default web site */ @@ -492,15 +492,15 @@ #endif #if USE_WCCP struct { - struct sockaddr_storage router; - struct sockaddr_storage address; + struct in_addr router; + struct in_addr address; int version; } Wccp; #endif #if USE_WCCPv2 struct { - sockaddr_storage_list *router; - struct sockaddr_storage address; + sockaddr_in_list *router; + struct in_addr address; int forwarding_method; int return_method; int assignment_method; @@ -581,17 +581,13 @@ u_short port; } Announce; struct { - struct sockaddr_storage udp_incoming; - struct sockaddr_storage udp_outgoing; + struct in_addr udp_incoming; + struct in_addr udp_outgoing; #if SQUID_SNMP - struct sockaddr_storage snmp_incoming; - struct sockaddr_storage snmp_outgoing; + struct in_addr snmp_incoming; + struct in_addr snmp_outgoing; #endif - struct sockaddr_storage client_netmask; - struct sockaddr_storage udp6_incoming; - struct sockaddr_storage udp6_outgoing; - int client_masklen; - int client6_masklen; + struct in_addr client_netmask; } Addrs; squid_off_t tcpRcvBufsz; squid_off_t udpMaxHitObjsz; @@ -760,7 +756,7 @@ squid_off_t rangeOffsetLimit; #if MULTICAST_MISS_STREAM struct { - struct sockaddr_storage addr; + struct in_addr addr; int ttl; unsigned short port; char *encode_key; @@ -870,9 +866,9 @@ unsigned int type; u_short local_port; u_short remote_port; - struct sockaddr_storage local_addr; + struct in_addr local_addr; unsigned char tos; - char ipaddr[80]; /* dotted decimal address of peer */ + char ipaddr[16]; /* dotted decimal address of peer */ const char *desc; char descbuf[FD_DESC_SZ]; struct { @@ -1119,7 +1115,7 @@ }; struct _icpUdpData { - struct sockaddr_storage address; + struct sockaddr_in address; void *msg; size_t len; icpUdpData *next; @@ -1166,8 +1162,8 @@ icp_opcode opcode; } icp; struct { - struct sockaddr_storage caddr; - struct sockaddr_storage out_ip; + struct in_addr caddr; + struct in_addr out_ip; squid_off_t size; size_t rq_size; log_type code; @@ -1264,9 +1260,9 @@ /* the user details for connection based authentication */ auth_user_request_t *auth_user_request; dlink_list reqs; - struct sockaddr_storage peer; - struct sockaddr_storage me; - struct sockaddr_storage log_addr; + struct sockaddr_in peer; + struct sockaddr_in me; + struct in_addr log_addr; char rfc931[USER_IDENT_SZ]; int nrequests; struct { @@ -1286,7 +1282,7 @@ }; struct _ipcache_addrs { - struct sockaddr_storage *in_addrs; + struct in_addr *in_addrs; unsigned char *bad_mask; unsigned char count; unsigned char cur; @@ -1386,12 +1382,10 @@ #endif struct _peer { - hash_link hash; /* dummy, must be first */ - int ia_cur; char *name; char *host; peer_t type; - struct sockaddr_storage in_addr; + struct sockaddr_in in_addr; struct { int pings_sent; int pings_acked; @@ -1465,7 +1459,7 @@ char *digest_url; #endif int tcp_up; /* 0 if a connect() fails */ - struct sockaddr_storage addresses[10]; + struct in_addr addresses[10]; int n_addresses; int rr_count; int rr_lastcount; @@ -1559,14 +1553,14 @@ void *callback_data; FwdServer *servers; /* - * Why are these struct sockaddr_storage instead of peer *? Because a + * Why are these struct sockaddr_in instead of peer *? Because a * peer structure can become invalid during the peer selection * phase, specifically after a reconfigure. Thus we need to lookup * the peer * based on the address when we are finally ready to * reference the peer structure. */ - struct sockaddr_storage first_parent_miss; - struct sockaddr_storage closest_parent_miss; + struct sockaddr_in first_parent_miss; + struct sockaddr_in closest_parent_miss; /* * ->hit and ->secho can be peer* because they should only be * accessed during the thread when they are set @@ -1582,14 +1576,14 @@ #if USE_ICMP struct _pingerEchoData { - struct sockaddr_storage to; + struct in_addr to; unsigned char opcode; int psize; char payload[PINGER_PAYLOAD_SZ]; }; struct _pingerReplyData { - struct sockaddr_storage from; + struct in_addr from; unsigned char opcode; int rtt; int hops; @@ -1606,7 +1600,7 @@ u_num32 reqnum; /* req number (req'd for UDP) */ u_num32 flags; u_num32 pad; - struct sockaddr_storage shostid; /* sender host id */ + u_num32 shostid; /* sender host id */ }; struct _iostats { @@ -1889,12 +1883,13 @@ time_t ims; int imslen; int max_forwards; + /* these in_addr's could probably be sockaddr_in's */ unsigned short client_port; - struct sockaddr_storage client_addr; + struct in_addr client_addr; #if FOLLOW_X_FORWARDED_FOR - struct sockaddr_storage indirect_client_addr; /* after following X-Forwarded-For */ + struct in_addr indirect_client_addr; /* after following X-Forwarded-For */ #endif /* FOLLOW_X_FORWARDED_FOR */ - struct sockaddr_storage my_addr; + struct in_addr my_addr; unsigned short my_port; HttpHeader header; squid_off_t content_length; @@ -1913,7 +1908,7 @@ char *peer_domain; /* Configured peer forceddomain */ BODY_HANDLER *body_reader; void *body_reader_data; - struct sockaddr_storage out_ip; + struct in_addr out_ip; String extacl_log; /* String to be used for access.log purposes */ const char *extacl_user; /* User name returned by extacl lookup */ const char *extacl_passwd; /* Password returned by extacl lookup */ @@ -1962,7 +1957,7 @@ int xerrno; char *dnsserver_msg; time_t ttl; - struct sockaddr_storage src_addr; + struct in_addr src_addr; char *redirect_url; ERCB *callback; void *callback_data; @@ -2203,7 +2198,7 @@ struct _ClientInfo { hash_link hash; /* must be first */ - struct sockaddr_storage addr; + struct in_addr addr; struct { int result_hist[LOG_TYPE_MAX]; int n_requests; @@ -2237,15 +2232,11 @@ }; struct _FwdState { - hash_link hash; /* dummy, must be first */ - int ia_cur; int client_fd; /* XXX unnecessary */ StoreEntry *entry; request_t *request; FwdServer *servers; int server_fd; - int server_fd_was_v4; - int server_fd_was_inv_args; ErrorState *err; time_t start; int n_tries; @@ -2258,7 +2249,7 @@ unsigned int ftp_pasv_failed:1; } flags; #if LINUX_NETFILTER - struct sockaddr_storage src; + struct sockaddr_in src; #endif }; Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.4.2.12 retrieving revision 1.4.2.13 diff -u -r1.4.2.12 -r1.4.2.13 --- squid/src/tools.c 1 Jul 2007 08:34:30 -0000 1.4.2.12 +++ squid/src/tools.c 2 Jul 2007 07:37:03 -0000 1.4.2.13 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.4.2.12 2007/07/01 08:34:30 amosjeffries Exp $ + * $Id: tools.c,v 1.4.2.13 2007/07/02 07:37:03 amosjeffries Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -499,10 +499,10 @@ host[0] = '\0'; memcpy(&sa, &any_addr, sizeof(sa)); if (Config.Sockaddr.http && sa.s_addr == any_addr.s_addr) - memcpy(&sa, &((struct sockaddr_in *)&Config.Sockaddr.http->s)->sin_addr, sizeof(sa)); + memcpy(&sa, &Config.Sockaddr.http->s.sin_addr, sizeof(sa)); #if USE_SSL if (Config.Sockaddr.https && sa.s_addr == any_addr.s_addr) - memcpy(&sa, &((struct sockaddr_in *)&Config.Sockaddr.https->http.s)->sin_addr, sizeof(sa)); + memcpy(&sa, &Config.Sockaddr.https->http.s.sin_addr, sizeof(sa)); #endif /* * If the first http_port address has a specific address, try a @@ -1312,10 +1312,10 @@ getMyPort(void) { if (Config.Sockaddr.http) - return ntohs(((struct sockaddr_in *)&Config.Sockaddr.http->s)->sin_port); + return ntohs(Config.Sockaddr.http->s.sin_port); #if USE_SSL if (Config.Sockaddr.https) - return ntohs(((struct sockaddr_in *)&Config.Sockaddr.https->http.s)->sin_port); + return ntohs(Config.Sockaddr.https->http.s.sin_port); #endif fatal("No port defined"); return 0; /* NOT REACHED */ @@ -1363,15 +1363,6 @@ #endif } -char * -sockaddr_ntoa(struct sockaddr_storage *addr) -{ - static char host[100]; - memset(host, '\0', 100); - getnameinfo((struct sockaddr *)addr, SOCKLEN(addr), host, 100, NULL, 0, NI_NUMERICHOST); - return host; -} - /* XXX this is ipv4-only aware atm */ const char * xinet_ntoa(const struct in_addr addr) Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.4.2.7 retrieving revision 1.4.2.8 diff -u -r1.4.2.7 -r1.4.2.8 --- squid/src/typedefs.h 1 Jul 2007 05:44:25 -0000 1.4.2.7 +++ squid/src/typedefs.h 2 Jul 2007 07:37:04 -0000 1.4.2.8 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.4.2.7 2007/07/01 05:44:25 amosjeffries Exp $ + * $Id: typedefs.h,v 1.4.2.8 2007/07/02 07:37:04 amosjeffries Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -108,7 +108,7 @@ typedef struct _intrange intrange; typedef struct _ushortlist ushortlist; typedef struct _relist relist; -typedef struct _sockaddr_storage_list sockaddr_storage_list; +typedef struct _sockaddr_in_list sockaddr_in_list; typedef struct _http_port_list http_port_list; typedef struct _https_port_list https_port_list; typedef struct _SquidConfig SquidConfig; Index: squid/src/url.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/url.c,v retrieving revision 1.3.6.7 retrieving revision 1.3.6.8 diff -u -r1.3.6.7 -r1.3.6.8 --- squid/src/url.c 1 Jul 2007 08:34:30 -0000 1.3.6.7 +++ squid/src/url.c 2 Jul 2007 07:37:04 -0000 1.3.6.8 @@ -1,6 +1,6 @@ /* - * $Id: url.c,v 1.3.6.7 2007/07/01 08:34:30 amosjeffries Exp $ + * $Id: url.c,v 1.3.6.8 2007/07/02 07:37:04 amosjeffries Exp $ * * DEBUG: section 23 URL Parsing * AUTHOR: Duane Wessels @@ -110,8 +110,6 @@ }; static request_t *urnParse(method_t method, char *urn); -static const char valid_ipv6_addr_chars[] = -"ABCDEFabcdef0123456789:"; static const char valid_hostname_chars_u[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" @@ -343,10 +341,7 @@ strcpy((char *) host, t + 1); } /* Is there any host information? (we should eventually parse it above) */ - q = host; - if (strchr(host, '[') && strchr(host, ']')) - q = strchr(host, ']'); - if ((t = strrchr(q, ':'))) { + if ((t = strrchr(host, ':'))) { *t++ = '\0'; if (*t != '\0') port = atoi(t); @@ -365,20 +360,12 @@ *q = '\0'; } } - if (host == strrchr(host, '[') && - (host + strlen(host)-1) == strchr(host, ']')) { - if (strspn(host+1, valid_ipv6_addr_chars) != strlen(host)-2) { /* IPv6 address */ - debug(23, 1) ("urlParse: Illegal character in hostname '%s'\n", host); - return NULL; - } - } else { - if (Config.onoff.check_hostnames && strspn(host, Config.onoff.allow_underscore ? valid_hostname_chars_u : valid_hostname_chars) != strlen(host)) { - debug(23, 1) ("urlParse: Illegal character in hostname '%s'\n", host); - return NULL; - } - if (Config.appendDomain && !strchr(host, '.')) - strncat(host, Config.appendDomain, SQUIDHOSTNAMELEN - strlen(host) - 1); + if (Config.onoff.check_hostnames && strspn(host, Config.onoff.allow_underscore ? valid_hostname_chars_u : valid_hostname_chars) != strlen(host)) { + debug(23, 1) ("urlParse: Illegal character in hostname '%s'\n", host); + return NULL; } + if (Config.appendDomain && !strchr(host, '.')) + strncat(host, Config.appendDomain, SQUIDHOSTNAMELEN - strlen(host) - 1); /* remove trailing dots from hostnames */ while ((l = strlen(host)) > 0 && host[--l] == '.') host[l] = '\0'; @@ -425,12 +412,7 @@ } } request = requestCreate(method, protocol, urlpath); - if (strchr(host, '[')) { - xstrncpy(request->host, host+1, SQUIDHOSTNAMELEN); - request->host[strlen(host)-2] = '\0'; - } - else - xstrncpy(request->host, host, SQUIDHOSTNAMELEN); + xstrncpy(request->host, host, SQUIDHOSTNAMELEN); xstrncpy(request->login, login, MAX_LOGIN_SZ); request->port = (u_short) port; return request; @@ -446,7 +428,6 @@ const char * urlCanonical(request_t * request) { - LOCAL_ARRAY(char, hostbuf, MAX_URL); LOCAL_ARRAY(char, portbuf, 32); LOCAL_ARRAY(char, urlbuf, MAX_URL); if (request->canonical) @@ -462,17 +443,11 @@ portbuf[0] = '\0'; if (request->port != urlDefaultPort(request->protocol)) snprintf(portbuf, 32, ":%d", request->port); - - if (strchr(request->host, ':')) - snprintf(hostbuf, MAX_URL, "[%s]", request->host); - else - snprintf(hostbuf, MAX_URL, "%s", request->host); - snprintf(urlbuf, MAX_URL, "%s://%s%s%s%s%s", ProtocolStr[request->protocol], request->login, *request->login ? "@" : null_string, - hostbuf, + request->host, portbuf, strBuf(request->urlpath)); break; @@ -489,7 +464,6 @@ char * urlCanonicalClean(const request_t * request) { - LOCAL_ARRAY(char, hostbuf, MAX_URL); LOCAL_ARRAY(char, buf, MAX_URL); LOCAL_ARRAY(char, portbuf, 32); LOCAL_ARRAY(char, loginbuf, MAX_LOGIN_SZ + 1); @@ -503,11 +477,7 @@ } else { switch (request->method) { case METHOD_CONNECT: - if (strchr(request->host, ':')) - snprintf(hostbuf, MAX_URL, "[%s]", request->host); - else - snprintf(hostbuf, MAX_URL, "%s", request->host); - snprintf(buf, MAX_URL, "%s:%d", hostbuf, request->port); + snprintf(buf, MAX_URL, "%s:%d", request->host, request->port); break; default: portbuf[0] = '\0'; Index: squid/src/wccp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/wccp.c,v retrieving revision 1.3.6.5 retrieving revision 1.3.6.6 diff -u -r1.3.6.5 -r1.3.6.6 --- squid/src/wccp.c 1 Jul 2007 05:44:26 -0000 1.3.6.5 +++ squid/src/wccp.c 2 Jul 2007 07:37:04 -0000 1.3.6.6 @@ -1,6 +1,6 @@ /* - * $Id: wccp.c,v 1.3.6.5 2007/07/01 05:44:26 amosjeffries Exp $ + * $Id: wccp.c,v 1.3.6.6 2007/07/02 07:37:04 amosjeffries Exp $ * * DEBUG: section 80 WCCP Support * AUTHOR: Glenn Chisholm @@ -112,7 +112,7 @@ last_id = 0; last_assign_buckets_change = 0; number_caches = 0; - if (((struct sockaddr_in *)&Config.Wccp.router)->sin_addr.s_addr != any_addr.s_addr) + if (Config.Wccp.router.s_addr != any_addr.s_addr) if (!eventFind(wccpHereIam, NULL)) eventAdd("wccpHereIam", wccpHereIam, NULL, 5.0, 1); } @@ -124,17 +124,14 @@ struct sockaddr_in router, local; socklen_t local_len, router_len; debug(80, 5) ("wccpConnectionOpen: Called\n"); - if (((struct sockaddr_in *)&Config.Wccp.router)->sin_addr.s_addr == any_addr.s_addr) { + if (Config.Wccp.router.s_addr == any_addr.s_addr) { debug(1, 1) ("WCCP Disabled.\n"); return; } - if (Config.Wccp.address.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&Config.Wccp.address)->sin6_port = ntohs(port); - else - ((struct sockaddr_in *)&Config.Wccp.address)->sin_port = ntohs(port); theWccpConnection = comm_open(SOCK_DGRAM, IPPROTO_UDP, - &Config.Wccp.address, + Config.Wccp.address, + port, COMM_NONBLOCKING, "WCCP Socket"); if (theWccpConnection < 0) @@ -150,7 +147,7 @@ memset(&router, '\0', router_len); router.sin_family = AF_INET; router.sin_port = htons(port); - router.sin_addr = ((struct sockaddr_in *)&Config.Wccp.router)->sin_addr; + router.sin_addr = Config.Wccp.router; if (connect(theWccpConnection, (struct sockaddr *) &router, router_len)) fatal("Unable to connect WCCP out socket"); local_len = sizeof(local); @@ -209,7 +206,7 @@ (unsigned) ntohl(wccp_i_see_you.number)); if (len < 0) return; - if (((struct sockaddr_in *)&Config.Wccp.router)->sin_addr.s_addr != from.sin_addr.s_addr) + if (Config.Wccp.router.s_addr != from.sin_addr.s_addr) return; if (ntohl(wccp_i_see_you.version) != Config.Wccp.version) return; Index: squid/src/wccp2.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/wccp2.c,v retrieving revision 1.28.2.3 retrieving revision 1.28.2.4 diff -u -r1.28.2.3 -r1.28.2.4 --- squid/src/wccp2.c 1 Jul 2007 05:44:26 -0000 1.28.2.3 +++ squid/src/wccp2.c 2 Jul 2007 07:37:04 -0000 1.28.2.4 @@ -1,6 +1,6 @@ /* - * $Id: wccp2.c,v 1.28.2.3 2007/07/01 05:44:26 amosjeffries Exp $ + * $Id: wccp2.c,v 1.28.2.4 2007/07/02 07:37:04 amosjeffries Exp $ * * DEBUG: section 80 WCCP Support * AUTHOR: Steven WIlton @@ -523,7 +523,7 @@ void wccp2Init(void) { - sockaddr_storage_list *s; + sockaddr_in_list *s; char *ptr; uint32_t service_flags; struct wccp2_service_list_t *service_list_ptr; @@ -537,7 +537,7 @@ /* Calculate the number of routers configured in the config file */ for (s = Config.Wccp2.router; s; s = s->next) { - if (((struct sockaddr_in *)&s->s)->sin_addr.s_addr != any_addr.s_addr) { + if (s->s.sin_addr.s_addr != any_addr.s_addr) { /* Increment the counter */ wccp2_numrouters++; } @@ -670,15 +670,15 @@ /* Add each router. Keep this functionality here to make sure the received_id can be updated in the packet */ for (s = Config.Wccp2.router; s; s = s->next) { - if (((struct sockaddr_in *)&s->s)->sin_addr.s_addr != any_addr.s_addr) { + if (s->s.sin_addr.s_addr != any_addr.s_addr) { wccp2_here_i_am_header.length += sizeof(struct wccp2_router_id_element_t); assert(wccp2_here_i_am_header.length <= WCCP_RESPONSE_SIZE); /* Add a pointer to the router list for this router */ router_list_ptr->info = (struct wccp2_router_id_element_t *) ptr; - router_list_ptr->info->router_address = ((struct sockaddr_in *)&s->s)->sin_addr; + router_list_ptr->info->router_address = s->s.sin_addr; router_list_ptr->info->received_id = htonl(0); - router_list_ptr->router_sendto_address = ((struct sockaddr_in *)&s->s)->sin_addr; + router_list_ptr->router_sendto_address = s->s.sin_addr; router_list_ptr->member_change = htonl(0); /* Build the next struct */ @@ -764,13 +764,10 @@ debug(80, 2) ("WCCPv2 Disabled.\n"); return; } - if (Config.Wccp2.address.ss_family == AF_INET6) - ((struct sockaddr_in6 *)&Config.Wccp2.address)->sin6_port = ntohs(port); - else - ((struct sockaddr_in *)&Config.Wccp2.address)->sin_port = ntohs(port); theWccp2Connection = comm_open(SOCK_DGRAM, IPPROTO_UDP, - &Config.Wccp2.address, + Config.Wccp2.address, + port, COMM_NONBLOCKING, "WCCPv2 Socket"); if (theWccp2Connection < 0) Index: squid/src/auth/digest/auth_digest.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/auth/digest/auth_digest.c,v retrieving revision 1.4.12.6 retrieving revision 1.4.12.7 diff -u -r1.4.12.6 -r1.4.12.7 --- squid/src/auth/digest/auth_digest.c 1 Jul 2007 05:44:26 -0000 1.4.12.6 +++ squid/src/auth/digest/auth_digest.c 2 Jul 2007 07:37:05 -0000 1.4.12.7 @@ -727,17 +727,16 @@ return; } else { const char *useragent = httpHeaderGetStr(&request->header, HDR_USER_AGENT); - static struct sockaddr_storage last_broken_addr; + static struct in_addr last_broken_addr; static int seen_broken_client = 0; if (!seen_broken_client) { - memset(&last_broken_addr, '\0', sizeof(last_broken_addr)); + last_broken_addr = no_addr; seen_broken_client = 1; } if (memcmp(&last_broken_addr, &request->client_addr, sizeof(last_broken_addr)) != 0) { - debug(29, 1) ("\nDigest POST bug detected from %s using '%s'. Please upgrade browser. See Bug #630 for details.\n", sockaddr_ntoa(&request->client_addr), useragent ? useragent : "-"); - xmemcpy(&last_broken_addr, &request->client_addr, - SOCKLEN(&request->client_addr)); + debug(29, 1) ("\nDigest POST bug detected from %s using '%s'. Please upgrade browser. See Bug #630 for details.\n", inet_ntoa(request->client_addr), useragent ? useragent : "-"); + last_broken_addr = request->client_addr; } } } else {