Hello,<br><br>you can do nat_uac_test() for reply and it will detect is it natted, then you can call fix_nated_contact() -- this being another option.<br><br>Cheers,<br>Daniel<br><br><div class="gmail_quote">On Fri, Mar 9, 2012 at 8:56 PM, Giacomo Vacca <span dir="ltr">&lt;<a href="mailto:Giacomo.Vacca@truphone.com">Giacomo.Vacca@truphone.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 link="blue" vlink="purple" lang="EN-GB">
<div>
<p class="MsoNormal">Hi all,</p>
<p class="MsoNormal">I have a scenario where it’s not clear to me what the best approach should be (Kamailio 3.2.0 on Squeeze, although I think it’s a matter of routing logic only).</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I have a client behind NAT that sends an initial REGISTER request with a Contact containing private ip:port (e.g.
</p>
<p class="MsoNormal">Contact: “GV” &lt;<a>sip:12345@192.168.1.2:54321;transport=tcp</a>&gt;</p>
<p class="MsoNormal">)</p>
<p class="MsoNormal">However, after it’s challenged for authentication with a 401, it sends the following REGISTER request with Authorization header and with a Contact containing ip:port equal to the ‘received’ SIP URI (with a combination of ‘rport’ and ‘received’
 parameters (e.g.</p>
<p class="MsoNormal">Contact: “GV” &lt;<a>sip:12345@[received</a>IP]:[rport];transport=tcp&gt;</p>
<p class="MsoNormal">)</p>
<p class="MsoNormal">In this case kamailio’s routing logic is not marking the REGISTER as natted (no Received field in location and no NAT flags set).</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">You can imagine I have a fairly standard NAT handling:</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">route[NATDETECT] {</p>
<p class="MsoNormal">        force_rport();</p>
<p class="MsoNormal">        if (nat_uac_test(&quot;19&quot;)) {</p>
<p class="MsoNormal">                if (is_method(&quot;REGISTER&quot;)) {</p>
<p class="MsoNormal">                        fix_nated_register();</p>
<p class="MsoNormal">                } else {</p>
<p class="MsoNormal">                        fix_nated_contact();</p>
<p class="MsoNormal">                }</p>
<p class="MsoNormal">                setflag(FLT_NATS);</p>
<p class="MsoNormal">        }</p>
<p class="MsoNormal">        return;</p>
<p class="MsoNormal">}</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">FLT_NATS won’t be set, and so it won’t FLB_NATB in the following processing.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">This client receives a call: Kamailio relays the INVITE to it using the stored Contact. The INVITE is correctly received by the client, because the stored Contact refers to the connected socket ([received]:rport).</p>

<p class="MsoNormal">The trouble starts when then the client replies with a 200 OK containing the private ip:port in the Contact header field (again <a href="http://192.168.1.2:54321" target="_blank">192.168.1.2:54321</a>).</p>

<p class="MsoNormal">The ACK will then have that private ip:port in the R-URI, and its relaying will fail.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">One of the solutions I’ve found is using <i>always </i>add_contact_alias() in onreply_route when handling the 200 OK, and then use handle_ruri_alias() when defining the destination for the ACK.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I know that without traces and the full .cfg this is quite a broad question, but I wonder if you have already had to deal with this kind of client behaviour and can provide advice on the best practices.</p>

<p class="MsoNormal">This is in particular useful for the re-use of TCP-based connections.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Thanks in advance,</p>
<p class="MsoNormal">Giacomo</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
</div>
<p class="MsoNormal" style="text-align:justify"><span style="font-size:11.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Truphone Limited is a limited liability company registered in England &amp; Wales, registered office: 4 Royal Mint Court, London, EC3N 4HJ.
<span>Registered No. 04187081.</span> VAT No. <span>GB 851 5278 19.</span>
</span></p>
<p class="MsoNormal" style="text-align:justify"><span><span style="font-size:11.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">Tru</span></span><span style="font-size:11.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;"> is a brand name of Truphone and is a Truphone
 Communications Service. Truphone is a trading name for a number of distinct legal entities that operate in combination.
</span><a href="http://www.truphone.com" target="_blank"><span style="font-size:11.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">www.truphone.com</span></a><span style="font-size:11.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">.</span></p>

<br clear="all">
This e-mail, and any attachment(s), may contain information which is confidential and/or privileged, and is intended for the addressee only. If you are not the intended recipient, you may not use, disclose, copy or distribute this information in any manner whatsoever. If you have received this e-mail in error, please contact the sender immediately and delete it.<br>

</div>

<br>_______________________________________________<br>
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list<br>
<a href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a><br>
<a href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Daniel-Constantin Mierla<br>  <a href="http://www.asipto.com">http://www.asipto.com</a><br>