Squid-2.3.DEVEL2: http_port bind address Allow one to specify which address each port specified in http_port should be bound to, using address:port syntax. Index: squid/src/cache_cf.c diff -u squid/src/cache_cf.c:1.1.1.32.2.1 squid/src/cache_cf.c:1.1.1.32.2.2 --- squid/src/cache_cf.c:1.1.1.32.2.1 Sat Aug 7 18:20:19 1999 +++ squid/src/cache_cf.c Sat Aug 7 18:29:07 1999 @@ -280,7 +280,7 @@ fatal("No http_port specified!"); snprintf(ThisCache, sizeof(ThisCache), "%s:%d (%s)", uniqueHostname(), - (int) Config.Port.http->i, + (int) Config.Port.http->port, full_appname_string); /* * the extra space is for loop detection in client_side.c -- we search @@ -288,7 +288,7 @@ */ snprintf(ThisCache2, sizeof(ThisCache), " %s:%d (%s)", uniqueHostname(), - (int) Config.Port.http->i, + (int) Config.Port.http->port, full_appname_string); if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF) Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF; @@ -534,6 +534,62 @@ memset(addr, '\0', sizeof(struct in_addr)); } +static int +check_null_ipportlist(ipportlist * u) +{ + return u == NULL; +} + +static void +dump_ipportlist(StoreEntry * entry, const char *name, ipportlist * ip) +{ + while (ip) { + storeAppendPrintf(entry, "%s %s:%d\n", name, inet_ntoa(ip->addr), + (int) ip->port); + ip = ip->next; + } +} + +static void +parse_ipportlist(ipportlist **portlist) +{ + const struct hostent *hp; + char *token, *port; + ipportlist *ipport; + while (*portlist) + portlist = &(*portlist)->next; + while ((token = strtok(NULL, w_space)) != NULL) { + ipport = xcalloc(1, sizeof(*ipport)); + port = strchr(token, ':'); + if (port) { + *port++ = '\0'; + if (safe_inet_addr(token, &ipport->addr) == 1) + (void) 0; + else if ((hp = gethostbyname(token))) /* dont use ipcache */ + ipport->addr = inaddrFromHostent(hp); + else + self_destruct(); + } else { + port = token; + ipport->addr.s_addr = INADDR_ANY; + } + if (sscanf(port, "%hu", &ipport->port) != 1) + self_destruct(); + *portlist = ipport; + portlist = &(*portlist)->next; + } +} + +static void +free_ipportlist(ipportlist ** P) +{ + ipportlist *ip; + while ((ip = *P) != NULL) { + *P = ip->next; + xfree(ip); + } +} + #if DELAY_POOLS /* do nothing - free_delay_pool_count is the magic free function. @@ -907,7 +963,7 @@ char *token = NULL; peer *p; int i; - ushortlist *u; + ipportlist *u; const char *me = null_string; /* XXX */ p = memAllocate(MEM_PEER); p->http_port = CACHE_HTTP_PORT; @@ -926,7 +982,7 @@ p->icp.port = (u_short) i; if (strcmp(p->host, me) == 0) { for (u = Config.Port.http; u; u = u->next) { - if (p->http_port != u->i) + if (p->http_port != u->port) continue; debug(15, 0) ("parse_peer: Peer looks like myself: %s %s/%d/%d\n", p->type, p->host, p->http_port, p->icp.port); @@ -1177,6 +1233,7 @@ } } +#if UNUSED static void dump_ushortlist(StoreEntry * entry, const char *name, ushortlist * u) { @@ -1220,6 +1277,7 @@ xfree(u); } } +#endif static void dump_int(StoreEntry * entry, const char *name, int var) Index: squid/src/cf.data.pre diff -u squid/src/cf.data.pre:1.1.1.39.2.1 squid/src/cf.data.pre:1.1.1.39.2.2 --- squid/src/cf.data.pre:1.1.1.39.2.1 Sat Aug 7 18:23:38 1999 +++ squid/src/cf.data.pre Sat Aug 7 18:29:07 1999 @@ -54,7 +54,7 @@ COMMENT_END NAME: http_port ascii_port -TYPE: ushortlist +TYPE: ipportlist DEFAULT: none DEFAULT_IF_NONE: 3128 LOC: Config.Port.http @@ -65,6 +65,10 @@ You may specify multiple ports here, but they MUST all be on a single line. + + Each port number can be prefixed with an ipaddress to specify + which network interface Squid should listen on, using ipaddress:port + syntax. http_port 3128 DOC_END Index: squid/src/client_side.c diff -u squid/src/client_side.c:1.1.1.43 squid/src/client_side.c:1.1.1.43.2.1 --- squid/src/client_side.c:1.1.1.43 Sat Aug 7 17:13:18 1999 +++ squid/src/client_side.c Sat Aug 7 18:29:08 1999 @@ -1187,7 +1187,7 @@ /* Append X-Cache-Lookup: -- temporary hack, to be removed @?@ @?@ */ httpHeaderPutStrf(hdr, HDR_X_CACHE_LOOKUP, "%s from %s:%d", http->lookup_type ? http->lookup_type : "NONE", - getMyHostname(), Config.Port.http->i); + getMyHostname(), Config.Port.http->port); #endif if (httpReplyBodySize(request->method, http->entry->mem_obj->reply) < 0) { debug(33, 3) ("clientBuildReplyHeader: can't keep-alive, unknown body size\n"); @@ -2394,11 +2394,11 @@ if (!http->flags.internal) { if (internalCheck(strBuf(request->urlpath))) { if (internalHostnameIs(request->host) && - request->port == Config.Port.http->i) { + request->port == Config.Port.http->port) { http->flags.internal = 1; } else if (internalStaticCheck(strBuf(request->urlpath))) { xstrncpy(request->host, internalHostname(), SQUIDHOSTNAMELEN); - request->port = Config.Port.http->i; + request->port = Config.Port.http->port; http->flags.internal = 1; } } @@ -2745,14 +2745,14 @@ void clientHttpConnectionsOpen(void) { - ushortlist *u; + ipportlist *ip; int fd; - for (u = Config.Port.http; u; u = u->next) { + for (ip = Config.Port.http; ip; ip = ip->next) { enter_suid(); fd = comm_open(SOCK_STREAM, 0, - Config.Addrs.tcp_incoming, - u->i, + ip->addr.s_addr != INADDR_ANY ? ip->addr : Config.Addrs.tcp_incoming, + ip->port, COMM_NONBLOCKING, "HTTP Socket"); leave_suid(); @@ -2761,8 +2761,8 @@ comm_listen(fd); commSetSelect(fd, COMM_SELECT_READ, httpAccept, NULL, 0); /*commSetDefer(fd, httpAcceptDefer, NULL); */ - debug(1, 1) ("Accepting HTTP connections on port %d, FD %d.\n", - (int) u->i, fd); + debug(1, 1) ("Accepting HTTP connections on port %s:%d, FD %d.\n", + inet_ntoa(ip->addr), (int) ip->port, fd); HttpSockets[NHttpSockets++] = fd; } if (NHttpSockets < 1) Index: squid/src/internal.c diff -u squid/src/internal.c:1.1.1.9 squid/src/internal.c:1.1.1.9.2.1 --- squid/src/internal.c:1.1.1.9 Sat Aug 7 17:13:24 1999 +++ squid/src/internal.c Sat Aug 7 18:29:09 1999 @@ -117,7 +117,7 @@ char * internalLocalUri(const char *dir, const char *name) { - return internalRemoteUri(getMyHostname(), Config.Port.http->i, dir, name); + return internalRemoteUri(getMyHostname(), Config.Port.http->port, dir, name); } const char * Index: squid/src/main.c diff -u squid/src/main.c:1.1.1.33 squid/src/main.c:1.1.1.33.2.1 --- squid/src/main.c:1.1.1.33 Sat Aug 7 17:13:25 1999 +++ squid/src/main.c Sat Aug 7 18:29:09 1999 @@ -435,7 +435,7 @@ setEffectiveUser(); assert(Config.Port.http); if (httpPortNumOverride != 1) - Config.Port.http->i = (u_short) httpPortNumOverride; + Config.Port.http->port = (u_short) httpPortNumOverride; if (icpPortNumOverride != 1) Config.Port.icp = (u_short) icpPortNumOverride; Index: squid/src/send-announce.c diff -u squid/src/send-announce.c:1.1.1.13 squid/src/send-announce.c:1.1.1.13.2.1 --- squid/src/send-announce.c:1.1.1.13 Sat Aug 7 17:13:27 1999 +++ squid/src/send-announce.c Sat Aug 7 18:29:09 1999 @@ -75,7 +75,7 @@ assert(Config.Port.http); snprintf(tbuf, 256, "Running on %s %d %d\n", getMyHostname(), - (int) Config.Port.http->i, + (int) Config.Port.http->port, (int) Config.Port.icp); strcat(sndbuf, tbuf); if (Config.adminEmail) { Index: squid/src/structs.h diff -u squid/src/structs.h:1.1.1.40.2.5 squid/src/structs.h:1.1.1.40.2.6 --- squid/src/structs.h:1.1.1.40.2.5 Sat Aug 7 18:23:39 1999 +++ squid/src/structs.h Sat Aug 7 18:29:09 1999 @@ -183,6 +183,12 @@ ushortlist *next; }; +struct _ipportlist { + u_short port; + struct in_addr addr; + ipportlist *next; +}; + struct _relist { char *pattern; regex_t regex; @@ -264,7 +270,7 @@ size_t maxRequestBodySize; size_t maxReplyBodySize; struct { - ushortlist *http; + ipportlist *http; u_short icp; #if USE_HTCP u_short htcp; Index: squid/src/typedefs.h diff -u squid/src/typedefs.h:1.1.1.25 squid/src/typedefs.h:1.1.1.25.2.1 --- squid/src/typedefs.h:1.1.1.25 Sat Aug 7 17:13:33 1999 +++ squid/src/typedefs.h Sat Aug 7 18:29:10 1999 @@ -70,6 +70,7 @@ typedef struct _intlist intlist; typedef struct _intrange intrange; typedef struct _ushortlist ushortlist; +typedef struct _ipportlist ipportlist; typedef struct _relist relist; typedef struct _SquidConfig SquidConfig; typedef struct _SquidConfig2 SquidConfig2;