Commit b38c3d32 authored by Geoff Simmons's avatar Geoff Simmons

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

parent bd74e05a
......@@ -747,6 +747,26 @@ GIP(server)
/*--------------------------------------------------------------------*/
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;
}
CHECK_OBJ_NOTNULL(sp->listen_sock, LISTEN_SOCK_MAGIC);
AN(sp->listen_sock->endpoint);
return (sp->listen_sock->endpoint);
}
/*--------------------------------------------------------------------*/
VCL_STRING
VRT_r_server_identity(VRT_CTX)
{
......
......@@ -5,7 +5,7 @@ server s1 -listen "${tmpdir}/s1.sock" {
txresp
} -start
varnish v1 -arg "-a ${tmpdir}/v1.sock" -vcl+backend {
varnish v1 -syntax 4.1 -arg "-a ${tmpdir}/v1.sock" -vcl+backend {
acl acl1 {
"${localhost}";
}
......@@ -16,6 +16,7 @@ varnish v1 -arg "-a ${tmpdir}/v1.sock" -vcl+backend {
set beresp.http.b-local = local.ip;
set beresp.http.b-remote = remote.ip;
set beresp.http.b-compare = local.ip == remote.ip;
set beresp.http.b-endpoint = local.endpoint;
}
sub vcl_deliver {
......@@ -28,6 +29,7 @@ varnish v1 -arg "-a ${tmpdir}/v1.sock" -vcl+backend {
set resp.http.server_acl = server.ip ~ acl1;
set resp.http.local_acl = local.ip ~ acl1;
set resp.http.remote_acl = remote.ip ~ acl1;
set resp.http.c-endpoint = local.endpoint;
}
} -start
......@@ -40,11 +42,13 @@ client c1 -connect "${tmpdir}/v1.sock" {
expect resp.http.c-local == "0.0.0.0"
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.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.client_acl == "false"
expect resp.http.server_acl == "false"
expect resp.http.local_acl == "false"
......
......@@ -106,13 +106,27 @@ varnish v1 -syntax 4.0 -errvcl {Symbol not found: 'sess.xid' (Only available whe
}
}
varnish v1 -syntax 4.0 -errvcl {Symbol not found: 'local.endpoint' (Only available when 4.1 <= VCL syntax)} {
sub vcl_recv {
set req.http.Endpoint = local.endpoint;
}
}
varnish v1 -syntax 4.0 -errvcl {Symbol not found: 'local.endpoint' (Only available when 4.1 <= VCL syntax)} {
sub vcl_backend_fetch {
set bereq.http.Endpoint = local.endpoint;
}
}
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;
}
sub vcl_deliver {
set resp.http.C-Sess-XID = sess.xid;
set resp.http.C-Endpoint = local.endpoint;
}
}
......@@ -123,4 +137,6 @@ client c1 {
expect resp.http.C-Sess-XID ~ "^[0-9]+$"
expect resp.http.B-Sess-XID ~ "^[0-9]+$"
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}"
} -run
......@@ -52,22 +52,34 @@ With PROXY protocol::
CLIENT ------------ PROXY ------------ VARNISHD
local.endpoint
local.ip
Type: IP
Readable from: client, backend
The IP address (and port number) of the local end of the
TCP connection, for instance `192.168.1.1:81`
If the connection is a UNIX domain socket, the value
will be `0.0.0.0:0`
local.endpoint ``VCL >= 4.1``
Type: STRING
Readable from: client
Readable from: client, backend
The address of the '-a' socket the session was accepted on.
If the argument was `-a foo=:81` this would be ":81"
local.socket
local.socket ``VCL >= 4.1``
Type: STRING
Readable from: client
Readable from: client, backend
The name of the '-a' socket the session was accepted on.
......@@ -76,18 +88,6 @@ local.socket
Note that all '-a' gets a default name on the form `a%d`
if no name is provided.
local.ip
Type: IP
Readable from: client, backend
The IP address (and port number) of the local end of the
TCP connection, for instance `192.168.1.1:81`
If the connection is a UNIX domain socket, the value
will be `0.0.0.0:0`
remote.ip
Type: IP
......
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