Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-hoailona
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-hoailona
Commits
0c54b6bf
Commit
0c54b6bf
authored
Apr 13, 2017
by
Nils Goroll
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Match hosts in the order in which policies are added
parent
4ddbfe66
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
18 deletions
+37
-18
explain.vtc
src/tests/explain.vtc
+29
-10
vmod_hoailona.c
src/vmod_hoailona.c
+8
-8
No files found.
src/tests/explain.vtc
View file @
0c54b6bf
...
...
@@ -12,12 +12,23 @@ varnish v1 -vcl {
new h = hoailona.hosts();
h.add("example.com", "p1");
h.add("example.org", "p2");
// specific entry after wildcard - never matched
h.add("*.example.com", "p1", "/foo/...");
h.add("*.example.org", "p2", "/bar/...");
h.add("foo.example.org", "p2", "...");
h.add("example.net", "p1", description="net");
h.add("example.edu", "p2", description="edu");
h.add("*.example.net", "p1", "/baz/...", description="sub net");
h.add("*.example.edu", "p2", "/baz/...", description="sub edu");
// specific entry before wildcard has precendence,
// but lookup stops at the first host match
h.add("foo.example.net", "p1", "/bar/...",
description="sub net");
h.add("*.example.net", "p1", "/baz/...",
description="wild sub net");
h.add("*.example.edu", "p2", "/baz/...",
description="wild sub edu");
}
sub vcl_recv {
...
...
@@ -37,12 +48,16 @@ varnish v1 -vcl {
set resp.http.e5 = h.explain();
set resp.http.p6 = h.policy("example.edu", "/foo/bar");
set resp.http.e6 = h.explain();
set resp.http.p7 = h.policy("foo.example.net", "/ba
z
/quux");
set resp.http.p7 = h.policy("foo.example.net", "/ba
r
/quux");
set resp.http.e7 = h.explain();
set resp.http.p8 = h.policy("foo.example.
edu
", "/baz/quux");
set resp.http.p8 = h.policy("foo.example.
net
", "/baz/quux");
set resp.http.e8 = h.explain();
set resp.http.p9 = h.policy("
foo.example.com
", "/baz/quux");
set resp.http.p9 = h.policy("
bar.example.net
", "/baz/quux");
set resp.http.e9 = h.explain();
set resp.http.pA = h.policy("foo.example.edu", "/baz/quux");
set resp.http.eA = h.explain();
set resp.http.pB = h.policy("foo.example.com", "/baz/quux");
set resp.http.eB = h.explain();
}
} -start
...
...
@@ -63,11 +78,15 @@ client c1 {
expect resp.http.p6 == "1"
expect resp.http.e6 == "Matched host example.edu (edu) for global policy p2 (open)"
expect resp.http.p7 == "2"
expect resp.http.e7 == "Matched host *.example.net and pattern /baz/... (sub net) for policy p1"
expect resp.http.p8 == "1"
expect resp.http.e8 == "Matched host *.example.edu and pattern /baz/... (sub edu) for policy p2 (open)"
expect resp.http.p9 == "-1"
expect resp.http.e9 == "No policy was matched"
expect resp.http.e7 == "Matched host foo.example.net and pattern /bar/... (sub net) for policy p1"
expect resp.http.p8 == "-1"
expect resp.http.e8 == "No policy was matched"
expect resp.http.p9 == "2"
expect resp.http.e9 == "Matched host *.example.net and pattern /baz/... (wild sub net) for policy p1"
expect resp.http.pA == "1"
expect resp.http.eA == "Matched host *.example.edu and pattern /baz/... (wild sub edu) for policy p2 (open)"
expect resp.http.pB == "-1"
expect resp.http.eB == "No policy was matched"
} -run
varnish v1 -errvcl {h.explain() may not be called in vcl_init} {
...
...
src/vmod_hoailona.c
View file @
0c54b6bf
...
...
@@ -56,14 +56,14 @@ struct host {
unsigned
magic
;
#define VMOD_HOAILONA_HOST_MAGIC 0x731af58f
struct
assign_tree
assignments
;
VS
LIST
_ENTRY
(
host
)
list
;
VS
TAILQ
_ENTRY
(
host
)
list
;
char
*
name
;
char
*
description
;
struct
vmod_hoailona_policy
*
policy
;
size_t
len
;
};
typedef
VS
LIST
_HEAD
(
hosthead
,
host
)
hosthead_t
;
typedef
VS
TAILQ
_HEAD
(
hosthead
,
host
)
hosthead_t
;
struct
vmod_hoailona_hosts
{
unsigned
magic
;
...
...
@@ -246,7 +246,7 @@ vmod_hosts__init(VRT_CTX, struct vmod_hoailona_hosts **hostsp,
hosts
->
vcl_name
=
strdup
(
vcl_name
);
AN
(
hosts
->
vcl_name
);
VS
LIST
_INIT
(
&
hosts
->
hosthead
);
VS
TAILQ
_INIT
(
&
hosts
->
hosthead
);
}
/*
...
...
@@ -265,7 +265,7 @@ vmod_hosts__fini(struct vmod_hoailona_hosts **hostsp)
CHECK_OBJ_NOTNULL
(
hosts
,
VMOD_HOAILONA_HOSTS_MAGIC
);
if
(
hosts
->
vcl_name
!=
NULL
)
free
(
hosts
->
vcl_name
);
host
=
VS
LIST
_FIRST
(
&
hosts
->
hosthead
);
host
=
VS
TAILQ
_FIRST
(
&
hosts
->
hosthead
);
while
(
host
!=
NULL
)
{
struct
assignment
*
a
;
struct
host
*
next_host
=
NULL
;
...
...
@@ -295,7 +295,7 @@ vmod_hosts__fini(struct vmod_hoailona_hosts **hostsp)
FREE_OBJ
(
a
);
a
=
next_ass
;
}
next_host
=
VS
LIST
_NEXT
(
host
,
list
);
next_host
=
VS
TAILQ
_NEXT
(
host
,
list
);
FREE_OBJ
(
host
);
host
=
next_host
;
}
...
...
@@ -396,7 +396,7 @@ vmod_hosts_add(VRT_CTX, struct vmod_hoailona_hosts *hosts,
return
;
}
VS
LIST
_FOREACH
(
host
,
&
hosts
->
hosthead
,
list
)
{
VS
TAILQ
_FOREACH
(
host
,
&
hosts
->
hosthead
,
list
)
{
CHECK_OBJ
(
host
,
VMOD_HOAILONA_HOST_MAGIC
);
if
(
strcmp
(
hostname
,
host
->
name
)
==
0
)
break
;
...
...
@@ -443,7 +443,7 @@ vmod_hosts_add(VRT_CTX, struct vmod_hoailona_hosts *hosts,
VRB_INIT
(
&
host
->
assignments
);
AZ
(
host
->
description
);
AZ
(
host
->
policy
);
VS
LIST_INSERT_HEAD
(
&
hosts
->
hosthead
,
host
,
list
);
VS
TAILQ_INSERT_TAIL
(
&
hosts
->
hosthead
,
host
,
list
);
}
if
(
path
==
NULL
)
{
...
...
@@ -519,7 +519,7 @@ vmod_hosts_policy(VRT_CTX, struct vmod_hoailona_hosts *hosts,
/* XXX optimize */
hostlen
=
strlen
(
hostname
);
VS
LIST
_FOREACH
(
h
,
&
hosts
->
hosthead
,
list
)
{
VS
TAILQ
_FOREACH
(
h
,
&
hosts
->
hosthead
,
list
)
{
const
char
*
q
,
*
hs
;
CHECK_OBJ
(
h
,
VMOD_HOAILONA_HOST_MAGIC
);
...
...
Nils Goroll
@slink
mentioned in commit
dcdcefcb
·
Apr 25, 2017
mentioned in commit
dcdcefcb
mentioned in commit dcdcefcb5bb4275e47382945f4f6adca295afff3
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment