[SR-Users] (SOLVED) Re: Unable to SUBSCRIBE for presence using sip.js through WSS
Alex Villacís Lasso
a_villacis at palosanto.com
Thu Jul 31 21:08:31 CEST 2014
El 31/07/14 11:11, Alex Villacís Lasso escribió:
> El 30/07/14 17:33, Alex Villacís Lasso escribió:
>> My kamailio.cfg configuration file is attached.
>>
>> I am having trouble using SIP.js (http://sipjs.com/) to handle a SUBSCRIBE for presence information. With Jitsi clients (using plain UDP), presence seems to work correctly. However, when using SIP.js via a websocket, Kamailio is unable to send the
>> NOTIFY for the presence event. However, MESSAGE packets are routed correctly between peers, even through websockets.
>>
>> The location table after registration looks like this:
>>
>> +-----+----------------------+----------+------------------+--------------------------------------+------------------------------------+------+---------------------+-------+------------------------+------+---------------------+-------+--------+--------------+-----------------------+---------+-------------------------------------------------+--------+
>>
>> | id | ruid | username | domain | contact | received | path | expires | q | callid | cseq | last_modified | flags | cflags | user_agent |
>> socket | methods | instance | reg_id |
>> +-----+----------------------+----------+------------------+--------------------------------------+------------------------------------+------+---------------------+-------+------------------------+------+---------------------+-------+--------+--------------+-----------------------+---------+-------------------------------------------------+--------+
>>
>> | 192 | uloc-53d96398-1afc-1 | admin | pbx.villacis.com | sip:nfinhooe at 192.0.2.90;transport=ws | sip:192.168.3.2:41478;transport=WS | NULL | 2014-07-30 17:18:57 | -1.00 | 6a2dot9ihoobhng9ackqmq | 90 | 2014-07-30 17:08:57 | 0 | 64 | SIP.js/0.5.0
>> | tls:192.168.2.18:5061 | 782 | <urn:uuid:b8888e95-7833-46a4-a21e-8d2e809a66b8> | 1 |
>> +-----+----------------------+----------+------------------+--------------------------------------+------------------------------------+------+---------------------+-------+------------------------+------+---------------------+-------+--------+--------------+-----------------------+---------+-------------------------------------------------+--------+
>>
>>
>> When running the following javascript code:
>>
>> var subs = ua.subscribe('admin at pbx.villacis.com', 'presence');
>> subs.on('notify', function (n) { alert(n.request.body); });
>>
>> ... I see the following traffic in the browser console area:
>>
>> SUBSCRIBE sip:admin at pbx.villacis.com SIP/2.0
>> Via: SIP/2.0/WSS 192.0.2.90;branch=z9hG4bK3654279
>> Max-Forwards: 70
>> To: <sip:admin at pbx.villacis.com>
>> From: "Administrator" <sip:admin at pbx.villacis.com>;tag=rt0men9qve
>> Call-ID: pa7jno8q3op5pu0qitad
>> CSeq: 322 SUBSCRIBE
>> Proxy-Authorization: Digest algorithm=MD5, username="admin", realm="pbx.villacis.com", nonce="U9lswVPZa5WSu5jz1P/jIOJTvthKXw6v", uri="sip:admin at pbx.villacis.com", response="f7246e64573b5888d69896a70d4204aa"
>> Event: presence
>> Expires: 3600
>> Contact: <sip:nfinhooe at 192.0.2.90;transport=ws>
>> Allow: ACK,CANCEL,BYE,OPTIONS,MESSAGE
>> Supported: outbound
>> User-Agent: SIP.js/0.5.0
>> Content-Length: 0
>>
>> SIP/2.0 202 OK
>> Via: SIP/2.0/WSS 192.0.2.90;branch=z9hG4bK3654279;rport=41478;received=192.168.3.2
>> To: <sip:admin at pbx.villacis.com>;tag=a6a1c5f60faecf035a1ae5b6e96e979a-84c3
>> From: "Administrator" <sip:admin at pbx.villacis.com>;tag=rt0men9qve
>> Call-ID: pa7jno8q3op5pu0qitad
>> CSeq: 322 SUBSCRIBE
>> Expires: 3600
>> Contact: <sip:192.168.2.18:5061;transport=ws>
>> Server: kamailio (4.1.4 (x86_64/linux))
>> Content-Length: 0
>>
>> However, I also get the following messages in the kamailio log:
>>
>> Jul 30 17:03:01 elx3 /usr/sbin/kamailio[6908]: WARNING: <core> [msg_translator.c:2506]: via_builder(): TCP/TLS connection (id: 0) for WebSocket could not be found
>> Jul 30 17:03:01 elx3 /usr/sbin/kamailio[6908]: ERROR: tm [t_msgbuilder.c:1365]: assemble_via(): assemble_via: via building failed
>> Jul 30 17:03:01 elx3 /usr/sbin/kamailio[6908]: ERROR: tm [t_msgbuilder.c:1544]: build_uac_req(): build_uac_req(): Error while assembling Via
>> Jul 30 17:03:01 elx3 /usr/sbin/kamailio[6908]: ERROR: tm [uac.c:338]: t_uac_prepare(): t_uac: Error while building message
>> Jul 30 17:03:01 elx3 /usr/sbin/kamailio[6908]: ERROR: presence [notify.c:1591]: send_notify_request(): in function tmb.t_request_within
>> Jul 30 17:03:01 elx3 /usr/sbin/kamailio[6908]: ERROR: presence [notify.c:1678]: notify(): sending Notify not successful
>> Jul 30 17:03:01 elx3 /usr/sbin/kamailio[6908]: ERROR: presence [subscribe.c:678]: update_subscription(): Could not send notify
>> Jul 30 17:03:01 elx3 /usr/sbin/kamailio[6908]: ERROR: presence [subscribe.c:713]: update_subscription(): occured
>> Jul 30 17:03:01 elx3 /usr/sbin/kamailio[6908]: ERROR: presence [subscribe.c:994]: handle_subscribe(): in update_subscription
>>
>>
>> I have found a discussion at http://marc.info/?l=sr-users&m=136624316816288&w=2 which recommends fix_nated_contact(), but I am not really sure about how to add it, or what conditions to check on whether it should be used. I added the call to
>> fix_nated_contact() like this:
>>
>> # Caller NAT detection route
>> route[NATDETECT] {
>> #!ifdef WITH_NAT
>> force_rport();
>> #
>> # 1 - Contact header field is searched for occurrence of RFC1918 or rfc6598 addresses.
>> # 2 - the "received" test is used: address in Via is compared against source IP address of signaling
>> # 16 - test if the source port is different from the port in Via
>> # 64 - test if the source connection of signaling is a WebSocket
>> # -----
>> # 83
>> #!ifdef WITH_WEBSOCKET
>> # Do NAT traversal stuff for requests from a WebSocket
>> # connection - even if it is not behind a NAT!
>> # This won't be needed in the future if Kamailio and the
>> # WebSocket client support Outbound and Path.
>> if (nat_uac_test("83")) {
>> #!else
>> if (nat_uac_test("19")) {
>> #!endif
>> if (is_method("REGISTER")) {
>> fix_nated_register();
>> #!ifdef WITH_WEBSOCKET
>> if (nat_uac_test("64")) fix_nated_contact();
>> #!endif
>> } else {
>> if (is_first_hop())
>> if (!add_contact_alias()) {
>> xlog("L_ERR", "Error aliasing contact <$ct>\n");
>> sl_send_reply("400", "Bad Request");
>> exit;
>> }
>> }
>> setflag(FLT_NATS);
>> }
>> #!endif
>>
>> return;
>> }
>>
>> After registration, "kamctl ul show" reports this:
>>
>> [root at elx3 js]# kamctl ul show
>> Domain:: location table=512 records=1 max_slot=1
>> AOR:: admin at pbx.villacis.com
>> Contact:: sip:85017jar at 192.168.3.2:41777;transport=ws Q=
>> Expires:: 584
>> Callid:: argl25kg0r4qe8lbtbhn9f
>> Cseq:: 82
>> User-agent:: SIP.js/0.5.0
>> Received:: sip:192.168.3.2:41777;transport=WS
>> State:: CS_NEW
>> Flags:: 0
>> Cflag:: 64
>> Socket:: tls:192.168.2.18:5061
>> Methods:: 782
>> Ruid:: uloc-53d971c7-297f-1
>> Instance:: <urn:uuid:75464840-96b8-4e22-8eaa-5012ba327086>
>> Reg-Id:: 1
>> Last-Keepalive:: 1406759390
>> Last-Modified:: 1406759390
>>
>> However, it still does not work:
>>
>> Jul 30 17:30:21 elx3 /usr/sbin/kamailio[10624]: WARNING: <core> [msg_translator.c:2506]: via_builder(): TCP/TLS connection (id: 0) for WebSocket could not be found
>> Jul 30 17:30:21 elx3 /usr/sbin/kamailio[10624]: ERROR: tm [t_msgbuilder.c:1365]: assemble_via(): assemble_via: via building failed
>> Jul 30 17:30:21 elx3 /usr/sbin/kamailio[10624]: ERROR: tm [t_msgbuilder.c:1544]: build_uac_req(): build_uac_req(): Error while assembling Via
>> Jul 30 17:30:21 elx3 /usr/sbin/kamailio[10624]: ERROR: tm [uac.c:338]: t_uac_prepare(): t_uac: Error while building message
>> Jul 30 17:30:21 elx3 /usr/sbin/kamailio[10624]: ERROR: presence [notify.c:1591]: send_notify_request(): in function tmb.t_request_within
>> Jul 30 17:30:21 elx3 /usr/sbin/kamailio[10624]: ERROR: presence [notify.c:1678]: notify(): sending Notify not successful
>> Jul 30 17:30:21 elx3 /usr/sbin/kamailio[10624]: ERROR: presence [subscribe.c:678]: update_subscription(): Could not send notify
>> Jul 30 17:30:21 elx3 /usr/sbin/kamailio[10624]: ERROR: presence [subscribe.c:713]: update_subscription(): occured
>> Jul 30 17:30:21 elx3 /usr/sbin/kamailio[10624]: ERROR: presence [subscribe.c:994]: handle_subscribe(): in update_subscription
>
> Is there any additional information I could provide for troubleshooting this?
>
> _______________________________________________
> 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
To answer myself: fix_nated_contact() must be run for both REGISTER and SUBSCRIBE, like this:
route[NATDETECT] {
#!ifdef WITH_NAT
force_rport();
#
# 1 - Contact header field is searched for occurrence of RFC1918 or rfc6598 addresses.
# 2 - the "received" test is used: address in Via is compared against source IP address of signaling
# 16 - test if the source port is different from the port in Via
# 64 - test if the source connection of signaling is a WebSocket
# -----
# 83
#!ifdef WITH_WEBSOCKET
# Do NAT traversal stuff for requests from a WebSocket
# connection - even if it is not behind a NAT!
# This won't be needed in the future if Kamailio and the
# WebSocket client support Outbound and Path.
if (nat_uac_test("83")) {
#!else
if (nat_uac_test("19")) {
#!endif
if (is_method("REGISTER|SUBSCRIBE")) {
fix_nated_register();
#!ifdef WITH_WEBSOCKET
if (nat_uac_test("64")) fix_nated_contact();
#!endif
} else {
if (is_first_hop())
if (!add_contact_alias()) {
xlog("L_ERR", "Error aliasing contact <$ct>\n");
sl_send_reply("400", "Bad Request");
exit;
}
}
setflag(FLT_NATS);
}
#!endif
return;
}
More information about the sr-users
mailing list