[6.0] 24c586cec Add an optional default port argument to std.ip()
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed May 22 09:03:12 UTC 2019
commit 24c586cecac87173679a65b31af2148c114a4597
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Wed May 15 11:13:20 2019 +0200
Add an optional default port argument to std.ip()
And sync the documentation with the current behavior, part of which used
to be implicit.
Conflicts:
lib/libvmod_std/vmod.vcc
lib/libvmod_std/vmod_std_conversions.c
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index fc5ef3736..fa326bf52 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -164,16 +164,29 @@ Example
| ...
| }
-$Function IP ip(STRING s, IP fallback, BOOL resolve = 1)
+$Function IP ip(STRING s, IP fallback, BOOL resolve = 1, STRING p = "80")
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 false, getaddrinfo() is called using *AI_NUMERICHOST*
- to avoid network lookups. This makes "pure" IP strings cheaper to
- convert.
+ Converts the string *s* to the first IP number returned by the
+ system library function `getaddrinfo(3)`. If conversion fails,
+ *fallback* will be returned or VCL failure will happen.
+
+ The IP address includes a port number that can be found with
+ ``std.port()`` that defaults to 80. The default port can be set
+ to a different value with the *p* argument. It will be overriden
+ if *s* contains both an IP address and a port number or service
+ name.
+
+ When *s* contains both, the syntax is either ``address:port`` or
+ ``address port``. If the address is a numerical IPv6 address it
+ must be enclosed between brackets, for example ``[::1] 80`` or
+ ``[::1]:http``. The *fallback* may also contain both an address
+ and a port.
+
+ If *resolve* is false, `getaddrinfo(3)` is called using
+ ``AI_NUMERICHOST`` and ``AI_NUMERICSERV`` to avoid network lookups
+ depending on the system's `getaddrinfo(3)` or nsswitch configuration.
+ This makes "numerical" IP strings and services cheaper to convert.
Example
| if (std.ip(req.http.X-forwarded-for, "0.0.0.0") ~ my_acl) {
diff --git a/lib/libvmod_std/vmod_std_conversions.c b/lib/libvmod_std/vmod_std_conversions.c
index da8a84cd6..c89b79d03 100644
--- a/lib/libvmod_std/vmod_std_conversions.c
+++ b/lib/libvmod_std/vmod_std_conversions.c
@@ -78,7 +78,7 @@ vmod_integer(VRT_CTX, VCL_STRING p, VCL_INT i)
}
VCL_IP
-vmod_ip(VRT_CTX, VCL_STRING s, VCL_IP d, VCL_BOOL n)
+vmod_ip(VRT_CTX, VCL_STRING s, VCL_IP d, VCL_BOOL n, VCL_STRING default_port)
{
void *p;
VCL_IP retval;
@@ -94,8 +94,9 @@ vmod_ip(VRT_CTX, VCL_STRING s, VCL_IP d, VCL_BOOL n)
return (NULL);
}
- retval = VSS_ResolveFirst(p, s, "80", AF_UNSPEC, SOCK_STREAM,
- n ? 0 : AI_NUMERICHOST);
+ retval = VSS_ResolveFirst(p, s, default_port, AF_UNSPEC, SOCK_STREAM,
+ n ? 0 : AI_NUMERICHOST|AI_NUMERICSERV);
+
if (retval != NULL)
return (retval);
More information about the varnish-commit
mailing list