From: hno <> Date: Fri, 5 Apr 2002 04:33:26 +0000 (+0000) Subject: Make http_port optional, allowing for SSL-only operation. Squid will X-Git-Tag: SQUID_3_0_PRE1~1130 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=52f772dee6301d40d7a8cbf122dd4343f02f95cb;p=thirdparty%2Fsquid.git Make http_port optional, allowing for SSL-only operation. Squid will refuse to start unless at least one port is defined. --- diff --git a/ChangeLog b/ChangeLog index 9ca23e4399..b0437e143a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ Changes to squid-2.6 (): - CARP now plays well with the other peering algorithms - Configuration file can be read from an external program or preprocessor. See squid.8 man page. + - http_port is now optional, allowing for SSL only operation Changes to squid-2.5 (): diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 97afbac3d3..144a016a09 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.403 2002/04/04 21:17:25 hno Exp $ + * $Id: cache_cf.cc,v 1.404 2002/04/04 21:33:26 hno Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -96,7 +96,9 @@ static void free_denyinfo(acl_deny_info_list ** var); 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 0 static int check_null_sockaddr_in_list(const sockaddr_in_list *); +#endif #if USE_SSL static void parse_https_port_list(https_port_list **); static void dump_https_port_list(StoreEntry *, const char *, const https_port_list *); @@ -367,19 +369,15 @@ configDoConfigure(void) if (Config.Accel.port == 0) vport_mode = 1; } - if (Config.Sockaddr.http == NULL) - fatal("No http_port specified!"); - snprintf(ThisCache, sizeof(ThisCache), "%s:%d (%s)", + snprintf(ThisCache, sizeof(ThisCache), "%s (%s)", uniqueHostname(), - (int) ntohs(Config.Sockaddr.http->s.sin_port), full_appname_string); /* * the extra space is for loop detection in client_side.c -- we search * for substrings in the Via header. */ - snprintf(ThisCache2, sizeof(ThisCache), " %s:%d (%s)", + snprintf(ThisCache2, sizeof(ThisCache), " %s (%s)", uniqueHostname(), - (int) ntohs(Config.Sockaddr.http->s.sin_port), full_appname_string); if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF) Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF; @@ -2230,43 +2228,50 @@ parseNeighborType(const char *s) return PEER_SIBLING; } -static void -parse_sockaddr_in_list(sockaddr_in_list ** head) +void +parse_sockaddr_in_list_token(sockaddr_in_list ** head, char *token) { - char *token; char *t; char *host; const struct hostent *hp; unsigned short port; sockaddr_in_list *s; - while ((token = strtok(NULL, w_space))) { - host = NULL; - port = 0; - if ((t = strchr(token, ':'))) { - /* host:port */ - host = token; - *t = '\0'; - port = (unsigned short) atoi(t + 1); - if (0 == port) - self_destruct(); - } else if ((port = atoi(token)) > 0) { - /* port */ - } else { - self_destruct(); - } - s = xcalloc(1, sizeof(*s)); - 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); - else + + host = NULL; + port = 0; + if ((t = strchr(token, ':'))) { + /* host:port */ + host = token; + *t = '\0'; + port = (unsigned short) atoi(t + 1); + if (0 == port) self_destruct(); - while (*head) - head = &(*head)->next; - *head = s; + } else if ((port = atoi(token)) > 0) { + /* port */ + } else { + self_destruct(); + } + s = xcalloc(1, sizeof(*s)); + 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); + else + self_destruct(); + while (*head) + head = &(*head)->next; + *head = s; +} + +static void +parse_sockaddr_in_list(sockaddr_in_list ** head) +{ + char *token; + while ((token = strtok(NULL, w_space))) { + parse_sockaddr_in_list_token(head, token); } } @@ -2292,11 +2297,13 @@ free_sockaddr_in_list(sockaddr_in_list ** head) } } +#if 0 static int check_null_sockaddr_in_list(const sockaddr_in_list * s) { return NULL == s; } +#endif #if USE_SSL static void diff --git a/src/cf.data.pre b/src/cf.data.pre index ed933fd28c..993eb8669e 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.252 2002/04/02 20:32:43 hno Exp $ +# $Id: cf.data.pre,v 1.253 2002/04/04 21:33:26 hno Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -56,7 +56,6 @@ COMMENT_END NAME: http_port ascii_port TYPE: sockaddr_in_list DEFAULT: none -DEFAULT_IF_NONE: 3128 LOC: Config.Sockaddr.http DOC_START Usage: port @@ -72,8 +71,6 @@ DOC_START option. Most likely, you do not need to bind to a specific address, so you can use the port number alone. - The default port number is 3128. - If you are running Squid in accelerator mode, then you probably want to listen on port 80 also, or instead. @@ -87,6 +84,11 @@ DOC_START and an external interface then we recommend you to specify the internal address:port in http_port. This way Squid will only be visible on the internal address. + +NOCOMMENT_START +# Squid normally listens to port 3128 +http_port 3128 +NOCOMMENT_END DOC_END NAME: https_port diff --git a/src/client_side.cc b/src/client_side.cc index acdd173323..05b2eaf754 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.567 2002/04/01 06:02:15 wessels Exp $ + * $Id: client_side.cc,v 1.568 2002/04/04 21:33:26 hno Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -1210,7 +1210,7 @@ clientBuildReplyHeader(clientHttpRequest * http, HttpReply * rep) /* 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(), ntohs(Config.Sockaddr.http->s.sin_port)); + getMyHostname(), getMyPort()); #endif if (httpReplyBodySize(request->method, rep) < 0) { debug(33, 3) ("clientBuildReplyHeader: can't keep-alive, unknown body size\n"); @@ -2501,11 +2501,11 @@ clientReadRequest(int fd, void *data) if (!http->flags.internal) { if (internalCheck(strBuf(request->urlpath))) { if (internalHostnameIs(request->host) && - request->port == ntohs(Config.Sockaddr.http->s.sin_port)) { + request->port == getMyPort()) { http->flags.internal = 1; } else if (internalStaticCheck(strBuf(request->urlpath))) { xstrncpy(request->host, internalHostname(), SQUIDHOSTNAMELEN); - request->port = ntohs(Config.Sockaddr.http->s.sin_port); + request->port = getMyPort(); http->flags.internal = 1; } } diff --git a/src/internal.cc b/src/internal.cc index ead74c4449..92024ca5b7 100644 --- a/src/internal.cc +++ b/src/internal.cc @@ -1,6 +1,6 @@ /* - * $Id: internal.cc,v 1.23 2001/01/12 00:37:18 wessels Exp $ + * $Id: internal.cc,v 1.24 2002/04/04 21:33:26 hno Exp $ * * DEBUG: section 76 Internal Squid Object handling * AUTHOR: Duane, Alex, Henrik @@ -96,7 +96,7 @@ internalRemoteUri(const char *host, u_short port, const char *dir, const char *n { static MemBuf mb = MemBufNULL; static char lc_host[SQUIDHOSTNAMELEN]; - assert(host && port && name); + assert(host && name); /* convert host name to lower case */ xstrncpy(lc_host, host, SQUIDHOSTNAMELEN - 1); Tolower(lc_host); @@ -111,7 +111,7 @@ internalRemoteUri(const char *host, u_short port, const char *dir, const char *n memBufReset(&mb); memBufPrintf(&mb, "http://%s", lc_host); /* append port if not default */ - if (port != urlDefaultPort(PROTO_HTTP)) + if (port && port != urlDefaultPort(PROTO_HTTP)) memBufPrintf(&mb, ":%d", port); if (dir) memBufPrintf(&mb, "%s", dir); @@ -127,7 +127,7 @@ char * internalLocalUri(const char *dir, const char *name) { return internalRemoteUri(getMyHostname(), - ntohs(Config.Sockaddr.http->s.sin_port), dir, name); + 0, dir, name); } const char * diff --git a/src/main.cc b/src/main.cc index 05e28aa006..312903ded3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.347 2002/01/15 16:49:19 hno Exp $ + * $Id: main.cc,v 1.348 2002/04/04 21:33:27 hno Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -41,7 +41,6 @@ extern void (*failure_notify) (const char *); static int opt_send_signal = -1; static int opt_no_daemon = 0; static int opt_parse_cfg_only = 0; -static int httpPortNumOverride = 1; static int icpPortNumOverride = 1; /* Want to detect "-u 0" */ static int configured_once = 0; #if MALLOC_DBG @@ -146,7 +145,7 @@ mainParseOptions(int argc, char *argv[]) opt_reload_hit_only = 1; break; case 'a': - httpPortNumOverride = atoi(optarg); + parse_sockaddr_in_list_token(&Config.Sockaddr.http, optarg); break; case 'd': opt_debug_stderr = atoi(optarg); @@ -458,9 +457,6 @@ mainInitialize(void) squid_signal(SIGCHLD, sig_child, SA_NODEFER | SA_RESTART); setEffectiveUser(); - assert(Config.Sockaddr.http); - if (httpPortNumOverride != 1) - Config.Sockaddr.http->s.sin_port = htons(httpPortNumOverride); if (icpPortNumOverride != 1) Config.Port.icp = (u_short) icpPortNumOverride; diff --git a/src/protos.h b/src/protos.h index 564b496d75..5ec1b9f1bf 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.430 2002/04/01 06:02:16 wessels Exp $ + * $Id: protos.h,v 1.431 2002/04/04 21:33:27 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -101,6 +101,7 @@ extern void requirePathnameExists(const char *name, const char *path); 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_in_list_token(sockaddr_in_list **, char *); /* @@ -1162,6 +1163,7 @@ extern void *linklistShift(link_list **); extern int xrename(const char *from, const char *to); extern int isPowTen(int); extern void parseEtcHosts(void); +extern int getMyPort(void); #if USE_HTCP extern void htcpInit(void); diff --git a/src/send-announce.cc b/src/send-announce.cc index 7fda259b75..2958c066e2 100644 --- a/src/send-announce.cc +++ b/src/send-announce.cc @@ -1,6 +1,6 @@ /* - * $Id: send-announce.cc,v 1.62 2001/04/14 00:03:23 hno Exp $ + * $Id: send-announce.cc,v 1.63 2002/04/04 21:33:27 hno Exp $ * * DEBUG: section 27 Cache Announcer * AUTHOR: Duane Wessels @@ -72,7 +72,7 @@ send_announce(const ipcache_addrs * ia, void *junk) assert(Config.Sockaddr.http); snprintf(tbuf, 256, "Running on %s %d %d\n", getMyHostname(), - (int) ntohs(Config.Sockaddr.http->s.sin_port), + getMyPort(), (int) Config.Port.icp); strcat(sndbuf, tbuf); if (Config.adminEmail) { diff --git a/src/tools.cc b/src/tools.cc index 083a0c69c0..f4f50ad019 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,6 +1,6 @@ /* - * $Id: tools.cc,v 1.214 2002/03/30 16:29:51 hno Exp $ + * $Id: tools.cc,v 1.215 2002/04/04 21:33:27 hno Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -1021,3 +1021,16 @@ parseEtcHosts(void) wordlistDestroy(&hosts); } } + +int +getMyPort(void) +{ +#if USE_SSL + if (Config.Sockaddr.http) + return Config.Sockaddr.http->s.sin_port; + else + return Config.Sockaddr.https->s.sin_port; +#else + return Config.Sockaddr.http->s.sin_port; +#endif +}