Hello,

On 31.12.19 17:14, Dovid Bender wrote:
Hi,

First off please forgive my lack of knowledge on how TCP works.   

We are using Kamailio 5.0.7 and we have an issue where clients are connecting via TCP and their NAT devices are closing up. Because of this we want to send TCP keep alives every so often.

1) When restarting Kamailio it's sends a RST. Is this Kamailio sending it out or is it linux sending it when the application is killed?
I think in this case is the linux doing the connections cleanup.
The issue we have is if say we need to do a restart 2-3 times (yes we should normally do that) then we end up with 3x registrations in the db (since when using db mode if the connection goes away it won't remove the reg from the db (as per - https://kamailio.org/docs/modules/5.0.x/modules/usrloc.html#usrloc.p.handle_lost_tcp)

2) I haven testing with the following settings.
a. tcp_crlf_ping=yes
b. tcp_keepcnt = 3
c. tcp_keepidle = 5

With the above I see the TCP keep alives coming in every 75 seconds. If I tcp_keepintvl = 10 then I see TCP keep alives going out from Kamailio to the phone. As per https://www.kamailio.org/wiki/cookbooks/5.0.x/core#tcp_keepintvl it says "Time interval between keepalive probes, when the previous probe failed". Looking at my captures Kamilio sends out the TCP keep alive and gets it back. Is Kamailio not seeing it? With the above it seems to be working the way I want it but I want to make sure that I am doing it right.


The tcp ping options are set to the socket and the kernel takes care of tcp ping-pong. IIRC, the application doesn't get informed when all these happen.



3) For the devs on here how hard would it be to implement handle_lost_tcp for DB-Only?


Probably you can already do it to some extent via config, like:

event_route[tcp:closed] {
    sql_query("delete from location where connection_id=$conid");
}

In case you set attributes for contact, you have to fetch first the ruid by connection id and delete also the records from location_attrs.

But his will work for the connections that are closed during runtime, not because of a restart.

To your question: adding it in the module will be a matter of some C coding, nothing very complex, just a scan of the records in the db to fetch ruid and connection_id, then check if connection exists and if not, delete based on ruid from location and location_attrs.

At the end, this can be also implemented via config, using rtimer module to do a timer-based route execution with the sql queries from above.

Or you make a shell script to delete all the tcp records when restart is executed, because after the restart, the tcp connection will not be available anyhow. Only be careful in case you have UAs that register with a tcp contact address where it expects to get a tcp connect and such UAs close the tcp connection after register -- this is allowed by sip specs.

Cheers,
Daniel



TIA and a happy new year to all.

Regards,

Dovid

_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
-- 
Daniel-Constantin Mierla -- www.asipto.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Kamailio World Conference - April 27-29, 2020, in Berlin -- www.kamailioworld.com