Hi Federico,
I was facing the same issues when I was playing with the proxy protocol some time ago.
As per my understanding the way how proxy protocol(PP) is implemented in Kamailio is outlined in the de-facto standard doc:
https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt"
The PROXY protocol's goal is to fill the server's internal structures with the
information collected by the proxy that the server would have been able to get
by itself if the client was connecting directly to the server instead of via a
proxy. The information carried by the protocol are the ones the server would
get using getsockname() and getpeername() :
- address family (AF_INET for IPv4, AF_INET6 for IPv6, AF_UNIX)
- socket protocol (SOCK_STREAM for TCP, SOCK_DGRAM for UDP)
- layer 3 source and destination addresses
- layer 4 source and destination ports if any
"
So that internally Kamailio will have info of Client source_ip:source_port/LB_external_IP:LB_external_port
You can confirm that by executing core.tcp_list command.
For a call initiated by a client behind LB with proxy protocol, responses will re-use existing TCP connection and will reach the client. But for example if the call will be terminated from the callee side, (i.e new transaction) Kamailio will fail to find existing TCP connection since it does not know nothing about it and will try to open a new one, which, in turn will fail either because of LB reject - if so_useport is disabled, or if so_reuseport=yes because of the fact that in the OS there is already opened TCP connection with the same tuple (ie. between LB and Kamailio host)
So the way to use proxy protocol in Kamailio is DSR (direct server return) scenarios.