OPTIM: http_ext: avoid useless copy in http_7239_extract_{ipv4,ipv6}
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 18 Mar 2024 14:18:08 +0000 (15:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 25 Mar 2024 15:24:15 +0000 (16:24 +0100)
commitdb1cd8f8819b59f599b6e5f407816db52c8e7ae6
tree782f6c6f5fdfa346bef608a657b5fb6a0fb55e74
parent3de1acfb2350d758df7b4c3bfb81fa6113013ddd
OPTIM: http_ext: avoid useless copy in http_7239_extract_{ipv4,ipv6}

In http_7239_extract_{ipv4,ipv6}, we declare a local buffer in order to
use inet_pton() since it requires a valid destination argument (cannot be
NULL). Then, if the caller provided <ip> argument, we copy inet_pton()
result (from local buffer to <ip>).

In fact when the caller provides <ip>, we may directly use <ip> as
inet_pton() dst argument to avoid an useless copy. Thus the local buffer
is only relevant when the user doesn't provide <ip>.

While at it, let's add a missing testcase for the rfc7239_n2nn converter
(to check that http_7239_extract_ipv4() with <ip> provided works properly)

This could be backported in 2.8 with b2bb925 ("MINOR: proxy/http_ext:
introduce proxy forwarded option")
reg-tests/http-rules/forwarded-header-7239.vtc
src/http_ext.c