[master] b38c3d3 Implement VCL var local.endpoint (VCL >= 4.1).
Geoff Simmons
geoff at uplex.de
Mon Mar 12 09:55:10 UTC 2018
commit b38c3d32bc060c213e380ca553dfa927822e863d
Author: Geoff Simmons <geoff at uplex.de>
Date: Wed Mar 7 17:15:49 2018 +0100
Implement VCL var local.endpoint (VCL >= 4.1).
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 2d08ffa..f543157 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -748,6 +748,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)
{
diff --git a/bin/varnishtest/tests/c00087.vtc b/bin/varnishtest/tests/c00087.vtc
index 761ba0d..3f2a3e3 100644
--- a/bin/varnishtest/tests/c00087.vtc
+++ b/bin/varnishtest/tests/c00087.vtc
@@ -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"
diff --git a/bin/varnishtest/tests/v00025.vtc b/bin/varnishtest/tests/v00025.vtc
index 9a20422..9639053 100644
--- a/bin/varnishtest/tests/v00025.vtc
+++ b/bin/varnishtest/tests/v00025.vtc
@@ -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
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index 8f20afc..c66386c 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -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
More information about the varnish-commit
mailing list