[master] 6a08beba4 split out proxyv1 formatting

Nils Goroll nils.goroll at uplex.de
Wed Jan 15 16:12:07 UTC 2020


commit 6a08beba48a92f1a73c0565de5edc9a0c27d37d5
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Nov 23 15:26:19 2018 +0100

    split out proxyv1 formatting
    
    Note: this partially reverts cf14a0fd774fcbcd4bfd2d50bcbe029f63ff7e0e
    to prepare for bytes accounting in a later patch

diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c
index 80d93349e..69722805f 100644
--- a/bin/varnishd/proxy/cache_proxy_proto.c
+++ b/bin/varnishd/proxy/cache_proxy_proto.c
@@ -606,11 +606,36 @@ vpx_enc_port(struct vsb *vsb, const struct suckaddr *s)
 	VSB_bcat(vsb, b, sizeof(b));
 }
 
+/* short path for stringified addresses from session attributes */
+static void
+vpx_format_proxy_v1(struct vsb *vsb, int proto,
+    const char *cip,  const char *cport,
+    const char *sip,  const char *sport)
+{
+	AN(vsb);
+	AN(cip);
+	AN(cport);
+	AN(sip);
+	AN(sport);
+
+	VSB_bcat(vsb, vpx1_sig, sizeof(vpx1_sig));
+
+	if (proto == PF_INET6)
+		VSB_cat(vsb, " TCP6 ");
+	else if (proto == PF_INET)
+		VSB_cat(vsb, " TCP4 ");
+	else
+		WRONG("Wrong proxy v1 proto");
+
+	VSB_printf(vsb, "%s %s %s %s\r\n", cip, sip, cport, sport);
+
+	AZ(VSB_finish(vsb));
+}
+
 void
 VPX_Send_Proxy(int fd, int version, const struct sess *sp)
 {
 	struct vsb *vsb, *vsb2;
-	const char *p1, *p2;
 	struct suckaddr *sac, *sas;
 	char ha[VTCP_ADDRBUFSIZE];
 	char pa[VTCP_PORTBUFSIZE];
@@ -627,17 +652,11 @@ VPX_Send_Proxy(int fd, int version, const struct sess *sp)
 	assert(proto == PF_INET6 || proto == PF_INET);
 
 	if (version == 1) {
-		VSB_bcat(vsb, vpx1_sig, sizeof(vpx1_sig));
-		p1 = SES_Get_String_Attr(sp, SA_CLIENT_IP);
-		AN(p1);
-		p2 = SES_Get_String_Attr(sp, SA_CLIENT_PORT);
-		AN(p2);
 		VTCP_name(sas, ha, sizeof ha, pa, sizeof pa);
-		if (proto == PF_INET6)
-			VSB_cat(vsb, " TCP6 ");
-		else if (proto == PF_INET)
-			VSB_cat(vsb, " TCP4 ");
-		VSB_printf(vsb, "%s %s %s %s\r\n", p1, ha, p2, pa);
+		vpx_format_proxy_v1(vsb, proto,
+		    SES_Get_String_Attr(sp, SA_CLIENT_IP),
+		    SES_Get_String_Attr(sp, SA_CLIENT_PORT),
+		    ha, pa);
 	} else if (version == 2) {
 		AZ(SES_Get_client_addr(sp, &sac));
 		AN(sac);
@@ -657,11 +676,12 @@ VPX_Send_Proxy(int fd, int version, const struct sess *sp)
 		vpx_enc_addr(vsb, proto, sas);
 		vpx_enc_port(vsb, sac);
 		vpx_enc_port(vsb, sas);
+		AZ(VSB_finish(vsb));
 	} else
 		WRONG("Wrong proxy version");
 
-	AZ(VSB_finish(vsb));
-	(void)VSB_tofile(fd, vsb);	// XXX: Error handling ?
+	(void)write(fd, VSB_data(vsb), VSB_len(vsb));
+
 	if (!DO_DEBUG(DBG_PROTOCOL)) {
 		VSB_delete(vsb);
 		return;


More information about the varnish-commit mailing list