]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: http: accept IPv6 values with (s)hdr_ip acl
authorCyril Bonté <cyril.bonte@free.fr>
Wed, 24 Oct 2012 22:01:06 +0000 (00:01 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 25 Oct 2012 12:41:33 +0000 (14:41 +0200)
Commit ceb4ac9c states that IPv6 values are accepted by "hdr_ip" acl,
but the code didn't allow it. This patch provides the ability to accept IPv6
values.

src/proto_http.c

index 9cdf3be2beec788d0ec3d51bff3a2a2a21552a4d..62b7ca2d805fd2e00160e465a7bff1348a08a8c6 100644 (file)
@@ -8077,9 +8077,9 @@ smp_fetch_hdr_val(struct proxy *px, struct session *l4, void *l7, unsigned int o
        return ret;
 }
 
-/* Fetch an HTTP header's integer value. The integer value is returned. It
- * takes a mandatory argument of type string and an optional one of type int
- * to designate a specific occurrence. It returns an IPv4 address.
+/* Fetch an HTTP header's IP value. takes a mandatory argument of type string
+ * and an optional one of type int to designate a specific occurrence.
+ * It returns an IPv4 or IPv6 address.
  */
 static int
 smp_fetch_hdr_ip(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
@@ -8088,9 +8088,21 @@ smp_fetch_hdr_ip(struct proxy *px, struct session *l4, void *l7, unsigned int op
        int ret;
 
        while ((ret = smp_fetch_hdr(px, l4, l7, opt, args, smp)) > 0) {
-               smp->type = SMP_T_IPV4;
-               if (url2ipv4((char *)smp->data.str.str, &smp->data.ipv4))
+               if (url2ipv4((char *)smp->data.str.str, &smp->data.ipv4)) {
+                       smp->type = SMP_T_IPV4;
                        break;
+               } else {
+                       struct chunk *temp = sample_get_trash_chunk();
+                       if (smp->data.str.len < temp->size - 1) {
+                               memcpy(temp->str, smp->data.str.str, smp->data.str.len);
+                               temp->str[smp->data.str.len] = '\0';
+                               if (inet_pton(AF_INET6, temp->str, &smp->data.ipv6)) {
+                                       smp->type = SMP_T_IPV6;
+                                       break;
+                               }
+                       }
+               }
+
                /* if the header doesn't match an IP address, fetch next one */
                if (!(smp->flags & SMP_F_NOT_LAST))
                        return 0;