summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOto Valek <oto@valek.net>2023-02-24 21:39:56 +0100
committerWilly Tarreau <w@1wt.eu>2023-03-01 14:09:46 +0100
commitd1773e6881caba229575fa7e0525846697dd4e21 (patch)
treeac71bd049d86f14c7ca08b78db7473f148db8a4d
parentd48bfb6983a3d28183b068a4f8975c1c5cd05978 (diff)
downloadhaproxy-d1773e6881caba229575fa7e0525846697dd4e21.tar.gz
BUG/MINOR: http-fetch: recognize IPv6 addresses in square brackets in req.hdr_ip()
If an IPv6 address is enclosed in square brackets [], trim them before calling inet_pton(). This is to comply with RFC7239 6.1 and RFC3986 3.2.2.
-rw-r--r--src/http_fetch.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/http_fetch.c b/src/http_fetch.c
index 8c01e0343..f855a675f 100644
--- a/src/http_fetch.c
+++ b/src/http_fetch.c
@@ -1024,7 +1024,15 @@ static int smp_fetch_hdr_ip(const struct arg *args, struct sample *smp, const ch
/* IPv4 address suffixed with ':' followed by a valid port number */
smp->data.type = SMP_T_IPV4;
break;
+ } else if (temp->area[0] == '[' && temp->area[smp->data.u.str.data-1] == ']') {
+ /* IPv6 address enclosed in square brackets */
+ temp->area[smp->data.u.str.data-1] = '\0';
+ if (inet_pton(AF_INET6, temp->area+1, &smp->data.u.ipv6)) {
+ smp->data.type = SMP_T_IPV6;
+ break;
+ }
} else if (inet_pton(AF_INET6, temp->area, &smp->data.u.ipv6)) {
+ /* plain IPv6 address */
smp->data.type = SMP_T_IPV6;
break;
}