[SR-Users] nat_keepalive() and fix_contact() are incompatible

Klaus Darilion klaus.mailinglists at pernau.at
Wed May 22 10:06:03 CEST 2013



On 21.05.2013 18:37, David wrote:
> Hello,
>
> So I want to setup a Kamailio SIP Proxy(  version 4 ) that will do NAT
> signalling handling. With the help of nat_traversal and path modules.
>
> Attached is my kamailio.cfg file.
>
> My problem is I want to do keep alive on users who are behind NAT, so I
> called nat_keepalive();. The script will work fine, but as soon as I
> enable either add_contact_alias() or fix_contact(), the keep alive
> doesn't activate.
>
> I modified nat_traversal.c to identify the issue and found that it is
> comparing the contact header from the request and the reply to find the
> expiration. Trouble is, the request contact header was taken from before
> I called fix_contact() and the reply header has the contact from after
> the fix_contact() call. So my traces show that on the return trip the
> callback is called, I bet the stack trace looks like this :
>
> 1. Some method in tm
> 2. __tm_reply_in() defined at nat_traversal.c:1358
> 3. get_register_expire called from nat_traversal.c:1377 and defined at
> nat_traversal.c:878
> 4. STR_MATCH_STR called from nat_traversal.c:937 and defined at
> nat_traversal.c:77
>
> STR_MATCH_STR returns false because the headers are different.
>
> I added
>
>                else
>                          {
>                                  LM_ERR("failed to match because request
> %s is not reply %s", contact->uri.s, r_contact->uri.s ) ;
>                          }
>
> to the code and see :
>
> May 21 12:18:52 kamailio-dev-nat /usr/sbin/kamailio[30163]: ERROR:
> nat_traversal [nat_traversal.c:946]: failed to match because request
> sip:username at mytld#015#012#015#012 is not reply
> sip:username at myip:59080>;expires=60;received="sip:64.18.189.196:5060"#015#012Server:
> CenseredUA 5.2-rc1#015#012Content-Length: 0#015#012#015
>
> So as you can see the original Contact header has the server's domain
> name and the response has the IP address that set by fix_contact().

Even if you do not call fix_contact I fail to see how the URIs should 
match, as the contact URI in the response has the "expires" parameter 
and therefore the string comparison should fail.

> So I think that nat_keepalive() should not be comparing the Contact from
> the original request but using the contact header from the modified
> request.

That would be a solution. Another solution would be to use 
fix_nated_register() for REGISTER and add_contact_alias() for other 
requests (from nathelper module)

regards
Klaus


>
> Any ideas what to do next ?
>
> Thanks,
> David
>
>
>
>
> _______________________________________________
> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
> sr-users at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
>



More information about the sr-users mailing list