Discussion:
[SR-Users] usrloc: Unregister client on TCP connection close
Camille Oudot
2014-10-22 13:08:12 UTC
Permalink
Hi,

I'm looking for a mechanism to unregister clients when the corresponding
TCP connection is closed, but had no success so far.

I've tried the handle_lost_tcp parameter of usrloc, but it didn't work:
the user was not unregistered, whereas the connection was seen as
closed by kamailio. Is it still a relevant option?

Otherwise, is there any mechanism that would trigger some kind of
event_route whenever a connection (TCP, TLS, WS, WSS) is lost or
closed?

Cheers,
--
Camille
Carlos Ruiz Díaz
2014-10-22 14:02:01 UTC
Permalink
Well, in websocket module you have the event route that's triggered when a
connection is lost [1].

You wouldn't be able to use the unregister function of the registrar
module, because a faked SIP message is used to trigger the event, but you
can always write a custom SQL to delete the record of the location table
using the socket information, to which you do have access: $si, $sp.

[1]
http://kamailio.org/docs/modules/stable/modules/websocket.html#websocket.e.closed

Regards,
Carlos
Post by Camille Oudot
Hi,
I'm looking for a mechanism to unregister clients when the corresponding
TCP connection is closed, but had no success so far.
the user was not unregistered, whereas the connection was seen as
closed by kamailio. Is it still a relevant option?
Otherwise, is there any mechanism that would trigger some kind of
event_route whenever a connection (TCP, TLS, WS, WSS) is lost or
closed?
Cheers,
--
Camille
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
--
Carlos
http://caruizdiaz.com
Daniel-Constantin Mierla
2014-10-22 14:12:12 UTC
Permalink
Hello,
Post by Camille Oudot
Hi,
I'm looking for a mechanism to unregister clients when the corresponding
TCP connection is closed, but had no success so far.
the user was not unregistered, whereas the connection was seen as
closed by kamailio. Is it still a relevant option?
Otherwise, is there any mechanism that would trigger some kind of
event_route whenever a connection (TCP, TLS, WS, WSS) is lost or
closed?
it should work -- quickly looked to the code and couldn't spot a
problem. Just be aware that is working only when usrloc keeps the
records in memory (not designed for db only mode).
Also, note that the record is not unregistered/removed immediately after
the connection is closed, but by the timer task that checks for expired
records.

Cheers,
Daniel
--
Daniel-Constantin Mierla
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Camille Oudot
2014-10-22 16:19:31 UTC
Permalink
Le Wed, 22 Oct 2014 16:12:12 +0200,
Post by Daniel-Constantin Mierla
it should work -- quickly looked to the code and couldn't spot a
problem. Just be aware that is working only when usrloc keeps the
records in memory (not designed for db only mode).
Ok, i'm using in memory storage, so it should be fine
Post by Daniel-Constantin Mierla
Also, note that the record is not unregistered/removed immediately
after the connection is closed, but by the timer task that checks for
expired records.
Well, i configured usrloc with:

modparam("usrloc", "handle_lost_tcp", 1)
modparam("usrloc", "timer_interval", 5)

then disconnect the SIP phone from the network, and here are the logs:

...
DEBUG: <core> [io_wait.h:610]: io_watch_del(): DBG: io_watch_del (0xa2a320, 13, -1, 0x10) fd_no=2 called
DEBUG: <core> [tcp_read.c:1434]: release_tcpconn(): releasing con 0x7fedfe6cbe20, state 1, fd=13, id=3
DEBUG: <core> [tcp_read.c:1435]: release_tcpconn(): extra_data (nil)
DEBUG: <core> [tcp_main.c:3331]: handle_tcp_child(): handle_tcp_child: reader response= 7fedfe6cbe20, 1 from 2
DEBUG: <core> [io_wait.h:388]: io_watch_add(): DBG: io_watch_add(0x9e6080, 60, 2, 0x7fedfe6cbe20), fd_no=45
DEBUG: <core> [tcp_main.c:3459]: handle_tcp_child(): handle_tcp_child: CONN_RELEASE 0x7fedfe6cbe20 refcnt= 1
...

