Commit 9621d9a8 authored by Geoff Simmons's avatar Geoff Simmons

the hosts.add() method may only be called in vcl_init

parent 1a4d6532
Pipeline #108 skipped
......@@ -18,6 +18,31 @@ varnish v1 -vcl {
}
} -start
varnish v1 -vcl {
import hoailona from "${vmod_topbuild}/src/.libs/libvmod_hoailona.so";
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new p = hoailona.policy(OPEN, 1h);
new h = hoailona.hosts();
}
sub vcl_recv {
h.add("example.com", "p");
}
}
client c1 {
txreq
rxresp
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error "^vmod hoailona error: h.add.. may only be called in vcl_init$"
expect * = End
} -run
varnish v1 -errvcl {vmod hoailona error: host is empty in h.add()} {
import hoailona from "${vmod_topbuild}/src/.libs/libvmod_hoailona.so";
backend b { .host = "${bad_ip}"; }
......
......@@ -51,6 +51,8 @@
#define ERRNOMEM(ctx, msg) \
ERR((ctx), msg ", out of space")
#define INIT(ctx) (((ctx)->method & VCL_MET_INIT) != 0)
#define INIT_FINI(ctx) (((ctx)->method & (VCL_MET_INIT | VCL_MET_FINI)) != 0)
#define ILLEGAL(ctx, m) \
......@@ -322,7 +324,6 @@ valid_hostname(VRT_CTX, const char * restrict const hostname)
return 1;
}
/* XXX only legal in init */
VCL_VOID
vmod_hosts_add(VRT_CTX, struct vmod_hoailona_hosts *hosts,
struct vmod_priv *init_task, VCL_STRING hostname,
......@@ -341,6 +342,11 @@ vmod_hosts_add(VRT_CTX, struct vmod_hoailona_hosts *hosts,
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
CHECK_OBJ_NOTNULL(hosts, VMOD_HOAILONA_HOSTS_MAGIC);
AN(init_task);
if (!INIT(ctx)) {
VERR(ctx, "%s.add() may only be called in vcl_init",
hosts->vcl_name);
return;
}
if (hostname == NULL || hostname[0] == '\0') {
VERR(ctx, "host is empty in %s.add()", hosts->vcl_name);
return;
......
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