Re: getservbyname support for cache_peer ports.

From: Pawel Worach <pawel.worach@dont-contact.us>
Date: Thu, 4 Oct 2007 18:03:29 +0200

On 10/3/07, Amos Jeffries <squid3@treenet.co.nz> wrote:
> > 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.
> >
>
> Wonderful. Thank you very much for this addition.
>
> Amos
>

Per Henrik's suggestion on IRC, add wrappers for TCP and UDP.

--- src/cache_cf.c.orig 2007-10-02 20:30:27.000000000 +0200
+++ src/cache_cf.c 2007-10-04 17:58:40.000000000 +0200
@@ -290,6 +290,31 @@
     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 u_short
+GetTcpService(void)
+{
+ return GetService("tcp");
+}
+
+static u_short
+GetUdpService(void)
+{
+ return GetService("udp");
+}
+
 static squid_off_t
 GetOffT(void)
 {
@@ -1634,10 +1659,10 @@
        p->options.no_digest = 1;
        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();
     p->connection_auth = -1; /* auto */
     while ((token = strtok(NULL, w_space))) {
        if (!strcasecmp(token, "proxy-only")) {

-- 
Pawel
Received on Thu Oct 04 2007 - 10:03:35 MDT

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