[master] 8ff2953 Introduce local.ip and remote.ip VCL variables.

Poul-Henning Kamp phk at FreeBSD.org
Wed Mar 18 21:04:03 CET 2015


commit 8ff29534ba0154e883d18017105648d138264f83
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Mar 18 20:02:59 2015 +0000

    Introduce local.ip and remote.ip VCL variables.
    
    These reference the actual TCP connection, whereas client.ip and server.ip
    may (in a near future) talk about another TCP connection terminating in
    a proxy in front of Varnish.

diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index c05d6c7..2088d5d 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -551,7 +551,7 @@ pool_mkpool(unsigned pool_no)
 	AZ(pthread_create(&pp->herder_thr, NULL, pool_herder, pp));
 
 	while (VTAILQ_EMPTY(&pp->idle_queue))
-		usleep(10000);
+		(void)usleep(10000);
 
 	pp->sesspool = SES_NewPool(pp, pool_no);
 	AN(pp->sesspool);
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index f896438..e900726 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -593,29 +593,26 @@ VRT_r_req_##field(VRT_CTX)				\
 
 /*--------------------------------------------------------------------*/
 
-VCL_IP
-VRT_r_client_ip(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_remote_addr(ctx->req->sp, &sa));
-	return (sa);
-}
+#define GIP(fld)						\
+	VCL_IP							\
+	VRT_r_##fld##_ip(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));	\
+		return (sa);					\
+	}
 
-VCL_IP
-VRT_r_server_ip(VRT_CTX)
-{
-	struct suckaddr *sa;
+GIP(local)
+GIP(remote)
+GIP(client)
+GIP(server)
+#undef GIP
 
-	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_local_addr(ctx->req->sp, &sa));
-	return (sa);
-}
+/*--------------------------------------------------------------------*/
 
 const char*
 VRT_r_server_identity(VRT_CTX)
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 871b8bc..19da0e0 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -157,6 +157,15 @@ returns =(
 # 'both' means all methods tagged "B" or "C"
 
 sp_variables = [
+	('remote.ip',
+		'IP',
+		( 'client',),
+		( ), """
+		The IP address of the other end of the TCP connection.
+		This can either be the clients IP, or the outgoing IP
+		of a proxy server.
+		"""
+	),
 	('client.ip',
 		'IP',
 		( 'client',),
@@ -172,6 +181,13 @@ sp_variables = [
 		in the client director.
 		"""
 	),
+	('local.ip',
+		'IP',
+		( 'client',),
+		( ), """
+		The IP address of the local end of the TCP connection.
+		"""
+	),
 	('server.ip',
 		'IP',
 		( 'client',),



More information about the varnish-commit mailing list