<p>Let me rephrase, Kamailio is using the wrong local TCP socket as the source.<br>
It is my understanding that a TCP connection is defined by 4 things: source IP, source port, destination IP, and destination port. A device which has registered to Kamailio over TCP establishes a connection which should be used for all requests from the server. The 'location' table used by the registrar module has a 'socket' column which shows the local socket that the remote device registered to. This is the socket transport:address:port which I would expect Kamailio to use for all INVITEs to the remote device.</p>
<p>The problem we were having was that Kamailio started sending INVITEs from the wrong local socket, then the customer's router couldn't figure out to translate NAT for that socket. This was recreated when the remote device received an INVITE which had a contact header which differed from the sending socket, and caused the device to create a new TCP connection for it's response. For some reason, Kamailio saw this new connection and started sending calls (initial INVITEs in a completely new transaction) to it instead of the actual TCP connection that was used for registration. Another possibly important factor is that the "new" socket created by the remote router for NAT was similar to another device's registration socket. It had the same remote source, so maybe Kamailio matched this with an existing registration for a different device?<br>
Device A: tcp:CustomerIP:10042 -> tcp:KamailioIP:4242<br>
Device B: tcp:CustomerIP:11042 -> tcp:KamailioIP:4242<br>
Device A new connection for a 200 OK response: tcp:CustomerIP:11042 -> tcp:KamailioIP:5062</p>
<p>I am not using any functions which update the registration for the device with this new TCP connection, and interestingly other kinds of packets like NOTIFY in response to a subscription and OPTIONs keep alives continue to use the registration socket. I think it is somehow internal to Kamailio.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you commented.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1532#issuecomment-398796849">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZW06w2_mNKnmwUEM3tc2ITVIPuvvks5t-mzUgaJpZM4UAV3q">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZWIcE2CsyEUU-e1o0WsvyeoNgyRcks5t-mzUgaJpZM4UAV3q.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","potentialAction":{"@type":"ViewAction","target":"https://github.com/kamailio/kamailio/issues/1532#issuecomment-398796849","url":"https://github.com/kamailio/kamailio/issues/1532#issuecomment-398796849","name":"View Issue"},"description":"View this Issue on GitHub","publisher":{"@type":"Organization","name":"GitHub","url":"https://github.com"}}</script>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"PERSON","message":"@Forty-Tw0 in #1532: Let me rephrase, Kamailio is using the wrong local TCP socket as the source.\r\nIt is my understanding that a TCP connection is defined by 4 things: source IP, source port, destination IP, and destination port. A device which has registered to Kamailio over TCP establishes a connection which should be used for all requests from the server. The 'location' table used by the registrar module has a 'socket' column which shows the local socket that the remote device registered to. This is the socket transport:address:port which I would expect Kamailio to use for all INVITEs to the remote device.\r\n\r\nThe problem we were having was that Kamailio started sending INVITEs from the wrong local socket, then the customer's router couldn't figure out to translate NAT for that socket. This was recreated when the remote device received an INVITE which had a contact header which differed from the sending socket, and caused the device to create a new TCP connection for it's response. For some reason, Kamailio saw this new connection and started sending calls (initial INVITEs in a completely new transaction) to it instead of the actual TCP connection that was used for registration. Another possibly important factor is that the \"new\" socket created by the remote router for NAT was similar to another device's registration socket. It had the same remote source, so maybe Kamailio matched this with an existing registration for a different device?\r\nDevice A: tcp:CustomerIP:10042 -\u003e tcp:KamailioIP:4242\r\nDevice B: tcp:CustomerIP:11042 -\u003e tcp:KamailioIP:4242\r\nDevice A new connection for a 200 OK response: tcp:CustomerIP:11042 -\u003e tcp:KamailioIP:5062\r\n\r\nI am not using any functions which update the registration for the device with this new TCP connection, and interestingly other kinds of packets like NOTIFY in response to a subscription and OPTIONs keep alives continue to use the registration socket. I think it is somehow internal to Kamailio."}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1532#issuecomment-398796849"}}}</script>
<script type="application/ld+json">{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [kamailio/kamailio] t_relay() sending packets from the wrong TCP socket (#1532)",
"sections": [
{
"text": "",
"activityTitle": "**Jared Hull**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@Forty-Tw0",
"facts": [

]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1532,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/kamailio/kamailio/issues/1532#issuecomment-398796849"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 335633898\n}"
}
],
"themeColor": "26292E"
}</script>