Re: getservbyname support for cache_peer ports.

From: Alex Rousskov <rousskov@dont-contact.us>
Date: Mon, 12 Nov 2007 09:27:16 -0700

On Sun, 2007-11-11 at 22:46 +1300, Amos Jeffries wrote:
> This wanted improvement seems to have been left out so far.
> Any objections to this patch going into either version of squid now?

No objection from me regarding Squid3, especially if you can test that
it compiles fine on at least one non-FreeBSD OS.

Thank you,

Alex.

> Pawel Worach wrote:
> > 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")) {
> >
Received on Mon Nov 12 2007 - 09:27:25 MST

This archive was generated by hypermail pre-2.1.9 : Sat Dec 01 2007 - 12:00:05 MST