r2983 - in trunk/varnish-cache: bin/varnishd include lib/libvcl man

petter at projects.linpro.no petter at projects.linpro.no
Tue Jul 22 09:52:00 CEST 2008


Author: petter
Date: 2008-07-22 09:52:00 +0200 (Tue, 22 Jul 2008)
New Revision: 2983

Modified:
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
   trunk/varnish-cache/include/vrt_obj.h
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
   trunk/varnish-cache/lib/libvcl/vcc_obj.c
   trunk/varnish-cache/man/vcl.7
Log:
Added the variable server.port that holds the port on which the server has answered the request in the same way that server.ip holds the IP number. Fixes #264.


Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2008-07-22 07:37:32 UTC (rev 2982)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2008-07-22 07:52:00 UTC (rev 2983)
@@ -478,6 +478,19 @@
 	return (sp->mysockaddr);
 }
 
+int
+VRT_r_server_port(struct sess *sp)
+{
+	char abuf[TCP_ADDRBUFSIZE];
+	char pbuf[TCP_PORTBUFSIZE];
+
+	if (sp->mysockaddr->sa_family == AF_UNSPEC)
+		AZ(getsockname(sp->fd, sp->mysockaddr, &sp->mysockaddrlen));
+	TCP_name(sp->mysockaddr, sp->mysockaddrlen, abuf, sizeof abuf, pbuf, sizeof pbuf);
+
+	return (atoi(pbuf));
+}
+
 /*--------------------------------------------------------------------
  * Add an element to the array/list of hash bits.
  */

Modified: trunk/varnish-cache/include/vrt_obj.h
===================================================================
--- trunk/varnish-cache/include/vrt_obj.h	2008-07-22 07:37:32 UTC (rev 2982)
+++ trunk/varnish-cache/include/vrt_obj.h	2008-07-22 07:52:00 UTC (rev 2983)
@@ -8,6 +8,7 @@
 
 struct sockaddr * VRT_r_client_ip(const struct sess *);
 struct sockaddr * VRT_r_server_ip(struct sess *);
+int VRT_r_server_port(struct sess *);
 const char * VRT_r_req_request(const struct sess *);
 void VRT_l_req_request(const struct sess *, const char *, ...);
 const char * VRT_r_req_url(const struct sess *);

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2008-07-22 07:37:32 UTC (rev 2982)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2008-07-22 07:52:00 UTC (rev 2983)
@@ -465,6 +465,7 @@
 	vsb_cat(sb, "\n");
 	vsb_cat(sb, "struct sockaddr * VRT_r_client_ip(const struct sess *);\n");
 	vsb_cat(sb, "struct sockaddr * VRT_r_server_ip(struct sess *);\n");
+	vsb_cat(sb, "int VRT_r_server_port(struct sess *);\n");
 	vsb_cat(sb, "const char * VRT_r_req_request(const struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_req_request(const struct sess *, const char *, ...);\n");
 	vsb_cat(sb, "const char * VRT_r_req_url(const struct sess *);\n");

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2008-07-22 07:37:32 UTC (rev 2982)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2008-07-22 07:52:00 UTC (rev 2983)
@@ -1,4 +1,4 @@
-#!/usr/local/bin/tclsh8.4
+#!/usr/bin/tclsh8.4
 #-
 # Copyright (c) 2006 Verdens Gang AS
 # Copyright (c) 2006-2008 Linpro AS
@@ -51,7 +51,11 @@
 		{recv pipe pass hash miss hit fetch deliver                }
 		"struct sess *"
 	}
-
+	{ server.port
+		RO INT
+		{recv pipe pass hash miss hit fetch deliver                }
+		"struct sess *"
+	}
 	# Request paramters
 	{ req.request
 		RW STRING

Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_obj.c	2008-07-22 07:37:32 UTC (rev 2982)
+++ trunk/varnish-cache/lib/libvcl/vcc_obj.c	2008-07-22 07:52:00 UTC (rev 2983)
@@ -25,6 +25,13 @@
 	    0,
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
 	},
+	{ "server.port", INT, 11,
+	    "VRT_r_server_port(sp)",
+	    NULL,
+	    V_RO,
+	    0,
+	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
+	},
 	{ "req.request", STRING, 11,
 	    "VRT_r_req_request(sp)",
 	    "VRT_l_req_request(sp, ",

Modified: trunk/varnish-cache/man/vcl.7
===================================================================
--- trunk/varnish-cache/man/vcl.7	2008-07-22 07:37:32 UTC (rev 2982)
+++ trunk/varnish-cache/man/vcl.7	2008-07-22 07:52:00 UTC (rev 2983)
@@ -394,6 +394,9 @@
 .It Va server.ip
 The IP address of the socket on which the client connection was
 received.
+.It Va server.port
+The port number of the socket on which the client connection was
+received.
 .It Va req.request
 The request type (e.g. "GET", "HEAD").
 .It Va req.url




More information about the varnish-commit mailing list