raccoon@newt.dlc.fi writes:
> Is it possible to configure squid to listen to multiple ports?
Not currently. But I have a patch from Lincoln Dale to do it:
==============================================================================
From: Lincoln Dale <ltd@aone.com.au>
Subject: patch to listen on multiple http ports
Date: Sat, 15 Mar 1997 13:04:17 +1100
==============================================================================
The following patch allows the use of multiple http_port lines in the config
file for squid, in order to listen on multiple ports for incoming HTTP
requests.
ie. you could listen on 3128, 80, 8080 all simultaneously.
the patch has been tested on solaris 2.5 and linux 2.0.27. some brief
attempts were made to check to see if it would work on digital unix 4.0a,
however it did not, although i don't believe this is a result of the changes
i've made (more the fact that i'm not running 'fixes.patch' nor the additional
fix that you posted to the squid list for DU.
also note that the changes to the USE_POLL code are untested.
regardless, here are the changes, based on squid 1.1.9.
cheers,
lincoln.
diff -Nur ../orig/cache_cf.c ./cache_cf.c
--- ../orig/cache_cf.c Sat Mar 29 07:28:11 1997
+++ ./cache_cf.c Sun Apr 6 02:25:45 1997
@@ -868,7 +868,14 @@
GetInteger(i);
if (i < 0)
i = 0;
- Config.Port.http = (u_short) i;
+
+ if (Config.Port.number_http == MAXHTTPPORTS) {
+ sprintf(fatal_str,"Limit of %d HTTP Ports reached. Redefine MAXHTTPPORTS
for more.\n",
+ MAXHTTPPORTS);
+ fatal(fatal_str);
+ }
+
+ Config.Port.http[Config.Port.number_http++] = (u_short) i;
}
static void
@@ -1566,8 +1573,9 @@
Config.effectiveGroup = safe_xstrdup(DefaultEffectiveGroup);
Config.appendDomain = safe_xstrdup(DefaultAppendDomain);
Config.errHtmlText = safe_xstrdup(DefaultErrHtmlText);
- Config.Port.http = DefaultHttpPortNum;
+ Config.Port.http[0] = DefaultHttpPortNum;
Config.Port.icp = DefaultIcpPortNum;
+ Config.Port.number_http = 0;
Config.Log.log_fqdn = DefaultLogLogFqdn;
Config.Log.log = safe_xstrdup(DefaultCacheLogFile);
Config.Log.access = safe_xstrdup(DefaultAccessLogFile);
@@ -1640,7 +1648,7 @@
vhost_mode = 1;
sprintf(ThisCache, "%s:%d (Squid/%s)",
getMyHostname(),
- (int) Config.Port.http,
+ (int) Config.Port.http[0],
SQUID_VERSION);
if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF)
Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF;
diff -Nur ../orig/cache_cf.h ./cache_cf.h
--- ../orig/cache_cf.h Sat Mar 29 07:28:12 1997
+++ ./cache_cf.h Sun Apr 6 02:25:46 1997
@@ -109,6 +109,8 @@
#define DefaultDnsChildrenMax 32 /* 32 processes */
#define DefaultRedirectChildrenMax 32 /* 32 processes */
+#define MAXHTTPPORTS 12 /* can bind to up to 12 ports */
+
typedef struct _wordlist {
char *key;
struct _wordlist *next;
@@ -163,8 +165,9 @@
int cleanRate;
int maxRequestSize;
struct {
- u_short http;
+ u_short http[MAXHTTPPORTS];
u_short icp;
+ u_short number_http;
} Port;
struct {
char *log;
diff -Nur ../orig/client_db.c ./client_db.c
--- ../orig/client_db.c Wed Mar 26 18:29:36 1997
+++ ./client_db.c Sun Apr 6 02:25:45 1997
@@ -73,6 +73,7 @@
void
clientdbUpdate(struct in_addr addr, log_type log_type, u_short port)
{
+ int j;
char *key;
ClientInfo *c;
if (!Config.Options.client_db)
@@ -83,10 +84,14 @@
c = clientdbAdd(addr);
if (c == NULL)
debug_trap("clientdbUpdate: Failed to add entry");
- if (port == Config.Port.http) {
- c->Http.n_requests++;
- c->Http.result_hist[log_type]++;
- } else if (port == Config.Port.icp) {
+
+ for (j=0;j < Config.Port.number_http; j++) {
+ if (port == Config.Port.http[j]) {
+ c->Http.n_requests++;
+ c->Http.result_hist[log_type]++;
+ }
+ }
+ if (port == Config.Port.icp) {
c->Icp.n_requests++;
c->Icp.result_hist[log_type]++;
}
diff -Nur ../orig/comm.c ./comm.c
--- ../orig/comm.c Sat Mar 29 02:17:31 1997
+++ ./comm.c Sun Apr 6 02:25:45 1997
@@ -635,6 +635,7 @@
struct pollfd pfds[3];
unsigned long N = 0;
unsigned long i = 0;
+ int j;
int dopoll = 0;
PF hdl = NULL;
if (theInIcpConnection >= 0)
@@ -642,8 +643,11 @@
if (theInIcpConnection != theOutIcpConnection)
if (theOutIcpConnection >= 0)
fds[N++] = theOutIcpConnection;
- if (theHttpConnection >= 0 && fdstat_are_n_free_fd(RESERVED_FD))
- fds[N++] = theHttpConnection;
+ for (j=0; j < Config.Port.number_http; j++) {
+ if (theHttpConnection[j] >= 0 && fdstat_are_n_free_fd(RESERVED_FD))
+ fds[N++] = theHttpConnection[j];
+ }
+
fds[N++] = 0;
for (i = 0; i < N; i++) {
fd = fds[i];
@@ -696,11 +700,14 @@
int fds[4];
int N = 0;
int i = 0;
+ int j;
PF hdl = NULL;
FD_ZERO(&read_mask);
FD_ZERO(&write_mask);
- if (theHttpConnection >= 0 && fdstat_are_n_free_fd(RESERVED_FD))
- fds[N++] = theHttpConnection;
+ for (j=0; j < Config.Port.number_http; j++) {
+ if (theHttpConnection[j] >= 0 && fdstat_are_n_free_fd(RESERVED_FD))
+ fds[N++] = theHttpConnection[j];
+ }
if (theInIcpConnection >= 0)
fds[N++] = theInIcpConnection;
if (theInIcpConnection != theOutIcpConnection)
@@ -751,6 +758,7 @@
PF hdl = NULL;
int fd;
int i;
+ int j;
int maxfd;
unsigned long nfds;
int incnfd;
@@ -799,9 +807,12 @@
incnfd = 1;
}
if (incnfd == 1) {
- if (i == theHttpConnection)
- httpindex = nfds;
- nfds++;
+ for (j=0; j < Config.Port.number_http; j++) {
+ if (i == theHttpConnection[j]) {
+ httpindex = nfds;
+ nfds++;
+ }
+ }
}
}
/* If we're out of free fd's, don't poll the http incoming fd */
@@ -866,7 +877,12 @@
continue;
if (fd == theOutIcpConnection)
continue;
- if (fd == theHttpConnection)
+ continueloop = 0;
+ for (j = 0; j < Config.Port.number_http; j++) {
+ if (fd == theHttpConnection[j])
+ continueloop = 1;
+ }
+ if (continueloop)
continue;
if (pfds[i].revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) {
debug(5, 6, "comm_select: FD %d ready for reading\n", fd);
@@ -935,6 +951,8 @@
PF hdl = NULL;
int fd;
int i;
+ int j;
+ int continueloop;
int maxfd;
int nfds;
int num;
@@ -979,8 +997,12 @@
FD_SET(i, &writefds);
}
}
- if (!fdstat_are_n_free_fd(RESERVED_FD) && theHttpConnection >= 0) {
- FD_CLR(theHttpConnection, &readfds);
+ if (!fdstat_are_n_free_fd(RESERVED_FD)) {
+ for (j = 0; j < Config.Port.number_http; j++) {
+ if (theHttpConnection[j] >= 0) {
+ FD_CLR(theHttpConnection[j], &readfds);
+ }
+ }
}
if (shutdown_pending || reread_pending)
debug(5, 2, "comm_select: Still waiting on %d FDs\n", nfds);
@@ -1032,8 +1054,14 @@
continue;
if (fd == theOutIcpConnection)
continue;
- if (fd == theHttpConnection)
- continue;
+ continueloop = 0;
+ for (j = 0; j < Config.Port.number_http; j++) {
+ if (fd == theHttpConnection[j])
+ continueloop = 1;
+ }
+ if (continueloop)
+ continue;
+
if (FD_ISSET(fd, &readfds)) {
debug(5, 6, "comm_select: FD %d ready for reading\n", fd);
if (fd_table[fd].read_handler) {
diff -Nur ../orig/main.c ./main.c
--- ../orig/main.c Sat Mar 29 10:25:36 1997
+++ ./main.c Sun Apr 6 02:25:45 1997
@@ -106,7 +106,8 @@
#include "squid.h"
time_t squid_starttime = 0;
-int theHttpConnection = -1;
+int theHttpConnection[MAXHTTPPORTS];
+
int theInIcpConnection = -1;
int theOutIcpConnection = -1;
int vizSock = -1;
@@ -337,25 +338,32 @@
u_short port;
int len;
int x;
- enter_suid();
- theHttpConnection = comm_open(SOCK_STREAM,
- 0,
- Config.Addrs.tcp_incoming,
- Config.Port.http,
- COMM_NONBLOCKING,
- "HTTP Port");
- leave_suid();
- if (theHttpConnection < 0) {
- fatal("Cannot open HTTP Port");
+ int i;
+ char fatal_str[BUFSIZ];
+
+ for (i=0; i < Config.Port.number_http; i++) {
+ enter_suid();
+ theHttpConnection[i] = comm_open(SOCK_STREAM,
+ 0,
+ Config.Addrs.tcp_incoming,
+ Config.Port.http[i],
+ COMM_NONBLOCKING,
+ "HTTP Port");
+ leave_suid();
+ if (theHttpConnection[i] < 0) {
+ sprintf(fatal_str, "Cannot open HTTP Port #%d (port %d)",
+ i, Config.Port.http[i]);
+ fatal(fatal_str);
+ }
+ fd_note(theHttpConnection[i], "HTTP socket");
+ comm_listen(theHttpConnection[i]);
+ commSetSelect(theHttpConnection[i],
+ COMM_SELECT_READ,
+ asciiHandleConn,
+ NULL, 0);
+ debug(1, 1, "Accepting HTTP connections for port %d on FD %d.\n",
+ Config.Port.http[i], theHttpConnection[i]);
}
- fd_note(theHttpConnection, "HTTP socket");
- comm_listen(theHttpConnection);
- commSetSelect(theHttpConnection,
- COMM_SELECT_READ,
- asciiHandleConn,
- NULL, 0);
- debug(1, 1, "Accepting HTTP connections on FD %d.\n",
- theHttpConnection);
if (!httpd_accel_mode || Config.Accel.withProxy) {
if ((port = Config.Port.icp) > (u_short) 0) {
@@ -467,15 +475,20 @@
{
/* NOTE, this function will be called repeatedly while shutdown
* is pending */
- if (theHttpConnection >= 0) {
- debug(1, 1, "FD %d Closing HTTP connection\n",
- theHttpConnection);
- comm_close(theHttpConnection);
- commSetSelect(theHttpConnection,
- COMM_SELECT_READ,
- NULL,
- NULL, 0);
- theHttpConnection = -1;
+
+ int i;
+
+ for (i=0; i < Config.Port.number_http; i++) {
+ if (theHttpConnection[i] >= 0) {
+ debug(1, 1, "FD %d Closing HTTP connection %d (port %d)\n",
+ theHttpConnection[i],i,Config.Port.http[i]);
+ comm_close(theHttpConnection[i]);
+ commSetSelect(theHttpConnection[i],
+ COMM_SELECT_READ,
+ NULL,
+ NULL, 0);
+ theHttpConnection[i]= -1;
+ }
}
if (theInIcpConnection >= 0) {
/* NOTE, don't close outgoing ICP connection, we need to write to
@@ -542,7 +555,7 @@
fatal("Don't run Squid as root, set 'cache_effective_user'!");
}
if (httpPortNumOverride != 1)
- Config.Port.http = (u_short) httpPortNumOverride;
+ Config.Port.http[0] = (u_short) httpPortNumOverride;
if (icpPortNumOverride != 1)
Config.Port.icp = (u_short) icpPortNumOverride;
diff -Nur ../orig/neighbors.c ./neighbors.c
--- ../orig/neighbors.c Sun Mar 30 04:28:04 1997
+++ ./neighbors.c Sun Apr 6 02:25:46 1997
@@ -832,11 +832,17 @@
int mcast_ttl)
{
peer *e = NULL;
+ int j;
const char *me = getMyHostname();
- if (!strcmp(host, me) && http_port == Config.Port.http) {
- debug(15, 0, "neighborAdd: skipping cache_host %s %s/%d/%d\n",
- type, host, http_port, icp_port);
- return;
+
+ if (!strcmp(host, me)) {
+ for (j=0;j < Config.Port.number_http; j++) {
+ if (http_port == Config.Port.http[j]) {
+ debug(15, 0, "neighborAdd: skipping cache_host %s %s/%d/%d\n",
+ type, host, http_port, icp_port);
+ return;
+ }
+ }
}
e = xcalloc(1, sizeof(peer));
e->http_port = http_port;
diff -Nur ../orig/send-announce.c ./send-announce.c
--- ../orig/send-announce.c Wed Feb 26 05:24:51 1997
+++ ./send-announce.c Sun Apr 6 02:25:46 1997
@@ -62,9 +62,10 @@
sndbuf[0] = '\0';
sprintf(tbuf, "cache_version SQUID/%s\n", version_string);
strcat(sndbuf, tbuf);
+ /* XXX should actually send all http ports -- ltd */
sprintf(tbuf, "Running on %s %d %d\n",
getMyHostname(),
- Config.Port.http,
+ Config.Port.http[0],
Config.Port.icp);
strcat(sndbuf, tbuf);
if (Config.adminEmail) {
diff -Nur ../orig/squid.h ./squid.h
--- ../orig/squid.h Fri Mar 28 09:19:15 1997
+++ ./squid.h Sun Apr 6 02:25:46 1997
@@ -315,7 +315,7 @@
extern time_t squid_starttime; /* main.c */
extern int do_reuse; /* main.c */
-extern int theHttpConnection; /* main.c */
+extern int theHttpConnection[MAXHTTPPORTS]; /* main.c */
extern int theInIcpConnection; /* main.c */
extern int theOutIcpConnection; /* main.c */
extern int vizSock;
diff -Nur ../orig/tools.c ./tools.c
--- ../orig/tools.c Thu Mar 27 17:19:02 1997
+++ ./tools.c Sun Apr 6 02:25:46 1997
@@ -132,9 +132,13 @@
static void
releaseServerSockets(void)
{
+ int j;
+
/* Release the main ports as early as possible */
- if (theHttpConnection >= 0)
- (void) close(theHttpConnection);
+ for (j = 0; j < Config.Port.number_http; j++) {
+ if (theHttpConnection[j] >= 0)
+ (void) close(theHttpConnection[j]);
+ }
if (theInIcpConnection >= 0)
(void) close(theInIcpConnection);
if (theOutIcpConnection >= 0 && theOutIcpConnection != theInIcpConnection)
Received on Mon Apr 28 1997 - 16:09:24 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:35:03 MST