Skip to content

Commit

Permalink
acceptor: use %kind to select the acceptor implementation
Browse files Browse the repository at this point in the history
We add [%kind,] to the acceptor command line options to select the acceptor
implementation. The syntax is now:

	[name=][%<kind>,][listen_address[,PROTO|,option=value,...]]

Reasons are explained in #4169
  • Loading branch information
nigoroll committed Nov 9, 2024
1 parent f5b5e1d commit 8f5ae74
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
25 changes: 18 additions & 7 deletions bin/varnishd/acceptor/mgt_acceptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ VCA_reopen_sockets(void)
return (fail);
}

/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------
* [name=][%kind,][listen_address[,PROTO|,option=value,...]]
*/

void
VCA_Arg(const char *spec)
{
struct acceptor *vca;
char **av;
struct acceptor *vca = NULL;
char **av, **ap;
struct listen_arg *la;
const char *err;
int error;
Expand All @@ -122,12 +124,21 @@ VCA_Arg(const char *spec)

av = MGT_NamedArg(spec, &name, "-a");
AN(av);
ap = av + 1;

ALLOC_OBJ(la, LISTEN_ARG_MAGIC);
AN(la);
VTAILQ_INIT(&la->socks);
VTAILQ_INSERT_TAIL(&listen_args, la, list);
la->endpoint = av[1];

if (ap[0] != NULL && ap[0][0] == '%') {
vca = VCA_Find(ap[0] + 1);
if (vca == NULL)
ARGV_ERR("Acceptor %s not found\n", ap[0] + 1);
ap++;
}

la->endpoint = *(ap++);

if (name == NULL) {
bprintf(name_buf, "a%u", seq++);
Expand All @@ -137,13 +148,13 @@ VCA_Arg(const char *spec)

la->name = name;

if (VUS_is(la->endpoint))
if (vca == NULL && VUS_is(la->endpoint))
vca = VCA_Find("uds");
else
else if (vca == NULL)
vca = VCA_Find("tcp");

AN(vca);
error = vca->open(av + 2, la, &err);
error = vca->open(ap, la, &err);

if (error) {
ARGV_ERR("Got no socket(s) for %s=%s (%s)\n",
Expand Down
1 change: 1 addition & 0 deletions bin/varnishd/acceptor/mgt_acceptor_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ vca_tcp_open(char **av, struct listen_arg *la, const char **err)
CHECK_OBJ_NOTNULL(la, LISTEN_ARG_MAGIC);
AN(av);
AN(err);
AN(la->endpoint);
AZ(la->perms);

if (strchr(la->endpoint, '/') != NULL)
Expand Down
5 changes: 5 additions & 0 deletions bin/varnishd/acceptor/mgt_acceptor_uds.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ vca_uds_open(char **av, struct listen_arg *la, const char **err)
CHECK_OBJ_NOTNULL(la, LISTEN_ARG_MAGIC);
AN(av);
AN(err);
AN(la->endpoint);

if (! VUS_is(la->endpoint)) {
ARGV_ERR("Not a unix domain socket addresses"
" in -a (%s)\n", la->endpoint);
}
if (*la->endpoint != '/' && strchr(la->endpoint, '/') != NULL)
ARGV_ERR("Unix domain socket addresses must be"
" absolute paths in -a (%s)\n", la->endpoint);
Expand Down
3 changes: 2 additions & 1 deletion bin/varnishd/mgt/mgt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ usage(void)

printf("\nBasic options:\n");

printf(FMT, "[-a [name=][listen_address",
printf(FMT, "[-a [name=][%kind,][listen_address",
"HTTP listen address, protocol, options.");
printf(FMT, " [,PROTO|,option=value,...]]",
"Can be specified multiple times.");
printf(FMT, "",
" default: \":80,HTTP\"");
printf(FMT, " %kind", "Selects an acceptor implementation");
printf(FMT, " options:",
"Proto can be \"PROXY\" or \"HTTP\" (default)");
printf(FMT, " [,user=<u>][,group=<g>]",
Expand Down
10 changes: 6 additions & 4 deletions doc/sphinx/reference/varnishd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SYNOPSIS
========

varnishd
[-a [name=][listen_address[,PROTO|,option=value,...]]
[-a [name=][%kind,][listen_address[,PROTO|,option=value,...]]
[-b [host[:port]|path]]
[-C]
[-d]
Expand Down Expand Up @@ -63,14 +63,16 @@ OPTIONS
Basic options
-------------

-a <[name=][listen_address[,PROTO|,option=value,...]]>
-a <[name=][%kind,][listen_address[,PROTO|,option=value,...]]>

Generic syntax to accept client requests on a listen_address. See below for
details.

Name is referenced in logs and available to vcl as ``local.socket``. If name
is not specified, ``a`` with a numerical sequence ("a0", "a1", etc.) is used.

``%kind`` selects the acceptor implementation *kind*.

Any arguments after the listen_address separated by comma are taken as either
an acceptor ``option=value`` pair if containing a ``=``, or as a PROTO(col)
selection otherwise.
Expand All @@ -85,7 +87,7 @@ Basic options
If no -a argument is given, the default `-a :80` will listen on
all IPv4 and IPv6 interfaces.

-a <[name=][ip_address][:port][,PROTO]>
-a <[name=][%kind,][ip_address][:port][,PROTO]>

The ip_address can be a host name ("localhost"), an IPv4 dotted-quad
("127.0.0.1") or an IPv6 address enclosed in square brackets
Expand All @@ -97,7 +99,7 @@ Basic options

At least one of ip_address or port is required.

-a <[name=][path][,PROTO][,user=name][,group=name][,mode=octal]>
-a <[name=][%kind,][path][,PROTO][,user=name][,group=name][,mode=octal]>

(VCL4.1 and higher)

Expand Down
4 changes: 2 additions & 2 deletions doc/sphinx/users-guide/command-line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ you will find the startup options here:
* FreeBSD: `/etc/rc.conf` (See also: /usr/local/etc/rc.d/varnishd)


'-a' *<[name=][listen_address[,PROTO|,option=value,...]]>*
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'-a' *<[name=][%kind,][listen_address[,PROTO|,option=value,...]]>*
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Each '-a' argument defines one endpoint which Varnish should service HTTP
requests on.
Expand Down

0 comments on commit 8f5ae74

Please sign in to comment.