conf: Accept addresses enclosed by square brackets in port forwarding specifiers
Even though we don't use : as delimiter for the port, making square brackets unneeded, RFC 3986, section 3.2.2, mandates them for IPv6 literals. We want IPv6 addresses there, but some users might still specify them out of habit. Same for IPv4 addresses: RFC 3986 doesn't specify square brackets for IPv4 literals, but I had reports of users actually trying to use them (they're accepted by many tools). Allow square brackets for both IPv4 and IPv6 addresses, correct or not, they're harmless anyway. Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
6ff702f325
commit
4a333c88d7
1 changed files with 17 additions and 7 deletions
24
conf.c
24
conf.c
|
@ -209,14 +209,24 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ifname == buf + 1) /* Interface without address */
|
if (ifname == buf + 1) { /* Interface without address */
|
||||||
addr = NULL;
|
addr = NULL;
|
||||||
else if (inet_pton(AF_INET, buf, addr))
|
} else {
|
||||||
af = AF_INET;
|
p = buf;
|
||||||
else if (inet_pton(AF_INET6, buf, addr))
|
|
||||||
af = AF_INET6;
|
/* Allow square brackets for IPv4 too for convenience */
|
||||||
else
|
if (*p == '[' && p[strlen(p) - 1] == ']') {
|
||||||
goto bad;
|
p[strlen(p) - 1] = '\0';
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inet_pton(AF_INET, p, addr))
|
||||||
|
af = AF_INET;
|
||||||
|
else if (inet_pton(AF_INET6, p, addr))
|
||||||
|
af = AF_INET6;
|
||||||
|
else
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
spec = buf;
|
spec = buf;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue