Mailing List Archive

[master] bc46b11d2 vrt: Make client.identity readable in backend tasks
commit bc46b11d22088073e75554a07cc72912f834c69f
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Fri Oct 9 15:57:43 2020 +0200

vrt: Make client.identity readable in backend tasks

This puts client.identity at the same level as client.ip which happens
to be its fall-back before being explicitly set.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 22acb7c7f..6a01cd5b5 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -440,6 +440,8 @@ struct busyobj {

uint16_t err_code;
const char *err_reason;
+
+ const char *client_identity;
};


diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index 1e77272c0..d80bd1ecc 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -132,6 +132,11 @@ VBO_GetBusyObj(struct worker *wrk, const struct req *req)

bo->do_stream = 1;

+ if (req->client_identity != NULL) {
+ bo->client_identity = WS_Copy(bo->ws, req->client_identity, -1);
+ XXXAN(bo->client_identity);
+ }
+
bo->director_req = req->director_hint;
bo->vcl = req->vcl;
VCL_Ref(bo->vcl);
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 1f3138e1c..957d49cdb 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -296,11 +296,19 @@ VRT_r_beresp_uncacheable(VRT_CTX)
VCL_STRING
VRT_r_client_identity(VRT_CTX)
{
+ const char *id;
+
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
- CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
- if (ctx->req->client_identity != NULL)
- return (ctx->req->client_identity);
- return (SES_Get_String_Attr(ctx->req->sp, SA_CLIENT_IP));
+ if (ctx->req != NULL) {
+ CHECK_OBJ(ctx->req, REQ_MAGIC);
+ id = ctx->req->client_identity;
+ } else {
+ CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+ id = ctx->bo->client_identity;
+ }
+ if (id != NULL)
+ return (id);
+ return (SES_Get_String_Attr(ctx->sp, SA_CLIENT_IP));
}

VCL_VOID
diff --git a/bin/varnishtest/tests/v00025.vtc b/bin/varnishtest/tests/v00025.vtc
index d3d0cf684..790f24873 100644
--- a/bin/varnishtest/tests/v00025.vtc
+++ b/bin/varnishtest/tests/v00025.vtc
@@ -2,8 +2,10 @@ varnishtest "More VCL coverage"

server s1 {
rxreq
+ expect req.http.c_id == "Samuel B. Nobody"
txresp
rxreq
+ expect req.http.c_id == ${localhost}
txresp
} -start

@@ -85,6 +87,7 @@ varnish v1 -syntax 4.0 -vcl+backend {
}

sub vcl_backend_fetch {
+ set bereq.http.c_id = client.identity;
if (bereq.between_bytes_timeout < 10s) {
set bereq.http.quick = "please";
}
@@ -147,6 +150,10 @@ varnish v1 -syntax 4.0 -errvcl {Symbol not found: 'local.socket' (Only available
}

varnish v1 -syntax 4.1 -vcl+backend {
+ sub vcl_backend_fetch {
+ set bereq.http.c_id = client.identity;
+ }
+
sub vcl_backend_response {
set beresp.http.B-Sess-XID = sess.xid;
set beresp.http.B-Endpoint = local.endpoint;
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index a6e67d2d2..72098379a 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -117,7 +117,7 @@ client.identity

Type: STRING

- Readable from: client
+ Readable from: client, backend

Writable from: client

_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit