Commit 58324619 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4778 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 52573b54
......@@ -447,7 +447,7 @@ void
mgt_vcc_init(void)
{
VCC_InitCompile(default_vcl);
VCC_InitCompile(default_vcl, L_arg);
AZ(atexit(mgt_vcc_atexit));
}
......
......@@ -469,8 +469,6 @@ main(int argc, char * const *argv)
VTAILQ_INIT(&heritage.socks);
mgt_vcc_init();
MCF_ParamInit(cli);
if (sizeof(void *) < 8) {
......@@ -591,6 +589,8 @@ main(int argc, char * const *argv)
argc -= optind;
argv += optind;
mgt_vcc_init();
if (L_arg) {
/* Learner mode */
if (!s_arg_given)
......
......@@ -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);
......@@ -393,7 +393,9 @@ vcc_ParseHostDef(struct tokenlist *tl, int serial, const char *vgcname)
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_ParseHostDef(struct tokenlist *tl, int serial, const char *vgcname)
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 @@ vcc_ParseHostDef(struct tokenlist *tl, int serial, const char *vgcname)
}
/* 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,
......
......@@ -86,6 +86,8 @@ struct method method_tab[] = {
static const char *vcc_default_vcl_b, *vcc_default_vcl_e;
unsigned Learn_mode = 0;
/*--------------------------------------------------------------------*/
static void
......@@ -673,9 +675,10 @@ VCC_Return_Name(unsigned method)
*/
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);
......
......@@ -163,6 +163,7 @@ void vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs);
/* vcc_compile.c */
extern struct method method_tab[];
extern unsigned Learn_mode;
/*
* H -> Header, before the C code
* C -> C-code
......
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