but then, nothing from usrloc module.

It's maybe worth nothing that the kamailio instance dealing with these
connections is not the registrar, but only a proxy in front of it,
keeping track of successful registrations. The proxy's usrloc database
is populated by calls to save() when a 200 OK response comes from the
registrar box.

The Received information however is correctly set using the
received_avp feature of the registrar module.

But is this "received" information used by the usrloc timer task, or
does it remebers the source IP and port of the machine sending the
200 OK response instead?

Cheers,
--
Camille
Daniel-Constantin Mierla
2014-10-22 17:21:54 UTC
Permalink
Post by Camille Oudot
Le Wed, 22 Oct 2014 16:12:12 +0200,
Post by Daniel-Constantin Mierla
it should work -- quickly looked to the code and couldn't spot a
problem. Just be aware that is working only when usrloc keeps the
records in memory (not designed for db only mode).
Ok, i'm using in memory storage, so it should be fine
Post by Daniel-Constantin Mierla
Also, note that the record is not unregistered/removed immediately
after the connection is closed, but by the timer task that checks for
expired records.
modparam("usrloc", "handle_lost_tcp", 1)
modparam("usrloc", "timer_interval", 5)
...
DEBUG: <core> [io_wait.h:610]: io_watch_del(): DBG: io_watch_del (0xa2a320, 13, -1, 0x10) fd_no=2 called
DEBUG: <core> [tcp_read.c:1434]: release_tcpconn(): releasing con 0x7fedfe6cbe20, state 1, fd=13, id=3
DEBUG: <core> [tcp_read.c:1435]: release_tcpconn(): extra_data (nil)
DEBUG: <core> [tcp_main.c:3331]: handle_tcp_child(): handle_tcp_child: reader response= 7fedfe6cbe20, 1 from 2
DEBUG: <core> [io_wait.h:388]: io_watch_add(): DBG: io_watch_add(0x9e6080, 60, 2, 0x7fedfe6cbe20), fd_no=45
DEBUG: <core> [tcp_main.c:3459]: handle_tcp_child(): handle_tcp_child: CONN_RELEASE 0x7fedfe6cbe20 refcnt= 1
...
but then, nothing from usrloc module.
It's maybe worth nothing that the kamailio instance dealing with these
connections is not the registrar, but only a proxy in front of it,
keeping track of successful registrations. The proxy's usrloc database
is populated by calls to save() when a 200 OK response comes from the
registrar box.
The Received information however is correctly set using the
received_avp feature of the registrar module.
But is this "received" information used by the usrloc timer task, or
does it remebers the source IP and port of the machine sending the
200 OK response instead?
It is internal connection id of the respective message (should be the
REGISTER0 that is kept for this feature. In your case, it is not the
right one, because you call save() for reply, so the connection would be
the one on which reply came in (or none if it not tcp).

Maybe you can do save() when there is a register with credentials and
unregister if there is a failure for relaying that registration (e.g.,
it was failure to authenticate in the next server).
Cheers,
Daniel
--
Daniel-Constantin Mierla
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Camille Oudot
2014-10-22 18:52:51 UTC
Permalink
Le Wed, 22 Oct 2014 19:21:54 +0200,
Post by Daniel-Constantin Mierla
Maybe you can do save() when there is a register with credentials and
unregister if there is a failure for relaying that registration (e.g.,
it was failure to authenticate in the next server).
Ok, this is so simple and so great at the same time :) Solved the issue
for me, thanks.
--
Camille
Camille Oudot
2014-10-22 16:25:48 UTC
Permalink
Le Wed, 22 Oct 2014 09:02:01 -0500,
Post by Carlos Ruiz Díaz
You wouldn't be able to use the unregister function of the registrar
module, because a faked SIP message is used to trigger the event, but
you can always write a custom SQL to delete the record of the
location table using the socket information, to which you do have
access: $si, $sp.
Yes indeed, in the case of websockets this event already exists. Then I
can use a hash table to store the contact corresponding to the ip and
port, then be able to unregister it from the usrloc database.

I was wondering if such a mechanism was available for plain TCP and TLS
connections.

Cheers,
--
Camille
Loading...