Commit 467c3590 authored by Geoff Simmons's avatar Geoff Simmons

the hosts.policy() method may not be called in vcl_init

parent 9621d9a8
Pipeline #109 skipped
......@@ -379,6 +379,20 @@ client c1 {
} -run
# Usage tests
varnish v1 -errvcl {h.policy() may not be called in vcl_init} {
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();
h.add("example.com", "p");
if (h.policy("example.com", "/foo") != 1) {
return(fail);
}
}
}
varnish v1 -vcl {
import hoailona from "${vmod_topbuild}/src/.libs/libvmod_hoailona.so";
backend b { .host = "${bad_ip}"; }
......
......@@ -53,11 +53,6 @@
#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) \
ERR((ctx), m " is illegal in vcl_init() and vcl_fini()")
struct host {
unsigned magic;
#define VMOD_HOAILONA_HOST_MAGIC 0x731af58f
......@@ -483,6 +478,11 @@ vmod_hosts_policy(VRT_CTX, struct vmod_hoailona_hosts *hosts,
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
CHECK_OBJ_NOTNULL(hosts, VMOD_HOAILONA_HOSTS_MAGIC);
AN(priv_task);
if (INIT(ctx)) {
VERR(ctx, "%s.policy() may not be called in vcl_init",
hosts->vcl_name);
return -2;
}
if (hostname == NULL || hostname[0] == '\0') {
VERR(ctx, "host is empty in %s.policy()", hosts->vcl_name);
return -2;
......
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