[master] e8a296c Add a requirement for VCL programs to declare their version like this:
Poul-Henning Kamp
phk at varnish-cache.org
Mon Sep 23 22:24:33 CEST 2013
commit e8a296ca43b3346550e9f35c267c38d7ee265843
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Sep 23 20:21:49 2013 +0000
Add a requirement for VCL programs to declare their version like this:
vcl 4.0;
The first token, after 'include' expansion, has to be such a declaration,
which means that unless the first token in it is 'include' the file
you give to -f, vcl.load or vcl.inline, must start out with "vcl 4.0;"
The point about this is user-support and being able to offer better
backwards compatibility in the future.
diff --git a/bin/varnishd/default.vcl b/bin/varnishd/default.vcl
index db64791..5240164 100644
--- a/bin/varnishd/default.vcl
+++ b/bin/varnishd/default.vcl
@@ -39,6 +39,8 @@
* -b argument.
*/
+vcl 4.0;
+
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index 6701436..4df7b0f 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -402,6 +402,7 @@ mgt_vcc_default(const char *b_arg, const char *f_arg, char *vcl, int C_flag)
* XXX: again: we should check it here in the "trivial" case.
*/
bprintf(buf,
+ "vcl 4.0;\n"
"backend default {\n"
" .host = \"%s\";\n"
"}\n", b_arg);
diff --git a/bin/varnishtest/tests/b00014.vtc b/bin/varnishtest/tests/b00014.vtc
index b68c79e..8c5822e 100644
--- a/bin/varnishtest/tests/b00014.vtc
+++ b/bin/varnishtest/tests/b00014.vtc
@@ -10,7 +10,7 @@ server s1 {
txresp -body "bar"
} -start
-shell "echo 'backend foo { .host = \"${s1_addr}\"; .port = \"${s1_port}\"; }' > ${tmpdir}/_b00014.vcl"
+shell "echo 'vcl 4.0; backend foo { .host = \"${s1_addr}\"; .port = \"${s1_port}\"; }' > ${tmpdir}/_b00014.vcl"
varnish v1 -arg "-f ${tmpdir}/_b00014.vcl" -start
client c1 {
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index ff8cfa2..9e9733f 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -644,7 +644,7 @@ varnish_vcl(struct varnish *v, const char *vcl, enum VCLI_status_e expect, char
vsb = VSB_new_auto();
AN(vsb);
- VSB_printf(vsb, "vcl.inline vcl%d << %s\n%s\n%s\n",
+ VSB_printf(vsb, "vcl.inline vcl%d << %s\nvcl 4.0;\n%s\n%s\n",
++v->vcl_nbr, NONSENSE, vcl, NONSENSE);
AZ(VSB_finish(vsb));
@@ -688,7 +688,10 @@ varnish_vclbackend(struct varnish *v, const char *vcl)
vsb2 = VSB_new_auto();
AN(vsb2);
+ VSB_printf(vsb2, "vcl 4.0;\n");
+
cmd_server_genvcl(vsb2);
+
AZ(VSB_finish(vsb2));
VSB_printf(vsb, "vcl.inline vcl%d << %s\n%s\n%s\n%s\n",
diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c
index fa8a7d7..433d848 100644
--- a/lib/libvcc/vcc_acl.c
+++ b/lib/libvcc/vcc_acl.c
@@ -462,7 +462,7 @@ vcc_Acl_Hack(struct vcc *tl, char *b)
}
void
-vcc_Acl(struct vcc *tl)
+vcc_ParseAcl(struct vcc *tl)
{
struct token *an;
int i;
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index b0983cc..cd72db9 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -219,7 +219,7 @@ struct method {
/* vcc_acl.c */
-void vcc_Acl(struct vcc *tl);
+void vcc_ParseAcl(struct vcc *tl);
void vcc_Acl_Hack(struct vcc *tl, char *b);
/* vcc_action.c */
@@ -265,6 +265,7 @@ char *TlDupTok(struct vcc *tl, const struct token *tok);
void EncString(struct vsb *sb, const char *b, const char *e, int mode);
/* vcc_expr.c */
+double vcc_DoubleVal(struct vcc *tl);
void vcc_Duration(struct vcc *tl, double *);
unsigned vcc_UintVal(struct vcc *tl);
void vcc_Expr(struct vcc *tl, enum var_type typ);
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 164a8d6..33a59b1 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -141,7 +141,7 @@ vcc_NumVal(struct vcc *tl, double *d, int *frac)
vcc_NextToken(tl);
}
-static double
+double
vcc_DoubleVal(struct vcc *tl)
{
double d;
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index ab562f5..9a7c56a 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -206,7 +206,7 @@ vcc_Compound(struct vcc *tl)
*/
static void
-vcc_Function(struct vcc *tl)
+vcc_ParseFunction(struct vcc *tl)
{
int m, i;
@@ -277,18 +277,43 @@ vcc_Function(struct vcc *tl)
*/
static void
-vcc_Director(struct vcc *tl)
+vcc_ParseDirector(struct vcc *tl)
{
VSB_printf(tl->sb, "\ndirectors are now in directors VMOD.\n");
vcc_ErrWhere(tl, tl->t);
}
/*--------------------------------------------------------------------
+ */
+
+static void
+vcc_ParseVcl(struct vcc *tl)
+{
+ double ver;
+ struct token *tok;
+
+ assert(vcc_IdIs(tl->t, "vcl"));
+ vcc_NextToken(tl);
+ tok = tl->t;
+ ver = vcc_DoubleVal(tl);
+ ERRCHK(tl);
+ if (ver != 4.0) {
+ VSB_printf(tl->sb, "VCL version %.1f not supported.\n", ver);
+ vcc_ErrWhere(tl, tok);
+ ERRCHK(tl);
+ }
+ ExpectErr(tl, ';');
+ vcc_NextToken(tl);
+}
+
+/*--------------------------------------------------------------------
* Top level of parser, recognize:
* Inline C-code
* ACL definitions
* Function definitions
- * Backend & Director definitions
+ * Backend definitions
+ * VMOD import directives
+ * VCL version declarations
* End of input
*/
@@ -298,12 +323,13 @@ static struct toplev {
const char *name;
parse_f *func;
} toplev[] = {
- { "acl", vcc_Acl },
- { "sub", vcc_Function },
+ { "acl", vcc_ParseAcl },
+ { "sub", vcc_ParseFunction },
{ "backend", vcc_ParseBackend },
- { "director", vcc_Director },
+ { "director", vcc_ParseDirector },
{ "probe", vcc_ParseProbe },
{ "import", vcc_ParseImport },
+ { "vcl", vcc_ParseVcl },
{ NULL, NULL }
};
@@ -312,6 +338,18 @@ vcc_Parse(struct vcc *tl)
{
struct toplev *tp;
+ if (!vcc_IdIs(tl->t, "vcl")) {
+ VSB_printf(tl->sb,
+ "VCL version declaration missing\n"
+ "Update your VCL to Version 4 syntax, and add\n"
+ "\tvcl 4.0;\n"
+ "on the first line the VCL files.\n"
+ );
+ vcc_ErrWhere(tl, tl->t);
+ ERRCHK(tl);
+ }
+ vcc_ParseVcl(tl);
+ ERRCHK(tl);
while (tl->t->tok != EOI) {
ERRCHK(tl);
switch (tl->t->tok) {
More information about the varnish-commit
mailing list