### Description When Kamailio listening IP address is assigned to a secondary network interface and this card does not use for the default route, then at the L3-network level selected wrong IP address and in the "Recrod-Route" and "Via" headers used correct Kamailio IP.
For example in the attached file, frame 5 and fragments in frames 3,4. [invite-from-wrong-ip.pcap.gz](https://github.com/kamailio/kamailio/files/11781289/invite-from-wrong-ip.pca...)

#### Reproduction Our use case. 1. create a new virtual machine with a random IP address in the AWS cloud; 2. create a new network interface card with a static IP address; 3. attach a new network interface to a virtual machine, in Linux should be configured only one default route via the first network interface with a dynamic IP address; 4. start Kamailio daemon with configured listening TCP/socket with the IP address from the secondary IP card. 5. make a call via Kamailio.
I don't think this has to do anything with kamailio source code. It is about IP routing rules in the OS/kernel.
If the sip headers have the expected addresses based on listen socket, then kamailio selected what it should.
As noted on other issues here and mailing list discussions, for tcp is not really guaranteed that the source address of a tcp connection can be enforced, ultimately is the kernel/os stack making the decision.
If you want to discuss more, probably sr-users mailing list is more appropriate. If it results in discovering some code issue, then an issue can be created and it can be patched.
Closed #3486 as completed.
The network source address is important because the Kamailio address is whitelisted in the ACL. For me easier to manage this at the socket level, than manage it on the network OS routing rules.
We now working pull request for this issue. So we will make a new attempt to discuss via PR.
As a hotfix we used options ``` tcp_source_ipv4 = IPv4 address tcp_source_ipv6 = IPv6 address ``` https://www.kamailio.org/wiki/cookbooks/5.4.x/core#tcp_source_ipv4_tcp_sourc...
This works if all Kamailio sockets are bound to one IP. To get it working for multiple IPs we try to make such a change ```diff diff --git a/src/main.c b/src/main.c index 4ee5afe9d0..3670a8e826 100644 --- a/src/main.c +++ b/src/main.c @@ -1600,6 +1601,7 @@ int main_loop(void) (sendipv6_tcp->flags&(SI_IS_LO|SI_IS_MCAST))) && (si->address.af==AF_INET6)) sendipv6_tcp=si; + tcp_set_src_addr(&si->address); } /* the number of sockets does not matter */ cfg_register_child(tcp_children_no + 1 /* tcp main */);