Commit 29c0c571 authored by Geoff Simmons's avatar Geoff Simmons

Implement VCL var local.socket (VCL >= 4.1).

parent b38c3d32
......@@ -745,26 +745,33 @@ GIP(client)
GIP(server)
#undef GIP
/*--------------------------------------------------------------------*/
VCL_STRING
VRT_r_local_endpoint(VRT_CTX)
{
struct sess *sp;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (VALID_OBJ(ctx->req, REQ_MAGIC))
sp = ctx->req->sp;
else {
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
sp = ctx->bo->sp;
}
/*--------------------------------------------------------------------
* local.[endpoint|socket]
*/
CHECK_OBJ_NOTNULL(sp->listen_sock, LISTEN_SOCK_MAGIC);
AN(sp->listen_sock->endpoint);
return (sp->listen_sock->endpoint);
#define LOC(var,fld) \
VCL_STRING \
VRT_r_local_##var(VRT_CTX) \
{ \
struct sess *sp; \
\
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
if (VALID_OBJ(ctx->req, REQ_MAGIC)) \
sp = ctx->req->sp; \
else { \
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); \
sp = ctx->bo->sp; \
} \
\
CHECK_OBJ_NOTNULL(sp->listen_sock, LISTEN_SOCK_MAGIC); \
AN(sp->listen_sock->fld); \
return (sp->listen_sock->fld); \
}
LOC(endpoint, endpoint)
LOC(socket, name)
#undef LOC
/*--------------------------------------------------------------------*/
VCL_STRING
......
......@@ -5,7 +5,7 @@ server s1 -listen "${tmpdir}/s1.sock" {
txresp
} -start
varnish v1 -syntax 4.1 -arg "-a ${tmpdir}/v1.sock" -vcl+backend {
varnish v1 -syntax 4.1 -arg "-a foo=${tmpdir}/v1.sock" -vcl+backend {
acl acl1 {
"${localhost}";
}
......@@ -17,6 +17,7 @@ varnish v1 -syntax 4.1 -arg "-a ${tmpdir}/v1.sock" -vcl+backend {
set beresp.http.b-remote = remote.ip;
set beresp.http.b-compare = local.ip == remote.ip;
set beresp.http.b-endpoint = local.endpoint;
set beresp.http.b-socket = local.socket;
}
sub vcl_deliver {
......@@ -30,6 +31,7 @@ varnish v1 -syntax 4.1 -arg "-a ${tmpdir}/v1.sock" -vcl+backend {
set resp.http.local_acl = local.ip ~ acl1;
set resp.http.remote_acl = remote.ip ~ acl1;
set resp.http.c-endpoint = local.endpoint;
set resp.http.c-socket = local.socket;
}
} -start
......@@ -43,12 +45,14 @@ client c1 -connect "${tmpdir}/v1.sock" {
expect resp.http.c-remote == "0.0.0.0"
expect resp.http.c-compare == "true"
expect resp.http.c-endpoint == "${tmpdir}/v1.sock"
expect resp.http.c-socket == "foo"
expect resp.http.b-client == "0.0.0.0"
expect resp.http.b-server == "0.0.0.0"
expect resp.http.b-local == "0.0.0.0"
expect resp.http.b-remote == "0.0.0.0"
expect resp.http.b-compare == "true"
expect resp.http.b-endpoint == "${tmpdir}/v1.sock"
expect resp.http.b-socket == "foo"
expect resp.http.client_acl == "false"
expect resp.http.server_acl == "false"
expect resp.http.local_acl == "false"
......
......@@ -118,15 +118,29 @@ varnish v1 -syntax 4.0 -errvcl {Symbol not found: 'local.endpoint' (Only availab
}
}
varnish v1 -syntax 4.0 -errvcl {Symbol not found: 'local.socket' (Only available when 4.1 <= VCL syntax)} {
sub vcl_recv {
set req.http.Socket = local.socket;
}
}
varnish v1 -syntax 4.0 -errvcl {Symbol not found: 'local.socket' (Only available when 4.1 <= VCL syntax)} {
sub vcl_backend_fetch {
set bereq.http.Socket = local.socket;
}
}
varnish v1 -syntax 4.1 -vcl+backend {
sub vcl_backend_response {
set beresp.http.B-Sess-XID = sess.xid;
set beresp.http.B-Endpoint = local.endpoint;
set beresp.http.B-Socket = local.socket;
}
sub vcl_deliver {
set resp.http.C-Sess-XID = sess.xid;
set resp.http.C-Endpoint = local.endpoint;
set resp.http.C-Socket = local.socket;
}
}
......@@ -139,4 +153,52 @@ client c1 {
expect resp.http.C-Sess-XID == resp.http.B-Sess-XID
expect resp.http.C-Endpoint == "${v1_addr}:${v1_port}"
expect resp.http.B-Endpoint == "${v1_addr}:${v1_port}"
expect resp.http.C-Socket == "a0"
expect resp.http.B-Socket == "a0"
} -run
varnish v1 -stop
server s1 {
rxreq
txresp
rxreq
txresp
} -start
varnish v2 -arg "-a foo=${tmpdir}/foo.sock -a bar=${tmpdir}/bar.sock" \
-syntax 4.1 -vcl+backend {
sub vcl_backend_response {
set beresp.http.B-Endpoint = local.endpoint;
set beresp.http.B-Socket = local.socket;
}
sub vcl_deliver {
set resp.http.C-Endpoint = local.endpoint;
set resp.http.C-Socket = local.socket;
}
} -start
client c2 -connect "${tmpdir}/foo.sock" {
txreq
rxresp
expect resp.status == 200
expect resp.http.C-Endpoint == "${tmpdir}/foo.sock"
expect resp.http.B-Endpoint == "${tmpdir}/foo.sock"
expect resp.http.C-Socket == "foo"
expect resp.http.B-Socket == "foo"
} -run
# The backend endpoint/socket may be either of the two possibilities,
# because the busyobj may point to the session started for the first
# fetch.
client c2 -connect "${tmpdir}/bar.sock" {
txreq
rxresp
expect resp.status == 200
expect resp.http.C-Endpoint == "${tmpdir}/bar.sock"
expect resp.http.B-Endpoint ~ "^${tmpdir}/(bar|foo).sock$"
expect resp.http.C-Socket == "bar"
expect resp.http.B-Socket ~ "^(bar|foo)$"
} -run
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment