]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: sample: Add IPv6 support to the ipmask converter
authorTim Duesterhus <tim@bastelstu.be>
Thu, 25 Jan 2018 15:24:51 +0000 (16:24 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 25 Jan 2018 21:25:40 +0000 (22:25 +0100)
commit1478aa795eb7ec1e684de231e6501d29abe581c7
tree0ae52a49b60ac614c50e5d8800714484e177b8fd
parentb814da6c5c0fa0f51df861d467b007c51e08ac8f
MEDIUM: sample: Add IPv6 support to the ipmask converter

Add an optional second parameter to the ipmask converter that specifies
the number of bits to mask off IPv6 addresses.

If the second parameter is not given IPv6 addresses fail to mask (resulting
in an empty string), preserving backwards compatibility: Previously
a sample like `src,ipmask(24)` failed to give a result for IPv6 addresses.

This feature can be tested like this:

  defaults
   log global
   mode http
   option httplog
   option dontlognull
   timeout connect 5000
   timeout client  50000
   timeout server  50000

  frontend fe
   bind :::8080 v4v6

   # Masked IPv4 for IPv4, empty for IPv6 (with and without this commit)
   http-response set-header Test %[src,ipmask(24)]
   # Correctly masked IP addresses for both IPv4 and IPv6
   http-response set-header Test2 %[src,ipmask(24,ffff:ffff:ffff:ffff::)]
   # Correctly masked IP addresses for both IPv4 and IPv6
   http-response set-header Test3 %[src,ipmask(24,64)]

   default_backend be

  backend be
   server s example.com:80

Tested-By: Jarno Huuskonen <jarno.huuskonen@uef.fi>
doc/configuration.txt
src/sample.c