getservbyname support for cache_peer ports.

From: Pawel Worach <pawel.worach@dont-contact.us>
Date: Tue, 2 Oct 2007 21:49:45 +0200

Hi,

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 \
  no-digest no-netdb-exchange
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.

Also note that the GetShort and the various ushortlist functions are
unused in cache_cf.c, can they be removed ?

ps. Only tested on FreeBSD.

--- src/cache_cf.c.orig 2007-10-02 20:30:27.000000000 +0200
+++ src/cache_cf.c 2007-10-02 21:46:04.000000000 +0200
@@ -290,6 +290,19 @@
     return xatos(token);
 }

+static u_short
+GetService(const char *proto)
+{
+ struct servent *port = NULL;
+ char *token = strtok(NULL, w_space);
+ if (token == NULL)
+ self_destruct();
+ port = getservbyname(token, proto);
+ if (port != NULL)
+ return ntohs((u_short)port->s_port);
+ return xatos(token);
+}
+
 static squid_off_t
 GetOffT(void)
 {
@@ -1634,10 +1647,10 @@
        p->options.no_digest = 1;
        p->options.no_netdb_exchange = 1;
     }
- p->http_port = GetShort();
+ p->http_port = GetService("tcp");
     if (!p->http_port)
        self_destruct();
- p->icp.port = GetShort();
+ p->icp.port = GetService("udp");
     p->connection_auth = -1; /* auto */
     while ((token = strtok(NULL, w_space))) {
        if (!strcasecmp(token, "proxy-only")) {

-- 
Pawel
Received on Tue Oct 02 2007 - 13:49:50 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Oct 30 2007 - 13:00:03 MDT