Re: getservbyname support for cache_peer ports.

From: Amos Jeffries <squid3@dont-contact.us>
Date: Tue, 13 Nov 2007 12:06:34 +1300 (NZDT)

> 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.
>

Well, I've tested and its working on Debian, Ubuntu as well as the initial
FreeBSD.
The only problem seen is that 3128 is not by default listed in the
/etc/services on those OS. So it's not immediately possible to switch all
default config examples to using the simple text names.

It has now been committed.

Amos

> 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 - 16:06:37 MST

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