Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
ce0ccf57
Commit
ce0ccf57
authored
Jan 31, 2018
by
Guillaume Quintard
Committed by
guillaume quintard
Feb 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce optional resolve arg to std.ip
parent
918c848d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
2 deletions
+13
-2
m00011.vtc
bin/varnishtest/tests/m00011.vtc
+4
-0
vmod.vcc
lib/libvmod_std/vmod.vcc
+6
-1
vmod_std_conversions.c
lib/libvmod_std/vmod_std_conversions.c
+3
-1
No files found.
bin/varnishtest/tests/m00011.vtc
View file @
ce0ccf57
...
...
@@ -15,6 +15,8 @@ varnish v1 -vcl+backend {
set resp.http.foo3 = std.ip("1.2.3.5", "127.0.0.3");
set resp.http.foo4 = std.ip("2001:db8::", "[::1]");
set resp.http.foo5 = std.ip("2001::db8::", "[::1]");
set resp.http.foo6 = std.ip("localhost", "0.0.0.0", resolve = false);
set resp.http.foo7 = std.ip("1.2.3.4", "0.0.0.0", resolve = false);
}
} -start
...
...
@@ -29,4 +31,6 @@ client c1 {
expect resp.http.foo3 == "1.2.3.5"
expect resp.http.foo4 == "2001:db8::"
expect resp.http.foo5 == "::1"
expect resp.http.foo6 == "0.0.0.0"
expect resp.http.foo7 == "1.2.3.4"
} -run
lib/libvmod_std/vmod.vcc
View file @
ce0ccf57
...
...
@@ -165,12 +165,17 @@ Example
| ...
| }
$Function IP ip(STRING s, IP fallback)
$Function IP ip(STRING s, IP fallback
, BOOL resolve = 1
)
Description
Converts the string *s* to the first IP number returned by
the system library function getaddrinfo(3). If conversion
fails, *fallback* will be returned.
If *resolve* is true, getaddrinfo() is called using *AI_NUMERICHOST*
to avoid network lookups. This makes "pure" IP strings cheaper to
convert.
Example
| if (std.ip(req.http.X-forwarded-for, "0.0.0.0") ~ my_acl) {
| ...
...
...
lib/libvmod_std/vmod_std_conversions.c
View file @
ce0ccf57
...
...
@@ -77,7 +77,7 @@ vmod_integer(VRT_CTX, VCL_STRING p, VCL_INT i)
}
VCL_IP
vmod_ip
(
VRT_CTX
,
VCL_STRING
s
,
VCL_IP
d
)
vmod_ip
(
VRT_CTX
,
VCL_STRING
s
,
VCL_IP
d
,
VCL_BOOL
n
)
{
struct
addrinfo
hints
,
*
res0
=
NULL
;
const
struct
addrinfo
*
res
;
...
...
@@ -101,6 +101,8 @@ vmod_ip(VRT_CTX, VCL_STRING s, VCL_IP d)
memset
(
&
hints
,
0
,
sizeof
(
hints
));
hints
.
ai_family
=
PF_UNSPEC
;
hints
.
ai_socktype
=
SOCK_STREAM
;
if
(
!
n
)
hints
.
ai_flags
|=
AI_NUMERICHOST
;
error
=
getaddrinfo
(
s
,
"80"
,
&
hints
,
&
res0
);
if
(
!
error
)
{
for
(
res
=
res0
;
res
!=
NULL
;
res
=
res
->
ai_next
)
{
...
...
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