Commit 22677062 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add INT std.port(IP) which extracts the TCP port number.

By default IP renders as STRING with just the IP number, so if you
want to get the port number there too, you have to do something
like:

	set resp.http.where = client.ip + ":" + std.port(client.ip);

Not too elegant, but it will do.

Remove the "hard-coded" "foo.port" VCL variables.
parent 351e100e
......@@ -40,7 +40,6 @@
#include "cache_backend.h"
#include "vrt.h"
#include "vrt_obj.h"
#include "vsa.h"
static char vrt_hostname[255] = "";
......@@ -265,16 +264,6 @@ VRT_r_beresp_backend_ip(const struct vrt_ctx *ctx)
return(ctx->bo->vbc->addr);
}
long
VRT_r_beresp_backend_port(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
CHECK_OBJ_NOTNULL(ctx->bo->vbc, VBC_MAGIC);
return (VSA_Port(ctx->bo->vbc->addr));
}
const char *
VRT_r_beresp_storage(const struct vrt_ctx *ctx)
{
......@@ -546,20 +535,6 @@ VRT_r_server_hostname(const struct vrt_ctx *ctx)
return (vrt_hostname);
}
/*--------------------------------------------------------------------
* XXX: This is pessimistically silly
*/
long
VRT_r_server_port(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
AN(ctx->req->sp->local_addr);
return (VSA_Port(ctx->req->sp->local_addr));
}
/*--------------------------------------------------------------------*/
#define VOBJ_L(type, field) \
......
......@@ -12,9 +12,9 @@ varnish v1 -vcl {
sub vcl_hit { return(error(100,"the butter please")); }
}
varnish v1 -errvcl {Variable 'server.port' is read only.} {
varnish v1 -errvcl {Variable 'now' is read only.} {
backend b { .host = "127.0.0.1"; }
sub vcl_miss { set server.port = 1000; }
sub vcl_miss { set now = 1000; }
}
varnish v1 -vcl {
......@@ -34,7 +34,7 @@ varnish v1 -errvcl {Expected '=' got '+='} {
varnish v1 -errvcl {Expected '=' got '+='} {
backend b { .host = "127.0.0.1"; }
sub vcl_recv { set req.url += server.port; }
sub vcl_recv { set req.url += now; }
}
varnish v1 -errvcl {Expected ';' got 'if'} {
......
......@@ -7,8 +7,10 @@ server s1 {
varnish v1 -vcl+backend {
import ${vmod_std};
sub vcl_deliver {
set resp.http.server_port = server.port;
set resp.http.server_port = std.port(server.ip);
}
sub vcl_backend_response {
......
......@@ -142,14 +142,6 @@ The client's IP address.
specified by the -n parameter.
"""
),
('server.port',
'INT',
( 'client',),
( ), """
The port number of the socket on which the client
connection was received.
"""
),
('req.method',
'STRING',
( 'client',),
......@@ -424,13 +416,6 @@ The client's IP address.
IP of the backend this response was fetched from.
"""
),
('beresp.backend.port',
'INT',
( 'backend_response',),
( ), """
Port of the backend this response was fetched from.
"""
),
('beresp.storage',
'STRING',
( 'backend_response',),
......
......@@ -38,3 +38,4 @@ Function INT integer(STRING, INT)
Function VOID collect(HEADER)
Function IP ip(STRING, IP)
Function BOOL healthy(BACKEND)
Function INT port(IP)
......@@ -40,6 +40,7 @@
#include "vrt.h"
#include "vtcp.h"
#include "vsa.h"
#include "cache/cache.h"
#include "cache/cache_backend.h"
......@@ -194,3 +195,12 @@ vmod_healthy(const struct vrt_ctx *ctx, VCL_BACKEND be)
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
return (VDI_Healthy(be));
}
VCL_INT __match_proto__(td_std_port)
vmod_port(const struct vrt_ctx *ctx, VCL_IP ip)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (ip == NULL)
return (0);
return (VSA_Port(ip));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment