<div dir="ltr"><font color="#3366ff"><font><font face="tahoma,sans-serif">After endless tests, I tried to replace record_route_preset with insert_hf, writing the complete record route headers. A light started to come out of the tunnel.....</font></font></font><div>

<font color="#3366ff" face="tahoma, sans-serif"><br></font></div><div><font color="#3366ff" face="tahoma, sans-serif">Suppose User A is registered to port 53, User B to port 5060.<br></font><div><font color="#3366ff" face="tahoma, sans-serif"><br>

</font></div><div><font color="#3366ff" face="tahoma, sans-serif">In the case of double record route, when A sends an INVITE to B, I write the following in the SIP header of the INVITE forwarded to B :</font></div><div><font color="#3366ff" face="tahoma, sans-serif">Record-Route: &lt;sip:public_ip:5060;r2=on;lr=on&gt;</font></div>

<div><font color="#3366ff" face="tahoma, sans-serif">Record-Route: &lt;sip:public_ip:53;r2=on;lr=on&gt;</font></div><div><font color="#3366ff" face="tahoma, sans-serif"><br></font></div><div><font color="#3366ff" face="tahoma, sans-serif">The first transaction, INVITE / 200OK goes well, with Kamailio forwarding packets correctly from the corresponding socket of each user.</font></div>

<div><font color="#3366ff" face="tahoma, sans-serif"><br></font></div><div><font color="#3366ff" face="tahoma, sans-serif">The problem arises when User B sends BYE to the 5060 port, with both route headers in the SIP header of the BYE. I get the following error :</font></div>

<div><font color="#3366ff" face="tahoma, sans-serif">    WARNING: rr [loose.c:747]: no socket found for match second RR</font></div><div><font color="#3366ff" face="tahoma, sans-serif"><br></font></div><div><font color="#3366ff" face="tahoma, sans-serif">after which Kamailio forwards the BYE from the 5060 socket to User A. User A being registered on port 53, ignores the packet coming with source port 5060. The BYE is never replied to.</font></div>

<div><font color="#3366ff" face="tahoma, sans-serif"><br></font></div><div><font color="#3366ff" face="tahoma, sans-serif">I guess that means that Kamailio is not able to find the private_ip:53 socket from the public_ip:53 record-route header.</font></div>

<div><font color="#3366ff" face="tahoma, sans-serif">I hope it was clear.</font></div><div><font color="#3366ff" face="tahoma, sans-serif"><br></font></div><div><font color="#3366ff" face="tahoma, sans-serif">I think there&#39;s a fundamental issue with running Kamailio behind NAT and listening on multiple port numbers. Am I the only one suffering from this type of configuration?</font></div>

<div><font color="#3366ff" face="tahoma, sans-serif"><br></font></div><div><font color="#3366ff" face="tahoma, sans-serif">(Part of the problem is also tied to dumb ALG NAT routers which try to out-smart SIP servers, without which I wouldn&#39;t run Kamailio on multiple ports, and life would be much easier)</font></div>

<div><font color="#3366ff" face="tahoma, sans-serif"><br></font></div><div><div><div dir="ltr"><div><font color="#3366ff" face="tahoma, sans-serif">RA</font></div></div><br>
<br><br><div class="gmail_quote">On Thu, Jan 19, 2012 at 01:00, Reda Aouad <span dir="ltr">&lt;<a href="mailto:reda.aouad@gmail.com">reda.aouad@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><font color="#3366ff"><font><font face="tahoma,sans-serif">Okay, it seems we&#39;re on the right track.. BUT</font></font></font><div><font color="#3366ff"><font><font face="tahoma,sans-serif"><br></font></font></font></div>




<div><font color="#3366ff"><font><font face="tahoma,sans-serif">This is my code in the branch_route</font></font></font></div><div><font color="#3366ff"><font><br><div><font face="&#39;courier new&#39;, monospace">        if (is_method(&quot;INVITE|SUBSCRIBE&quot;)){</font></div>




<div><font face="&#39;courier new&#39;, monospace">                $avp(s:fs) = $fs;</font></div><div><font face="&#39;courier new&#39;, monospace">                $avp(s:Rp) = $Rp;</font></div><div><font face="&#39;courier new&#39;, monospace">                avp_subst(&quot;$avp(s:fs)&quot;, &quot;/(.*):(.*):(.*)/\3/&quot;);</font></div>




<div><font face="&#39;courier new&#39;, monospace">                #xlog(&quot;fs: $avp(s:fs) | Rp: $avp(s:Rp)&quot;);</font></div><div><font face="&#39;courier new&#39;, monospace">                if ($avp(s:fs) == $avp(s:Rp)) {</font></div>




<div><font face="&#39;courier new&#39;, monospace">                        record_route_preset(&quot;PUBLIC_IP:$avp(s:fs)&quot;);</font></div><div><font face="&#39;courier new&#39;, monospace">                        return;</font></div>




<div><font face="&#39;courier new&#39;, monospace">                }</font></div><div><font face="&#39;courier new&#39;, monospace">                record_route_preset(&quot;PUBLIC_IP:$avp(s:fs)&quot;, &quot;PUBLIC_IP:$avp(s:Rp)&quot;);</font></div>




<div><font face="&#39;courier new&#39;, monospace">        }</font></div><div><font face="&#39;courier new&#39;, monospace">        return;</font></div><div style="font-family:tahoma,sans-serif"><br></div></font></font></div>




<div><font color="#3366ff" face="tahoma, sans-serif">$avp(s:fs) is the outbound socket, on which I apply the avp_subst function to extract only the outbound port number Kamailio should send from.</font></div><div><font color="#3366ff" face="tahoma, sans-serif">$avp(s:Rp) is the inbound port, the port on which Kamailio received the INVITE.</font></div>



<div><font color="#3366ff" face="tahoma, sans-serif">Then if the above port numbers are equal, I do only one record route. If not, I do double record routing, one per port number.</font></div>
<div><font color="#3366ff"><font><font face="tahoma,sans-serif"><br></font></font></font></div><div><font color="#3366ff"><font><font face="tahoma,sans-serif">The problem is that for the first branch, everything works fine. But for the subsequent branches, I get the following error :</font></font></font></div>


<div><font color="#3366ff"><font><font face="tahoma,sans-serif">        ERROR: rr [rr_mod.c:256]: Duble attempt to record-route</font></font></font></div><div><font color="#3366ff"><font><font face="tahoma,sans-serif"><br>


</font></font></font></div><div><font color="#3366ff"><font><font face="tahoma,sans-serif">It seems that for subsequent branches, Kamailio detects that it already record routed the first branch, so gives an error and doesn&#39;t record route.</font></font></font></div>

<span class="HOEnZb"><font color="#888888">
</font></span><div><span class="HOEnZb"><font color="#888888"><font color="#3366ff"><font><font face="tahoma,sans-serif"><br clear="all"></font></font></font><div dir="ltr"><font color="#3366ff" face="tahoma, sans-serif"><br>



</font><div><font color="#3366ff" face="tahoma, sans-serif">Reda</font></div></div></font></span><div><div class="h5"><br><br></div></div></div></div></blockquote></div></div></div></div></div>