Squid-2.2.STABLE2: 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.29 squid/src/cache_cf.c:1.1.1.29.4.4 --- squid/src/cache_cf.c:1.1.1.29 Tue Apr 20 17:26:02 1999 +++ squid/src/cache_cf.c Tue May 18 02:30:46 1999 @@ -277,7 +277,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 @@ -285,7 +285,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; @@ -527,6 +527,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. @@ -923,7 +979,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; @@ -942,7 +998,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); @@ -1190,6 +1251,7 @@ } } +#if UNUSED static void dump_ushortlist(StoreEntry * entry, const char *name, ushortlist * u) { @@ -1233,6 +1295,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.32.2.5 squid/src/cf.data.pre:1.1.1.32.2.6 --- squid/src/cf.data.pre:1.1.1.32.2.5 Fri Mar 26 01:12:51 1999 +++ squid/src/cf.data.pre Sat Mar 27 21:56:42 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.37.2.2 squid/src/client_side.c:1.1.1.37.2.3 --- squid/src/client_side.c:1.1.1.37.2.2 Fri Mar 26 01:38:55 1999 +++ squid/src/client_side.c Sat Mar 27 21:56:43 1999 @@ -1100,7 +1100,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 /* * Clear keepalive for NON-HEAD requests with invalid content length @@ -2251,11 +2251,11 @@ if (!http->flags.internal) { if (internalCheck(strBuf(request->urlpath))) { if (0 == strcasecmp(request->host, internalHostname()) && - 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; } } @@ -2582,14 +2582,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(); @@ -2598,8 +2598,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.8 squid/src/internal.c:1.1.1.8.4.1 --- squid/src/internal.c:1.1.1.8 Sun Jan 24 09:34:14 1999 +++ squid/src/internal.c Sat Mar 27 21:56:45 1999 @@ -99,7 +99,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.28 squid/src/main.c:1.1.1.28.4.1 --- squid/src/main.c:1.1.1.28 Sun Jan 24 09:34:14 1999 +++ squid/src/main.c Sat Mar 27 21:56:45 1999 @@ -386,7 +386,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.10 squid/src/send-announce.c:1.1.1.10.4.1 --- squid/src/send-announce.c:1.1.1.10 Sun Jan 24 09:34:19 1999 +++ squid/src/send-announce.c Sat Mar 27 21:56:45 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.36.2.7 squid/src/structs.h:1.1.1.36.2.8 --- squid/src/structs.h:1.1.1.36.2.7 Fri Mar 26 01:12:54 1999 +++ squid/src/structs.h Sat Mar 27 21:56:45 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; @@ -252,7 +258,7 @@ } Timeout; size_t maxRequestSize; 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.22 squid/src/typedefs.h:1.1.1.22.2.1 --- squid/src/typedefs.h:1.1.1.22 Sun Feb 14 23:30:11 1999 +++ squid/src/typedefs.h Sat Mar 27 21:56:46 1999 @@ -69,6 +69,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;