Linphone UPnP

From the beginning, SIP has not been designed  to take into account IP addressing of equipments behind a Nated network.

Problem statement

The main challenge for SIP user agents behind  natted routers are IP/PORT associations maintained by routers from private IP/PORT to public IP/PORT port. This association enable a SIP server to reuse sockets initiated by a SIP client during registration for the purpose of notifying incoming calls. Usually, this association timeout after a fews tens of seconds without traffic on UDP while it can remains for tens of minutes for TCP. A typical workaround used by both SIP clients and SIP servers when UDP is mandatory is to initiate keep alives between client and server to refresh router IP/PORT association. rfc5626 describes some possible implementations. Even if keep alives are perfectly efficient when SIP clients are hosted on a plugged PC, they become a significant issue for mobile devices which need to stay in standby most of the time to save battery. This is why most of SIP clients on mobile devices have adopted SIP TCP as a replacement of SIP UDP. Notice this is even mandatory on IOS because Apple does not allow UDP sockets for background tasks.In case SIP UDP is still mandatory, UPnP Internet Device Gateway Protocol is a solution to fix NAT issue without keep alives. UPnP IDG is a protocol implemented by many routers to enable client applications to open an IP/PORT association. Starting from 3.6, Linphone leverages on this protocol for UDP NAT traversal.

Linphone implementation

UPnP mode can be activated using LinphonePolicyUseUpnp firewall policy with functionlinphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol) . With this mode selected, once network is detected up, liblinphone start searching for a UPnP IDG compatible devices and try to get an association for its local SIP port. Completion of this initial step is either mandatory for initiating registration or skipped after a timeout according to liblinphone configuration entry [sip] register_only_when_upnp_is_ok. Default value is TRUE. In case of a successful association, Linphone uses router allocated IP/PORT as address of record for the Contact header of SIP REGISTER messages. UPnP association may also be used for fixing SDP. If liblinphone configuration entry [rtp] disable_upnp is set to FALSE, associations for RTP ports are also requested for each call. In such case, SDP is filled with public IP/PORT allocated by the router. Else, only the SDP Connection field is set with the public ip address. With some router, using UPnP for RTP ports may slow down calls establishment because it requires between 2 and 4 associations (I.E audio rtp +audio rtcp + video rtp + video rtcp).

Previous news | View all news | Next news