From: petter Date: Tue, 22 Jul 2008 07:52:00 +0000 (+0000) Subject: Added the variable server.port that holds the port on which the server has answered... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08643564132add192033ed26d4f5ebbbd3b78fee;p=varnish 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2983 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index d17fef09..2ac8eada 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -478,6 +478,19 @@ VRT_r_server_ip(struct sess *sp) 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. */ diff --git a/varnish-cache/include/vrt_obj.h b/varnish-cache/include/vrt_obj.h index 24b5a9a9..39675c25 100644 --- a/varnish-cache/include/vrt_obj.h +++ b/varnish-cache/include/vrt_obj.h @@ -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 *); diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 4f5654c9..8254a75f 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -465,6 +465,7 @@ vcl_output_lang_h(struct vsb *sb) 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"); diff --git a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl index 08ce82a2..ed06f538 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl @@ -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 @@ set spobj { {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 diff --git a/varnish-cache/lib/libvcl/vcc_obj.c b/varnish-cache/lib/libvcl/vcc_obj.c index 2ab9c031..f674d5ff 100644 --- a/varnish-cache/lib/libvcl/vcc_obj.c +++ b/varnish-cache/lib/libvcl/vcc_obj.c @@ -25,6 +25,13 @@ struct var vcc_vars[] = { 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, ", diff --git a/varnish-cache/man/vcl.7 b/varnish-cache/man/vcl.7 index 3549ebda..6d1e0bdc 100644 --- a/varnish-cache/man/vcl.7 +++ b/varnish-cache/man/vcl.7 @@ -394,6 +394,9 @@ The client's IP address. .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