r4778 - in trunk/varnish-cache: bin/varnishd include lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Thu May 6 12:06:07 CEST 2010


Author: phk
Date: 2010-05-06 12:06:06 +0200 (Thu, 06 May 2010)
New Revision: 4778

Modified:
   trunk/varnish-cache/bin/varnishd/mgt_vcc.c
   trunk/varnish-cache/bin/varnishd/varnishd.c
   trunk/varnish-cache/include/libvcl.h
   trunk/varnish-cache/lib/libvcl/vcc_backend.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
Log:
Tell the VCC if we are in -L(earn) mode.

In Learn mode, a backend port can be specified as

	backend fs {
		.host = "127.0.0.1";
		.port = Learn(2);
	}

which complements the varnishtest server::-listen directive:

	server s1 -listen 2 {
		rxreq
		txresp -hdr "Foo: bar" -body "Hello World!"
	} -start -wait

Obviously, the 127.0.0.1 is mandatory for this to work.


Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2010-05-06 09:39:23 UTC (rev 4777)
+++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2010-05-06 10:06:06 UTC (rev 4778)
@@ -447,7 +447,7 @@
 mgt_vcc_init(void)
 {
 
-	VCC_InitCompile(default_vcl);
+	VCC_InitCompile(default_vcl, L_arg);
 	AZ(atexit(mgt_vcc_atexit));
 }
 

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2010-05-06 09:39:23 UTC (rev 4777)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2010-05-06 10:06:06 UTC (rev 4778)
@@ -469,8 +469,6 @@
 
 	VTAILQ_INIT(&heritage.socks);
 
-	mgt_vcc_init();
-
 	MCF_ParamInit(cli);
 
 	if (sizeof(void *) < 8) {
@@ -591,6 +589,8 @@
 	argc -= optind;
 	argv += optind;
 
+	mgt_vcc_init();
+
 	if (L_arg) {
 		/* Learner mode */
 		if (!s_arg_given)

Modified: trunk/varnish-cache/include/libvcl.h
===================================================================
--- trunk/varnish-cache/include/libvcl.h	2010-05-06 09:39:23 UTC (rev 4777)
+++ trunk/varnish-cache/include/libvcl.h	2010-05-06 10:06:06 UTC (rev 4778)
@@ -30,6 +30,6 @@
  */
 
 char *VCC_Compile(struct vsb *sb, const char *b, const char *e);
-void VCC_InitCompile(const char *default_vcl);
+void VCC_InitCompile(const char *default_vcl, unsigned L_arg);
 const char *VCC_Return_Name(unsigned action);
 

Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_backend.c	2010-05-06 09:39:23 UTC (rev 4777)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c	2010-05-06 10:06:06 UTC (rev 4778)
@@ -393,7 +393,9 @@
 	struct fld_spec *fs;
 	struct vsb *vsb;
 	unsigned u;
+	unsigned tL_port = 0;
 	double t;
+	char tmpbuf[20];
 
 	Fh(tl, 1, "\n#define VGC_backend_%s %d\n", vgcname, tl->ndirector);
 
@@ -447,10 +449,39 @@
 			vcc_NextToken(tl);
 			SkipToken(tl, ';');
 		} else if (vcc_IdIs(t_field, "port")) {
-			ExpectErr(tl, CSTR);
-			assert(tl->t->dec != NULL);
-			t_port = tl->t;
-			vcc_NextToken(tl);
+			if (Learn_mode) {
+				ExpectErr(tl, ID);
+				if (!vcc_IdIs(tl->t, "Learn")) {
+					vsb_printf(tl->sb,
+					    "Expected \"Learn\"\n");
+					vcc_ErrToken(tl, tl->t);
+					vcc_ErrWhere(tl, tl->t);
+					return;
+				}
+				vcc_NextToken(tl);
+
+				ExpectErr(tl, '(');
+				vcc_NextToken(tl);
+
+				ExpectErr(tl, CNUM);
+				t_port = tl->t;
+				tL_port = vcc_UintVal(tl);
+				if (tL_port > 9) {
+					vsb_printf(tl->sb,
+					    "Learn port > 9\n");
+					vcc_ErrToken(tl, t_port);
+					vcc_ErrWhere(tl, t_port);
+					return;
+				}
+
+				ExpectErr(tl, ')');
+				vcc_NextToken(tl);
+			} else {
+				ExpectErr(tl, CSTR);
+				assert(tl->t->dec != NULL);
+				t_port = tl->t;
+				vcc_NextToken(tl);
+			}
 			SkipToken(tl, ';');
 		} else if (vcc_IdIs(t_field, "host_header")) {
 			ExpectErr(tl, CSTR);
@@ -519,7 +550,11 @@
 	}
 
 	/* Check that the portname makes sense */
-	if (t_port != NULL) {
+	if (Learn_mode && t_port != NULL && t_port->tok == CNUM) {
+		assert(tL_port);
+		bprintf(tmpbuf, "%u", Learn_mode + 10 + tL_port);
+		Emit_Sockaddr(tl, t_host, tmpbuf);
+	} else if (t_port != NULL) {
 		ep = CheckHostPort("127.0.0.1", t_port->dec);
 		if (ep != NULL) {
 			vsb_printf(tl->sb,

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c	2010-05-06 09:39:23 UTC (rev 4777)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c	2010-05-06 10:06:06 UTC (rev 4778)
@@ -86,6 +86,8 @@
 
 static const char *vcc_default_vcl_b, *vcc_default_vcl_e;
 
+unsigned Learn_mode = 0;
+
 /*--------------------------------------------------------------------*/
 
 static void
@@ -673,9 +675,10 @@
  */
 
 void
-VCC_InitCompile(const char *default_vcl)
+VCC_InitCompile(const char *default_vcl, unsigned L_arg)
 {
 
+	Learn_mode = L_arg;
 	vcc_default_vcl_b = default_vcl;
 	vcc_default_vcl_e = strchr(default_vcl, '\0');
 	assert(vcc_default_vcl_e != NULL);

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-05-06 09:39:23 UTC (rev 4777)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-05-06 10:06:06 UTC (rev 4778)
@@ -163,6 +163,7 @@
 
 /* vcc_compile.c */
 extern struct method method_tab[];
+extern unsigned Learn_mode;
 /*
  * H -> Header, before the C code
  * C -> C-code




More information about the varnish-commit mailing list