Proxy protocol v1 client port fix

Rafael Zalamena rafaelfz at taghos.com.br
Fri Nov 6 11:40:16 CET 2015


After giving the proxy feature a try I noticed the client port collected
in the vpx_proto1() function is wrong. I read the code and noticed it
splits the proxy line in tokens and then when reading the client port it
picks the wrong token.

      0          1       2       3       4
PROXY PROTO_IPVX SRCADDR DSTADDR SRCPORT DSTPORT\r\n

The code is partially working because when it resolves the address it uses
the right token:
cache_proxy_proto.c:line 110
i = getaddrinfo(fld[1], fld[3], &hints, &res);

The proxy version 2 part seems to be working correctly.

The diff below fixes the problem I just reported.

diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c
index 604d796..6f64f3a 100644
--- a/bin/varnishd/proxy/cache_proxy_proto.c
+++ b/bin/varnishd/proxy/cache_proxy_proto.c
@@ -125,7 +125,7 @@ vpx_proto1(const struct worker *wrk, struct req *req)
 	SES_Reserve_client_addr(req->sp, &sa);
 	AN(VSA_Build(sa, res->ai_addr, res->ai_addrlen));
 	SES_Set_String_Attr(req->sp, SA_CLIENT_IP, fld[1]);
-	SES_Set_String_Attr(req->sp, SA_CLIENT_PORT, fld[2]);
+	SES_Set_String_Attr(req->sp, SA_CLIENT_PORT, fld[3]);
 	freeaddrinfo(res);
 
 	i = getaddrinfo(fld[2], fld[4], &hints, &res);



More information about the varnish-dev mailing list