--------------------- PatchSet 11189 Date: 2007/11/12 23:10:37 Author: Amos Jeffries Branch: HEAD Tag: (none) Log: Author: Pawel Worach Enable squid to lookup /etc/services for named peer ports. Here is patch so you can use port names from /etc/services in squid.conf for cache_peers like so: cache_peer upstream.example.net parent http-cache icpv2 assumng you have something like this in /etc/services http-cache 8080/tcp icpv2 3130/udp This became needed here where we have the same squid.conf's deployed across a cluster of reverse proxies and we control originserver addresses via a hosts file and originserver ports via /etc/services locally on each node. Members: src/cache_cf.cc:1.524->1.525 Index: squid3/src/cache_cf.cc =================================================================== RCS file: /cvsroot/squid/squid3/src/cache_cf.cc,v retrieving revision 1.524 retrieving revision 1.525 diff -u -r1.524 -r1.525 --- squid3/src/cache_cf.cc 31 Oct 2007 04:52:16 -0000 1.524 +++ squid3/src/cache_cf.cc 12 Nov 2007 23:10:37 -0000 1.525 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.524 2007/10/31 04:52:16 amosjeffries Exp $ + * $Id: cache_cf.cc,v 1.525 2007/11/12 23:10:37 amosjeffries Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -1538,6 +1538,49 @@ } } +/** + \param proto 'tcp' or 'udp' for protocol + \returns Port the named service is supposed to be listening on. + */ +static u_short +GetService(const char *proto) +{ + struct servent *port = NULL; + /** Parses a port number or service name from the squid.conf */ + char *token = strtok(NULL, w_space); + if (token == NULL) { + self_destruct(); + return -1; /* NEVER REACHED */ + } + /** Returns either the service port number from /etc/services */ + port = getservbyname(token, proto); + if (port != NULL) { + return ntohs((u_short)port->s_port); + } + /** Or a numeric translation of the config text. */ + return xatos(token); +} + +/** + \returns Port the named TCP service is supposed to be listening on. + \copydoc GetService(const char *proto) + */ +inline u_short +GetTcpService(void) +{ + return GetService("tcp"); +} + +/** + \returns Port the named UDP service is supposed to be listening on. + \copydoc GetService(const char *proto) + */ +inline u_short +GetUdpService(void) +{ + return GetService("udp"); +} + static void parse_peer(peer ** head) { @@ -1568,12 +1611,12 @@ p->options.no_netdb_exchange = 1; } - p->http_port = GetShort(); + p->http_port = GetTcpService(); if (!p->http_port) self_destruct(); - p->icp.port = GetShort(); + p->icp.port = GetUdpService(); while ((token = strtok(NULL, w_space))) { if (!strcasecmp(token, "proxy-only")) {