]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: backend: do not use the source port when hashing clientip
authorWilly Tarreau <w@1wt.eu>
Wed, 9 Apr 2025 08:57:54 +0000 (10:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 9 Apr 2025 09:05:22 +0000 (11:05 +0200)
commit7b6df86a834883f27f6f7d18d0caa8a6ea128c14
tree6fefd7876f9d6e3b4044b26151a838d7d9f1b741
parentafd5f5d671d52f2a5a1fb9df9d05bf29f90859b0
BUG/MINOR: backend: do not use the source port when hashing clientip

The server's "usesrc" keyword supports among other options "client"
and "clientip". The former means we bind to the client's IP and port
to connect to the server, while the latter means we bind to its IP
only. It's done in two steps, first alloc_bind_address() retrieves
the IP address and port, and second, tcp_connect_server() decides
to either bind to the IP only or IP+port.

The problem comes with idle connection pools, which hash all the
parameters: the hash is calculated before (and ideally withouy) calling
tcp_connect_server(), and it considers the whole struct sockaddr_storage
for the hash, except that both client and clientip entirely fill it with
the client's address. This means that both client and clientip make use
of the source port in the hash calculation, making idle connections
almost not reusable when using "usesrc clientip" while they should for
clients coming from the same source. A work-around is to force the
source port to zero using "tcp-request session set-src-port int(0)" but
it's ugly.

Let's fix this by properly zeroing the port for AF_INET/AF_INET6 addresses.

This can be backported to 2.4. Thanks to Sebastien Gross for providing a
reproducer for this problem.
src/backend.c