Hello,

i have an issue with my Kamailio 4.1.9 configuration.

This configuration is multi-homed, we have two network interfaces, one on a private network and on the public Internet. Kamailio is configured to listen on port 5060 and 5066 on both interfaces. We register two users Alice and Bob on the  public Internet using port 5066.  Both users are behind a NAT and we capture the SIP exchange on the proxy server.

We have set the parameter mhomed=1

When Alice calls Bob, we have

Alice			Proxy				Bob
src=5063		dst=5066
INVITE ------------------>

                        src=5066
                        ------  INVITE ---------------> dst=5060

                        dst=5066  
                        <------- 200 OK -------------- src=5060


dst=5063 
<------- 200 OK --------- src=5066

src=5063		dst=5066
-------- ACK ----------->

                        src=5060      (blocked by NAT)
                        ------  ACK-----x            dst=5060


The ACK packet gets relayed with the wrong source port. Then the NAT rejects the packet and the call cannot be established.

For some reason, when Bob calls Alice, the call is correctly established. Could it be because Bob happend to use 5060 as local port?

Also, if we set nhomed=0 it works BUT we are not sure that multi homed is handled correctly.

I was wondering if you have encounter this issue before?

I have investigated the code for selection socket and what is the logic of this selection ?

How does kamailo knows that it should choose 5066 as src port if the user is registered using port 5066 instead of 5066?

Thank you for your time.

Thomas