[master] 44fc7c4 Make the four IP#s available also in backend vcl methods.

Poul-Henning Kamp phk at FreeBSD.org
Fri Apr 8 00:13:04 CEST 2016


commit 44fc7c413debeb19bb34ec3e6a452da15b23f956
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Apr 7 22:12:16 2016 +0000

    Make the four IP#s available also in backend vcl methods.

diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 442bd47..10879c0 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -604,9 +604,8 @@ VRT_r_req_##field(VRT_CTX)				\
 		struct suckaddr *sa;				\
 								\
 		CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);		\
-		CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);		\
-		CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC);	\
-		AZ(SES_Get_##fld##_addr(ctx->req->sp, &sa));	\
+		CHECK_OBJ_NOTNULL(ctx->sp, SESS_MAGIC);		\
+		AZ(SES_Get_##fld##_addr(ctx->sp, &sa));		\
 		return (sa);					\
 	}
 
diff --git a/bin/varnishtest/tests/o00003.vtc b/bin/varnishtest/tests/o00003.vtc
new file mode 100644
index 0000000..d821ce7
--- /dev/null
+++ b/bin/varnishtest/tests/o00003.vtc
@@ -0,0 +1,24 @@
+varnishtest "VCL backend side access to IP#s"
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -proto PROXY -vcl+backend {
+	sub vcl_backend_response {
+		set beresp.http.li = local.ip;
+		set beresp.http.ri = remote.ip;
+		set beresp.http.ci = client.ip;
+		set beresp.http.si = server.ip;
+	}
+} -start
+
+client c1 {
+	send "PROXY TCP4 1.2.3.4 5.6.7.8 1111 5678\r\n"
+	txreq
+	rxresp
+	expect resp.http.li == ${v1_addr}
+	expect resp.http.ci == 1.2.3.4
+	expect resp.http.si == 5.6.7.8
+} -run
diff --git a/bin/varnishtest/tests/v00017.vtc b/bin/varnishtest/tests/v00017.vtc
index e00ad4f..d3a0ccf 100644
--- a/bin/varnishtest/tests/v00017.vtc
+++ b/bin/varnishtest/tests/v00017.vtc
@@ -64,12 +64,6 @@ varnish v1 -vcl {
 	sub vcl_recv { if (client.ip ~ a) { return(pass); } }
 }
 
-varnish v1 -errvcl {'client.ip': Not available in method 'vcl_backend_response'} {
-	backend b { .host = "127.0.0.1"; }
-	sub vcl_recv { if (client.ip == "127.0.0.1") { return(pass); } }
-	sub vcl_backend_response { if (client.ip != "127.0.0.1") { return(retry); } }
-}
-
 varnish v1 -errvcl {Operator > not possible on IP} {
 	backend b { .host = "127.0.0.1"; }
 	sub vcl_recv { if (client.ip > "127.0.0.1") { return(pass); } }
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 5efcff1..61cfc4d 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -160,7 +160,7 @@ returns =(
 sp_variables = [
 	('remote.ip',
 		'IP',
-		( 'client',),
+		( 'client', 'backend'),
 		( ), """
 		The IP address of the other end of the TCP connection.
 		This can either be the clients IP, or the outgoing IP
@@ -169,7 +169,7 @@ sp_variables = [
 	),
 	('client.ip',
 		'IP',
-		( 'client',),
+		( 'client', 'backend'),
 		( ), """
 		The client's IP address.
 		"""
@@ -184,14 +184,14 @@ sp_variables = [
 	),
 	('local.ip',
 		'IP',
-		( 'client',),
+		( 'client', 'backend'),
 		( ), """
 		The IP address of the local end of the TCP connection.
 		"""
 	),
 	('server.ip',
 		'IP',
-		( 'client',),
+		( 'client', 'backend'),
 		( ), """
 		The IP address of the socket on which the client
 		connection was received.



More information about the varnish-commit mailing list