Commit 3f077667 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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

parent d87c71cd
......@@ -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);
/*
......
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
......@@ -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));
......
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