[OpenSIPS-Users] How to keep a TCP connection persistent?

Gremaud Odin odin.gremaud at nexcom.fr
Thu Sep 8 14:29:44 CEST 2011


Hi everyone,

This is a pretty simple question when considering a simple 
implementation. However, with the following design, it becomes more 
complicated to handle TCP connections efficiently:

Public network  ||  Private network
                 ||
     U1 -------> P1 -------> P2
                 ||
                 ||

With the following:
- U1: NATed client
- P1: OpenSIPS NAT box (handles NAT-related features)
- P2: OpenSIPS Proxy/Registrar

P1 handles the NAT using the nat_traversal module. It is working great 
using UDP, but TCP is not kept alive by nat_traversal (nat_keepalive() 
is just ignored in TCP). I tried to find a workaround to this. I found 
three solutions for now:

1) Set the tcp_persistent_flag of the registrar module when NAT is 
detected. Unfortunately, P2 does not know the public network, and cannot 
therefore keep the TCP connections opened. Dead end, as adding the 
registrar module on P1 (without save() ) with the same flag set seems 
not to work from my experimentations (which would make sense, according 
to the documentation).

2) Another solution is to hard code on P1 the TCP lifetime using the 
global parameter (tcp_connection_lifetime) and to set it to the 
max_expires parameter of the registrar module (on P2). But I noticed 
that even with this parameter set, the TCP connections still went down 
after some time. Twinkle is the culprit here, as it closes the TCP 
connection after 32 seconds if the TCP persistent option is not checked. 
Note that with this option set, any configuration server-side did not 
have any effect: the server does not close the connection, even after 
its timer runs out. Would it be a valid solution with clients not 
messing up with this (meaning: at least not Twinkle)?

3) The last solution would rely on the client hard/soft-phone to keep 
the connection opened. However, it would require clients supporting TCP, 
and being able to keep the TCP connection opened on their side. I would 
rather find a server-based solution, as it would work for any clients 
out there.

By requirement, I cannot simplify the design (by putting the registrar 
function on P1 for instance), so I have to find another solution. Does 
anyone already encounter a similar case? I read a discussion about 
adding TCP support/keepalive to the nat_traversal module in an old 
discussion (2008, 
http://www.mail-archive.com/users@lists.opensips.org/msg00061.html). Is 
there anything new there or other stuff to consider/do?

Regards,

Odin



More information about the Users mailing list