[master] 3f077667d Teach Conn_pool to send preamble, vcc to configure it and test that it works.

Poul-Henning Kamp phk at FreeBSD.org
Fri Jan 29 21:51:12 UTC 2021


commit 3f077667d47338dcf1d593d6765b01151968072c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Jan 29 21:49:40 2021 +0000

    Teach Conn_pool to send preamble, vcc to configure it and test that it works.

diff --git a/bin/varnishd/cache/cache_conn_pool.c b/bin/varnishd/cache/cache_conn_pool.c
index 9b29217d8..23b8d4912 100644
--- a/bin/varnishd/cache/cache_conn_pool.c
+++ b/bin/varnishd/cache/cache_conn_pool.c
@@ -343,9 +343,20 @@ VCP_Open(struct conn_pool *cp, vtim_dur tmo, VCL_IP *ap, int *err)
 		return (-1);
 	}
 
+	*err = errno = 0;
 	r = cp->methods->open(cp, tmo, ap);
 
-	*err = errno;
+	if (r >= 0 && errno == 0 && cp->endpoint->preamble != NULL &&
+	     cp->endpoint->preamble->len > 0) {
+		if (write(r, cp->endpoint->preamble->blob,
+		    cp->endpoint->preamble->len) !=
+		    cp->endpoint->preamble->len) {
+			*err = errno;
+			closefd(&r);
+		}
+	} else {
+		*err = errno;
+	}
 
 	if (r >= 0)
 		return (r);
@@ -701,6 +712,10 @@ VCP_Ref(const struct vrt_endpoint *vep, const char *ident)
 			VSHA256_Update(cx, vep->ipv6, vsa_suckaddr_len);
 		}
 	}
+	if (vep->preamble != NULL && vep->preamble->len > 0) {
+		VSHA256_Update(cx, "PRE", 4); // include \0
+		VSHA256_Update(cx, vep->preamble->blob, vep->preamble->len);
+	}
 	VSHA256_Final(digest, cx);
 
 	/*
diff --git a/bin/varnishtest/tests/b00075.vtc b/bin/varnishtest/tests/b00075.vtc
new file mode 100644
index 000000000..bea1b6db2
--- /dev/null
+++ b/bin/varnishtest/tests/b00075.vtc
@@ -0,0 +1,27 @@
+varnishtest "Test backend preamble"
+
+server s1 {
+	rxreq
+	expect req.method == "POST"
+	expect req.url == "/preamble"
+	expect req.proto == "HTTP/7.3"
+	expect req.http.Header == "42"
+	rxreq
+	expect req.method == "GET"
+	expect req.url == "/"
+	expect req.proto == "HTTP/1.1"
+	txresp
+} -start
+
+varnish v1 -vcl {
+	backend s1 {
+		.host = "${s1_sock}";
+		.preamble = :UE9TVCAvcHJlYW1ibGUgSFRUUC83LjMKSGVhZGVyOiA0MgoKCg==: ;
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+} -run
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index 98a92c650..d61e973d9 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -339,6 +339,7 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname)
 	const struct token *t_path = NULL;
 	const struct token *t_hosthdr = NULL;
 	const struct token *t_did = NULL;
+	const struct token *t_preamble = NULL;
 	struct symbol *pb;
 	struct fld_spec *fs;
 	struct inifin *ifp;
@@ -382,6 +383,7 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname)
 	    "?probe",
 	    "?max_connections",
 	    "?proxy_header",
+	    "?preamble",
 	    NULL);
 
 	tl->fb = VSB_new_auto();
@@ -497,6 +499,11 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname)
 			vcc_ErrWhere(tl, tl->t);
 			VSB_destroy(&tl->fb);
 			return;
+		} else if (vcc_IdIs(t_field, "preamble")) {
+			ExpectErr(tl, CBLOB);
+			t_preamble = tl->t;
+			vcc_NextToken(tl);
+			SkipToken(tl, ';');
 		} else {
 			ErrInternal(tl);
 			VSB_destroy(&tl->fb);
@@ -534,6 +541,9 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname)
 		Emit_UDS_Path(tl, vsb1, t_path, "Backend path");
 	ERRCHK(tl);
 
+	if (t_preamble != NULL)
+		VSB_printf(vsb1, "\t.preamble = %s,\n", t_preamble->dec);
+
 	VSB_printf(vsb1, "};\n");
 	AZ(VSB_finish(vsb1));
 	Fh(tl, 0, "%s", VSB_data(vsb1));


More information about the varnish-commit mailing list