Documentation

Documentation.Tutorials-WebSocket-2-2 History

Hide minor edits - Show changes to output

April 15, 2019, at 07:34 AM by 89.45.16.83 -
Changed lines 158-159 from:
!!!! [[#opensips.cfg]] Normal SDP negociation
to:
!!!! [[#opensips.cfg]] Normal SDP negotiation
Changed lines 434-436 from:
!!!! [[#opensips-late.cfg]] Late SDP negociation

[[http://www.opensips.org/pub/docs/tutorials/websockets/opensips-late.cfg | Here ]] you can find a more complex configuration file, that also includes support for late SDP negociation (SDP is exchanged between 200 OK and ACK).
to:
!!!! [[#opensips-late.cfg]] Late SDP negotiation

[[http://www.opensips.org/pub/docs/tutorials/websockets/opensips-late.cfg | Here ]] you can find a more complex configuration file, that also includes support for late SDP negotiation (SDP is exchanged between 200 OK and ACK).
October 24, 2017, at 01:09 PM by razvancrainea -
Deleted lines 10-11:

This tutorial is inspired from
July 25, 2017, at 02:38 PM by razvancrainea -
Changed line 164 from:
'''NOTE:''' the default port port for WSS (443) is privileged, so if you are running this script, you should start OpenSIPS with super-user rights (as user root).
to:
'''NOTE:''' the default port for WSS (443) is privileged, so if you are running this script, you should start OpenSIPS with super-user rights (as user root).
July 25, 2017, at 02:38 PM by razvancrainea -
Added lines 163-164:

'''NOTE:''' the default port port for WSS (443) is privileged, so if you are running this script, you should start OpenSIPS with super-user rights (as user root).
July 07, 2017, at 05:10 PM by razvancrainea -
Changed lines 160-161 from:
* [[#opensips.cfg | Normal SDP negociation]]
to:
!!!! [[#opensips.cfg]] Normal SDP negociation
Changed lines 433-435 from:
* [[#opensips-late.cfg | Late SDP negociation]]
to:

!!!! [[#opensips-late.cfg]] Late SDP negociation
July 07, 2017, at 05:03 PM by razvancrainea -
Changed lines 160-161 from:
The following configuration file is a minimal working example of a Residential script that can handle clients connections over both UDP and Websocket transports. This example assumes that the SDP offer is present in the INVITE from the UAC and the SDP answer is in the 200 OK from the UAS.
to:
* [[#opensips.cfg | Normal SDP negociation]]

The [[http://www.opensips.org/pub/docs/tutorials/websockets/opensips.cfg | following ]] configuration file is a minimal working example of a Residential script that can handle clients connections over both UDP and Websocket transports. This example assumes that the SDP offer is present in the INVITE from the UAC and the SDP answer is in the 200 OK from the UAS.
Changed lines 431-434 from:
@]
to:
@]

* [[#opensips-late.cfg | Late SDP negociation]]
[[http://www.opensips.org/pub/docs/tutorials/websockets/opensips-late.cfg | Here ]] you can find a more complex configuration file, that also includes support for late SDP negociation (SDP is exchanged between 200 OK and ACK).
March 08, 2017, at 04:36 PM by ionutionita92 - Fix bad rtpengine start command
Changed line 43 from:
./rtpengine -p /var/run/rtpengine.pid --i eth0/1.1.1.1 -n 127.0.0.1:60000 -c 127.0.0.0.1:60001 -m 50000 -M 55000 -E -L 7
to:
./rtpengine -p /var/run/rtpengine.pid -i eth0/1.1.1.1 -n 127.0.0.1:60000 -c 127.0.0.0.1:60001 -m 50000 -M 55000 -E -L 7
July 18, 2016, at 10:20 AM by razvancrainea -
Changed line 33 from:
* @@-n@@: the listening IP and port that is used by OpenSIPS to communicate with the RTPengine
to:
* @@-n@@: the listening IP and port that is used by OpenSIPS to communicate with the RTPengine ('''NOTE:''' the rtpengine module only works with the rtpengine NG protocol, so you must use @@-n@@/@@--listen-ng@@; Using @@-u@@/@@--listen-udp@@ or @@-l@@/@@--listen-tcp@@ will not work!)
January 14, 2016, at 06:46 PM by etamme -
Changed line 28 from:
After installing the kernel module and the additional libraries, the rtpengine daemon has to be configured. This can be done from @@/etc/default/ngcp-rtpengine-daemon@@ if installed from debs, or from the command line if the daemon is started manually. On systemd based OSes, Eric Tamme created some [[https://github.com/etamme/federated-sip/tree/2.2-config/scripts|startup scripts]].
to:
After installing the kernel module and the additional libraries, the rtpengine daemon has to be configured. This can be done from @@/etc/default/ngcp-rtpengine-daemon@@ if installed from debs, or from the command line if the daemon is started manually. On systemd based OSes, Eric Tamme created some [[https://github.com/etamme/federated-sip/tree/master/scripts|startup scripts]].
January 14, 2016, at 06:42 PM by etamme -
Changed line 24 from:
Also important to note that as of 2.2, certificate management has been split out into a new module, tls_mgm. Setting appropriate modparams for the tls_mgm module is how we will manage our certificates for both WSS and TLS.
to:
Also important to note that as of 2.2, certificate management has been split out into a new module, [[ http://www.opensips.org/html/docs/modules/2.2.x/tls_mgm.html|TLS_MGM]]. Setting appropriate modparams for the tls_mgm module is how we will manage our certificates for both WSS and TLS.
January 14, 2016, at 06:41 PM by etamme -
Changed line 8 from:
[[http://tools.ietf.org/html/rfc6455|WebSocket]] is a protocol that provides full-duplex communication between web clients and servers over TCP connections. Using the WebSocket protocol, browsers can connect to web servers and exchange data, regardless the type or nature of the application protocol. [[https://tools.ietf.org/html/rfc7118|RFC 7118]] leveraged this protocol in order to allow browsers to make VoIP calls using the SIP protocol. [[ http://www.opensips.org/html/docs/modules/2.2.x/proto_wss.html |WebSocketSecure} ]] (WSS) overlays TLS onto the Websocket protocol making the connection secure, a requirement for many browsers if you want to do WebRTC.
to:
[[http://tools.ietf.org/html/rfc6455|WebSocket]] is a protocol that provides full-duplex communication between web clients and servers over TCP connections. Using the WebSocket protocol, browsers can connect to web servers and exchange data, regardless the type or nature of the application protocol. [[https://tools.ietf.org/html/rfc7118|RFC 7118]] leveraged this protocol in order to allow browsers to make VoIP calls using the SIP protocol. [[ http://www.opensips.org/html/docs/modules/2.2.x/proto_wss.html|WebSocketSecure]] (WSS) overlays TLS onto the Websocket protocol making the connection secure, a requirement for many browsers if you want to do WebRTC.
January 14, 2016, at 06:38 PM by etamme -
Changed line 8 from:
[[http://tools.ietf.org/html/rfc6455|WebSocket]] is a protocol that provides full-duplex communication between web clients and servers over TCP connections. Using the WebSocket protocol, browsers can connect to web servers and exchange data, regardless the type or nature of the application protocol. [[https://tools.ietf.org/html/rfc7118|RFC 7118]] leveraged this protocol in order to allow browsers to make VoIP calls using the SIP protocol. WebsocketSecure (WSS) overlays TLS onto the Websocket protocol making the connection secure, a requirement for many browsers if you want to do WebRTC.
to:
[[http://tools.ietf.org/html/rfc6455|WebSocket]] is a protocol that provides full-duplex communication between web clients and servers over TCP connections. Using the WebSocket protocol, browsers can connect to web servers and exchange data, regardless the type or nature of the application protocol. [[https://tools.ietf.org/html/rfc7118|RFC 7118]] leveraged this protocol in order to allow browsers to make VoIP calls using the SIP protocol. [[ http://www.opensips.org/html/docs/modules/2.2.x/proto_wss.html |WebSocketSecure} ]] (WSS) overlays TLS onto the Websocket protocol making the connection secure, a requirement for many browsers if you want to do WebRTC.
January 14, 2016, at 06:37 PM by etamme - update to include new docs for WSS and TLS with tls_mgm and proto_wss
Changed lines 8-11 from:
[[http://tools.ietf.org/html/rfc6455|WebSocket]] is a protocol that provides full-duplex communication between web clients and servers over TCP connections. Using the WebSocket protocol, browsers can connect to web servers and exchange data, regardless the type or nature of the application protocol. [[https://tools.ietf.org/html/rfc7118|RFC 7118]] leveraged this protocol in order to allow browsers to make VoIP calls using the SIP protocol.

This document describes how to use '''OpenSIPS''' as the core component of a SIP platform that connects both SIP clients (over UDP, TCP or TLS) as well as browser based clients (using SIP over WebSockets). While OpenSIPS handles the SIP signalling part, media is handled by [[https://github.com/sipwise/rtpengine|RTPengine]], a high performance media proxy that is able to handle both RTP and SRTP media streams, as well as bridging between them.
to:
[[http://tools.ietf.org/html/rfc6455|WebSocket]] is a protocol that provides full-duplex communication between web clients and servers over TCP connections. Using the WebSocket protocol, browsers can connect to web servers and exchange data, regardless the type or nature of the application protocol. [[https://tools.ietf.org/html/rfc7118|RFC 7118]] leveraged this protocol in order to allow browsers to make VoIP calls using the SIP protocol. WebsocketSecure (WSS) overlays TLS onto the Websocket protocol making the connection secure, a requirement for many browsers if you want to do WebRTC.

This document describes how to use '''OpenSIPS''' as the core component of a SIP platform that connects both SIP clients (over UDP, TCP or TLS) as well as browser based clients using SIP over WebSockets and WebSocketsSecure. While OpenSIPS handles the SIP signalling part, media is handled by [[https://github.com/sipwise/rtpengine|RTPengine]], a high performance media proxy that is able to handle both RTP and SRTP media streams, as well as bridging between them.
Added lines 22-25:
You must generate certificates to use with TLS and WSS. For this example we are generating certificates using [[https://letsencrypt.org/|LetsEncrypt]]

Also important to note that as of 2.2, certificate management has been split out into a new module, tls_mgm. Setting appropriate modparams for the tls_mgm module is how we will manage our certificates for both WSS and TLS.
Changed lines 65-66 from:
In order to use WebSocket in OpenSIPS, one has to load the [[http://www.opensips.org/html/docs/modules/2.2.x/proto_ws|proto_ws]] into its configuration file and define a listener for the WebSocket protocol.
to:
In order to use WebSocket and WebSocketSecure in OpenSIPS, one has to load the [[http://www.opensips.org/html/docs/modules/2.2.x/proto_ws|proto_ws]] and [[http://www.opensips.org/html/docs/modules/2.2.x/proto_wss|proto_wss]] into its configuration file and define a listener for the WebSocket and WebSocketSecure protocol. We also must load the [[http://www.opensips.org/html/docs/modules/2.2.x/tls_mgm|tls_mgm]] module in order to manage our certificates.
Added line 68:
# set listeners for all protocols
Changed lines 70-80 from:
...
to:
listen=wss:127.0.0.1:443
listen=tls:127.0.0.1:5061
listen=udp:127.0.0.1:5060

# load our certificate management module
loadmodule "tls_mgm.so"

#load all protocol modules
loadmodule "proto_udp.so"
loadmodule "proto_tls.so"
loadmodule "proto_wss.so"
Added lines 82-87:

# modparam our certificate information
modparam("tls_mgm", "certificate","/etc/letsencrypt/live/acme.com/cert.pem")
modparam("tls_mgm", "private_key","/etc/letsencrypt/live/acme.com/privkey.pem")

Changed line 101 from:
if (proto == WS)
to:
if (proto == WS || proto == WSS)
Changed lines 183-185 from:
listen=udp:127.0.0.0:5060 # TODO: update with your local IP and port
listen=ws:127.0.0.0:8080 # TODO: update with your local IP and port
to:
# Set up listeners
listen=ws:127.0.0.1:8080
listen=wss:127.0.0.1:443
listen=tls:127.0.0.1:5061
listen=udp:127.0.0.1:5060
Changed lines 245-249 from:
#### WebSocket protocol
to:
#### TLS protocol
loadmodule "proto_tls.so"

#### WebSocket and WebSocketSecure protocol
loadmodule "proto_wss.so"
Changed lines 252-258 from:
to:
# Certificate management
loadmodule "tls_mgm.so"
modparam("tls_mgm", "certificate","/etc/letsencrypt/live/acme.com/cert.pem")
modparam("tls_mgm", "private_key","/etc/letsencrypt/live/acme.com/privkey.pem")


Changed lines 343-344 from:
# check if the clients are using WebSockets
if (proto == WS)
to:
# check if the clients are using WebSockets or WebSocketSecure
if (proto == WS || proto == WSS)
March 17, 2015, at 09:43 PM by etamme - added note about offer answer model
Changed line 138 from:
The following configuration file is a minimal working example of a Residential script that can handle clients connections over both UDP and Websocket transports.
to:
The following configuration file is a minimal working example of a Residential script that can handle clients connections over both UDP and Websocket transports. This example assumes that the SDP offer is present in the INVITE from the UAC and the SDP answer is in the 200 OK from the UAS.
March 17, 2015, at 09:41 PM by etamme - changed startup scripts link
Changed line 24 from:
After installing the kernel module and the additional libraries, the rtpengine daemon has to be configured. This can be done from @@/etc/default/ngcp-rtpengine-daemon@@ if installed from debs, or from the command line if the daemon is started manually. On systemd based OSes, Eric Tamme created some [[https://github.com/etamme/federated-sip/wiki|start scripts]].
to:
After installing the kernel module and the additional libraries, the rtpengine daemon has to be configured. This can be done from @@/etc/default/ngcp-rtpengine-daemon@@ if installed from debs, or from the command line if the daemon is started manually. On systemd based OSes, Eric Tamme created some [[https://github.com/etamme/federated-sip/tree/2.2-config/scripts|startup scripts]].
March 17, 2015, at 08:02 PM by razvancrainea -
Changed lines 86-87 from:
if (is_method("REGISTER"))
{
to:
if (is_method("REGISTER")) {
Deleted line 236:
Deleted line 247:
Changed lines 303-304 from:
if (is_method("PUBLISH|SUBSCRIBE"))
{
to:
if (is_method("PUBLISH|SUBSCRIBE")) {
Changed lines 315-316 from:
if (is_method("REGISTER"))
{
to:
if (is_method("REGISTER")) {
Deleted line 344:
Deleted line 359:
Deleted line 375:
March 17, 2015, at 08:01 PM by razvancrainea -
Added lines 1-401:
!!!!! Documentation -> [[Documentation.Tutorials | Tutorials ]] -> [[ http://www.opensips.org/html/docs/modules/2.2.x/proto_ws.html | {+WebSocket Transport+} ]] using OpenSIPS
This page has been visited {$PageCount} times.
(:toc-float Table of Content:)
----

!!! Tutorial Overview

[[http://tools.ietf.org/html/rfc6455|WebSocket]] is a protocol that provides full-duplex communication between web clients and servers over TCP connections. Using the WebSocket protocol, browsers can connect to web servers and exchange data, regardless the type or nature of the application protocol. [[https://tools.ietf.org/html/rfc7118|RFC 7118]] leveraged this protocol in order to allow browsers to make VoIP calls using the SIP protocol.

This document describes how to use '''OpenSIPS''' as the core component of a SIP platform that connects both SIP clients (over UDP, TCP or TLS) as well as browser based clients (using SIP over WebSockets). While OpenSIPS handles the SIP signalling part, media is handled by [[https://github.com/sipwise/rtpengine|RTPengine]], a high performance media proxy that is able to handle both RTP and SRTP media streams, as well as bridging between them.

This tutorial is inspired from

!!! Setup

!!!! RTPengine

!!!!! Installation

The RTPengine consists of two main components: a kernel module used to efficiently route the RTP packets directly in kernel, and a daemon used to communicate with OpenSIPS. You can find more details [[https://github.com/sipwise/rtpengine#overview|here]]. Both components can be installed from debs (on Debian based systems) or directly from sources. Simply follow the [[https://github.com/sipwise/rtpengine#compiling-and-installing|official documentation]] to install RTPengine.

!!!!! Usage

After installing the kernel module and the additional libraries, the rtpengine daemon has to be configured. This can be done from @@/etc/default/ngcp-rtpengine-daemon@@ if installed from debs, or from the command line if the daemon is started manually. On systemd based OSes, Eric Tamme created some [[https://github.com/etamme/federated-sip/wiki|start scripts]].

The interesting parameters we are using are as follows:

* @@-i@@: the listening interface for RTP/SRTP
* @@-n@@: the listening IP and port that is used by OpenSIPS to communicate with the RTPengine
* @@-c@@: the IP and port of the CLI - this is used to gather statistics for the RTP/SRTP sessions
* @@-m, -M@@: both take an integer as argument and together define the local port range from which rtpengine will allocate UDP ports for media traffic relay. Default to 30000 and 40000 respectively.
* @@-L@@: indicates the debugging level

You can find all the parameters available [[https://github.com/sipwise/rtpengine#userspace-daemon|here]].

Here is an example that runs @@rtpengine@@ from cli that talks with OpenSIPS over localhost and RTP using the 1.1.1.1 IP:

[@
./rtpengine -p /var/run/rtpengine.pid --i eth0/1.1.1.1 -n 127.0.0.1:60000 -c 127.0.0.0.1:60001 -m 50000 -M 55000 -E -L 7
@]

!!!!! Troubleshoot

First make sure the @@rtpengine@@ daemon is started:
[@
ps -ef | grep rtpengine
@]

If the @@rtpengine@@ daemon does not start, make sure the @@xt_RTPENGINE@@ kernel module is loaded:
[@
lsmod | grep xt_RTPENGINE
@]

If the module is not loaded, make sure the @@ip_tables@@ and @@x_tables@@ kernel modules are loaded. Also, check the logs for the last errors of the system
[@
dmesg
@]

!!!! OpenSIPS

In order to use WebSocket in OpenSIPS, one has to load the [[http://www.opensips.org/html/docs/modules/2.2.x/proto_ws|proto_ws]] into its configuration file and define a listener for the WebSocket protocol.
[@
listen=ws:127.0.0.1:8080
...
loadmodule "proto_ws.so"
@]

Next, the [[http://www.opensips.org/html/docs/modules/2.2.x/rtpengine|rtpengine]] module has to be loaded and configured to communicate with the @@rtpengine@@ daemon.
[@
loadmodule "rtpengine.so"
modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:60000")
@]

Note that the [[http://www.opensips.org/html/docs/modules/2.2.x/rtpengine#rtpengine.p.rtpengine_sock|rtpengine_sock]] parameter should be the same as the @@-n@@ parameter sent to the @@rtpengine@@ daemon, and OpenSIPS should have IP connectivity to that socket.

Next, the routing logic has to be changed in order to treat different the clients that use DTLS-SRTP, from the ones that use plain RTP and enable bridging if necessary. To do that, one can check if the request message was received over the WebSocket protocol. This can be achieved using the following code:

[@
if (proto == WS)
setflag(SRC_WS);
@]

In case the request is a REGISTER, we want to store this information in the ''location'' table, so that we know then the user is called. To do that, we can set a branch flag before calling the [[http://www.opensips.org/html/docs/modules/2.2.x/registrar.html#id294034|save()]] function. This way, when the [[http://www.opensips.org/html/docs/modules/2.2.x/registrar.html#id294366|lookup()]] method returns, we will be able to determine whether the client uses WebSocket or not.

[@
if (is_method("REGISTER"))
{
if (isflagset(SRC_WS))
setbflag(DST_WS);

fix_nated_register();
if (!save("location"))
sl_reply_error();

exit;
}
@]

When a call is placed, based on the two flags (@@STR_WS@@ and @@DST_WS@@) we can determine what our caller and callee can "speak" (either RTP or DTLS-SRTP) and instruct the @@rtpengine@@ daemon how to handle the call. We can do that by tuning the parameters passed to the [[http://www.opensips.org/html/docs/modules/2.2.x/rtpengine#rtpengine.f.rtpengine_offer|rtpengine_offer()]] function.
[@
if (isflagset(SRC_WS) && isbflagset(DST_WS))
$var(rtpengine_flags) = "ICE=force-relay DTLS=passive";
else if (isflagset(SRC_WS) && !isbflagset(DST_WS))
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
else if (!isflagset(SRC_WS) && isbflagset(DST_WS))
$var(rtpengine_flags) = "UDP/TLS/RTP/SAVPF ICE=force";
else if (!isflagset(SRC_WS) && !isbflagset(DST_WS))
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";

rtpengine_offer("$var(rtpengine_flags)");
@]

The [[http://www.opensips.org/html/docs/modules/2.2.x/rtpengine#rtpengine.f.rtpengine_answer|rtpengine_answer()]] function logic should look like this:

[@
if (isflagset(SRC_WS) && isbflagset(DST_WS))
$var(rtpengine_flags) = "ICE=force-relay DTLS=passive";
else if (isflagset(SRC_WS) && !isbflagset(DST_WS))
$var(rtpengine_flags) = "UDP/TLS/RTP/SAVPF ICE=force";
else if (!isflagset(SRC_WS) && isbflagset(DST_WS))
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
else if (!isflagset(SRC_WS) && !isbflagset(DST_WS))
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";

rtpengine_answer("$var(rtpengine_flags)");
@]

Now, all we have to do is to close the RTP/SRTP session when the call is ended. To do that, we use the [[http://www.opensips.org/html/docs/modules/2.2.x/rtpengine#rtpengine.f.rtpengine_delete|rtpengine_delete()]] function:

[@
if (is_method("BYE|CANCEL")) {
rtpengine_delete();
@]

Having done all these settings should provide a full setup for interconnecting SIP clients over both UDP, TCP, etc. protocols, as well as browser based SIP clients over WebSocket.

!!! Configuration file

The following configuration file is a minimal working example of a Residential script that can handle clients connections over both UDP and Websocket transports.

[@
#
# OpenSIPS residential configuration script
# by OpenSIPS Solutions <team@opensips-solutions.com>
#
# Please refer to the Core CookBook at:
# http://www.opensips.org/Resources/DocsCookbooks
# for a explanation of possible statements, functions and parameters.
#


####### Global Parameters #########

debug=3
log_stderror=no
log_facility=LOG_LOCAL0

fork=yes
children=4
auto_aliases=no

listen=udp:127.0.0.0:5060 # TODO: update with your local IP and port
listen=ws:127.0.0.0:8080 # TODO: update with your local IP and port

####### Modules Section ########

# set module path
mpath="/usr/local/lib/opensips/modules/"

#### SIGNALING module
loadmodule "signaling.so"

#### StateLess module
loadmodule "sl.so"

#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 5)
modparam("tm", "fr_inv_timeout", 30)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)

#### Record Route Module
loadmodule "rr.so"
modparam("rr", "append_fromtag", 0)

#### MAX ForWarD module
loadmodule "maxfwd.so"

#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"

#### FIFO Management Interface
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)

#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)

#### USeR LOCation module
loadmodule "usrloc.so"
modparam("usrloc", "nat_bflag", "NAT")
modparam("usrloc", "db_mode", 0)

#### REGISTRAR module
loadmodule "registrar.so"

#### RTPengine protocol
loadmodule "rtpengine.so"
modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.0:60000")

#### Nathelper protocol
loadmodule "nathelper.so"
modparam("registrar|nathelper", "received_avp", "$avp(rcv)")

#### UDP protocol
loadmodule "proto_udp.so"

#### WebSocket protocol
loadmodule "proto_ws.so"


####### Routing Logic ########

# main request routing logic
route{
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}

if (has_totag()) {
# sequential requests within a dialog should
# take the path determined by record-routing
if (loose_route()) {

if (is_method("INVITE")) {
# even if in most of the cases is useless, do RR for
# re-INVITEs alos, as some buggy clients do change route set
# during the dialog.
record_route();
}

# route it out to whatever destination was set by loose_route()
# in $du (destination URI).
route(relay);
} else {

if ( is_method("ACK") ) {
if ( t_check_trans() ) {
# non loose-route, but stateful ACK; must be an ACK after
# a 487 or e.g. 404 from upstream server
t_relay();
exit;
} else {
# ACK without matching transaction ->
# ignore and discard
exit;
}
}
sl_send_reply("404","Not here");
}
exit;
}

# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans())
t_relay();
exit;
}

t_check_trans();

if (!is_method("REGISTER")) {
if (from_uri!=myself) {
# if caller is not local, then called number must be local
if (!uri==myself) {
send_reply("403","Rely forbidden");
exit;
}
}
}

# preloaded route checking
if (loose_route()) {
xlog("L_ERR",
"Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
if (!is_method("ACK"))
sl_send_reply("403","Preload Route denied");
exit;
}

# record routing
if (!is_method("REGISTER|MESSAGE"))
record_route();

if (!uri==myself) {
append_hf("P-hint: outbound\r\n");
route(relay);
}

# requests for my domain
if (is_method("PUBLISH|SUBSCRIBE"))
{
sl_send_reply("503", "Service Unavailable");
exit;
}

# check if the clients are using WebSockets
if (proto == WS)
setflag(SRC_WS);

# consider the client is behind NAT - always fix the contact
fix_nated_contact();

if (is_method("REGISTER"))
{
# indicate that the client supports DTLS
# so we know when he is called
if (isflagset(SRC_WS))
setbflag(DST_WS);

fix_nated_register();
if (!save("location"))
sl_reply_error();

exit;
}

if ($rU==NULL) {
# request with no Username in RURI
sl_send_reply("484","Address Incomplete");
exit;
}

# do lookup with method filtering
if (!lookup("location","m")) {
t_newtran();
t_reply("404", "Not Found");
exit;
}

route(relay);
}


route[relay] {
# for INVITEs enable some additional helper routes
if (is_method("INVITE")) {
t_on_branch("handle_nat");
t_on_reply("handle_nat");
} else if (is_method("BYE|CANCEL")) {
rtpengine_delete();
}

if (!t_relay()) {
send_reply("500","Internal Error");
};
exit;
}


branch_route[handle_nat] {

if (!is_method("INVITE") || !has_body("application/sdp"))
return;

if (isflagset(SRC_WS) && isbflagset(DST_WS))
$var(rtpengine_flags) = "ICE=force-relay DTLS=passive";
else if (isflagset(SRC_WS) && !isbflagset(DST_WS))
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
else if (!isflagset(SRC_WS) && isbflagset(DST_WS))
$var(rtpengine_flags) = "UDP/TLS/RTP/SAVPF ICE=force";
else if (!isflagset(SRC_WS) && !isbflagset(DST_WS))
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";

rtpengine_offer("$var(rtpengine_flags)");
}


onreply_route[handle_nat] {

fix_nated_contact();
if (!has_body("application/sdp"))
return;

if (isflagset(SRC_WS) && isbflagset(DST_WS))
$var(rtpengine_flags) = "ICE=force-relay DTLS=passive";
else if (isflagset(SRC_WS) && !isbflagset(DST_WS))
$var(rtpengine_flags) = "UDP/TLS/RTP/SAVPF ICE=force";
else if (!isflagset(SRC_WS) && isbflagset(DST_WS))
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
else if (!isflagset(SRC_WS) && !isbflagset(DST_WS))
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";

rtpengine_answer("$var(rtpengine_flags)");
}
@]

Page last modified on April 15, 2019, at 07:34 AM