<h3>Description</h3>

<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<p>we have an issue with our Kamailio.</p>
<p>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.</p>
<p>We have set the parameter mhomed=1</p>
<p><a href="https://user-images.githubusercontent.com/16304253/35796442-e642d466-0a5c-11e8-846f-a538e3185a69.png" target="_blank"><img src="https://user-images.githubusercontent.com/16304253/35796442-e642d466-0a5c-11e8-846f-a538e3185a69.png" alt="image" style="max-width:100%;"></a></p>
<p>The ACK packet gets relayed with the wrong source port. Then the NAT rejects the packet and the call cannot be established.</p>
<p>Also, if we set mhomed=0 it works BUT we are not sure that multi homed is handled correctly.</p>
<p>the issue seems to be located in the RR module and the loose_route() function.<br>
In the  after_loose() function in loose.c, the  function set_force_socket()  is called only if a DOUBLE route is mentioned in the route set of the ACK message</p>
<p>But when both users are using 5066 as proxy port, we get only ONE route for the proxy in the route set (and to us it is OK). In this case, we get a trace:</p>
<p>"No next URI found"</p>
<p>and the code exits. Later in the message processing, when t_relay() is called, the forward_request() selects the first socket defined in our configuration instead.</p>
<p>At this point, we can't presume what socket we be select. We believe that it is a software bug  and that after_loose() should force the send_socket even though we have only one route in the route set</p>
<h4>Debugging Data</h4>

<pre><code>(paste your debugging data here)
</code></pre>
<h4>Log Messages</h4>

<pre><code>(paste your log messages here)
</code></pre>
<h4>SIP Traffic</h4>

<pre><code>(paste your sip traffic here)
</code></pre>
<h3>Possible Solutions</h3>
<p>Adding the process of set_force_socket in case we have one route and only.</p>
<p>L.808 if (res > 0) { /* No next route found */<br>
LM_DBG("No next URI found\n");</p>
<blockquote>
<p>if (!use_ob) {<br>
if ((si = grep_sock_info( &puri.host, puri.port_no?puri.port_no:proto_default_port(puri.proto), puri.proto)) != 0) {<br>
set_force_socket(_m, si);<br>
} else if ((si = grep_sock_info( &puri.host, puri.port_no, puri.proto)) != 0) {<br>
set_force_socket(_m, si);<br>
} else {<br>
if (enable_socket_mismatch_warning) {<br>
LM_WARN("no socket found to match second RR (%.*s)\n",<br>
rt->nameaddr.uri.len, ZSW(rt->nameaddr.uri.s));<br>
if(!is_myself(&puri)) {<br>
LM_WARN("second RR uri is not myself (%.*s)\n",<br>
rt->nameaddr.uri.len, ZSW(rt->nameaddr.uri.s));<br>
}<br>
}<br>
}<br>
}</p>
</blockquote>
<pre><code>         status = (preloaded ? NOT_RR_DRIVEN : RR_DRIVEN);
                goto done;
        }
</code></pre>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>(paste your output here)
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>

<pre><code>(paste your output here)
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1428">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZatCbcPSQn1szNTeGtRJiot2MSKlks5tRxqxgaJpZM4R5l_w">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZRZd1KXC3fI376jDrHFo2MRRdUPsks5tRxqxgaJpZM4R5l_w.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/kamailio/kamailio/issues/1428"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>

<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://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":" Issue with Socket selection on Forwarding ACK message (#1428)"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1428"}}}</script>