{"id":294,"date":"2010-05-31T08:27:51","date_gmt":"2010-05-31T06:27:51","guid":{"rendered":""},"modified":"2018-11-01T11:15:01","modified_gmt":"2018-11-01T10:15:01","slug":"sip-over-nat","status":"publish","type":"post","link":"https:\/\/nil.uniza.sk\/en\/sip-over-nat\/","title":{"rendered":"Sip over NAT"},"content":{"rendered":"<blockquote>\n<div><cite><strong>If you use the article, please cite me:<\/strong><\/cite><\/div>\n<div><cite>SIP over NAT [SIP cez NAT] \/ Pavel Sege\u010d. In: Journal of  Information, Control and Management Systems. &#8211; ISSN 1336-1716. &#8211; Vol. 7,  No. 1 (2009), p. 89-95.<\/cite><\/div>\n<\/blockquote>\n<div style=\"text-align: justify;\"><strong>Abstract<\/strong><\/div>\n<div style=\"text-align: justify;\"><em>Session Initiation Protocol is one  of key IP communication protocols which will probably change the way  how we will communicate in the future. SIP offer a simple way how to  extend data computer networks with multimedia capabilities and services.  And if we taking into account that the standard is mature with many  successful products offered on the market, free or commercial, there is  no surprise that its implementations is increasing around the world and  affecting all kind of IP networks and segments. But the main principles  of the SIP and way how it works and how it establish communication  collides with one very import factor of modern IP networks, the  security. Security is often omitted factor of an IP networks, but with  the global availability of IP nets and IP services is achieving its  important. The implementation of multimedia capabilities provided by the  SIP into a secured network is not straightforward. In this article we  provide an introduction to SIP networks and Network Address Translation  (NAT) functions and we focusing on the way how the NAT affects SIP  communications, explaining some of the solutions that are available for  NAT traversal with SIP.<\/em><\/div>\n<div style=\"text-align: justify;\"><em><strong>Keywords<\/strong><\/em>:  SIP, VoIP, NAT, firewall, communication, STUN, TURN<\/div>\n<h1>&nbsp;<\/h1>\n<div style=\"text-align: justify;\">\n<h1>1 INTRODUCTION TO SIP<\/h1>\n<\/div>\n<div style=\"text-align: justify;\">\nThe Session Initiation Protocol  (SIP) is an IP based application protocol that has been developed by  IETF [1] as a signaling protocol for multimedia communications  established over IP network. SIP provides signaling and control  functionality for a large range of multimedia communications. The main  functions are: location of parties, invitation to service sessions, and  negotiation of session parameters as other signaling protocols. To  accomplish this, SIP uses a small number of text-based signaling  messages, which are exchanged between the SIP entities.<\/div>\n<h2 style=\"text-align: justify;\">1.1 SIP architecture<\/h2>\n<div style=\"text-align: justify;\">\nSIP define some functional  entities, which all have their specific task and allows to establish SIP  based communication infrastructure, which provides to their users  personal, terminal and service mobility.<br \/>\n<strong>User agent: <\/strong>The  UA represents the main end system, which initiate sessions between two  or more UAs. UA consist from a requester of a session, the User Agent  Client (UAC) and responder of a session, the User Agent Server (UAS).<br \/>\n<strong>Registrar:<\/strong>  A registrar receives registration requests sent by the UAC. These  requests include the temporary SIP address, the permanent SIP address  (SIP Uniform Resource Identifier (URI)) of the UAC and the IP address of  the UA. The Registrar keeps this location information so UA can be  reached under its permanent SIP-URI.<br \/>\n<strong>Proxy:<\/strong> A proxy  server receives messages for other entities (UA), processes and then  forwards them to an appropriate location. It is located on the way  between two user agents. Its main task is message routing.<br \/>\n<strong>Redirect  server:<\/strong> The main task of a redirect server is to provide to  the initiator of the call a list of alternative contact SIP addresses,  where the call should be redirected. But the redirect server does not  forward messages.<br \/>\n<strong>Back-to-back User Agent:<\/strong> A B2BUA  is a SIP device that receives a SIP request, reformulates it, and then  sends it out as a new request. Responses to the new request are also  reformulated and sent back out in the opposite direction.<\/div>\n<h2 style=\"text-align: justify;\">\n1.2 SIP signalization<\/h2>\n<div style=\"text-align: justify;\">SIP is protocol, where the clients  (UAC) send requests which are answered by a response generated by the  servers (UAS). The session between UAs consists from the sets of text  coded messages. A SIP message consists of the start line, the header, a  blank line and the body. The header consists from more header fields,  where each header field contain name of the header field, value of the  field, names of parameters and its values. The body can be leaved blank,  or it may contain session description defined by Session Description  Protocol (SDP), or it can contain some other content (image, text,  Quality of Service (QoS) parameters [2], etc.). There are two types of  SIP messages: Requests (or Methods) and Responses. Requests are  generated by clients and its receiving usually starts some processing on  the server side. A result is send back using kind of Response message.<\/div>\n<h1 style=\"text-align: justify;\">2 INTRODUCTION TO NETWORK ADDRESS  TRANSLATION (NAT)<\/h1>\n<div style=\"text-align: justify;\">\nNetwork Address Translation (NAT)  is the technique of modifying network address information (Layer 3) and  port information (Layer 4) in packet headers (L3 PDU) while it is  traversing a traffic routing device (NAT) for the purpose of remapping a  given source addresses into another address space. The most typical  implementation of the NAT is used to connect stub networks and their IP  hosts which are using private IP network ranges (inside) and allow them  to access and interact with publicly routed IP networks and its hosts  (outside). Dynamic NAT techniques usually allows traffic traverse from  inside to outside, back only if the connection was initiated from  inside. NAT was developed as a technique which helps to solve public IP  address crises. But NAT obscures an internal network&#8217;s structure (all  traffic appears to outside parties as it originates from the one host or  smaller number of hosts as it is in reality) also so it is usually used  as the first and simplest method of securing IP network.<\/div>\n<h2 style=\"text-align: justify;\">2.1 Types of NAT<\/h2>\n<div style=\"text-align: justify;\">\nThere are 4 types of NAT [3]:<br \/>\n<strong>Full  cone: <\/strong>The simplest implementation. Once an internal address  and port (iAddr:port1) is mapped to an external address (eAddr:port2),  any packets from iAddr:port1 will be sent through eAddr:port2. Any  external host can send packets to iAddr:port1 by sending packets to  eAddr:port2.<br \/>\n<strong>Address-Restricted cone:<\/strong> as above, but  the NAT device is maintaining a list of allowed connections from  originating devices inside. So if external device wants sent packet to  inside host, connection must be initiated from inside host first.<\/div>\n<div style=\"text-align: justify;\"><strong>Port-Restricted cone: <\/strong>As  Address-Restricted described above, to the address is applied port  restrictions. <strong>Symmetric NAT:<\/strong> Each request from the same  internal IP address and port to a specific destination IP address and  port is mapped to a unique external source IP address and port. If the  same internal host sends a packet even with the same source address and  port but to a different destination, a different mapping is used. Only  an external host that receives a packet from an internal host can send a  packet back.<\/div>\n<div style=\"text-align: justify;\">\n<h1>&nbsp;<\/h1>\n<\/div>\n<div style=\"text-align: justify;\">\n<h1>3 UNDERSTANDING PROBLEMS WITH SIP MULTIMEDIA AND NAT<\/h1>\n<\/div>\n<div style=\"text-align: justify;\">\nSIP is a protocol that was  designed to work hand in hand with other core Internet protocols and  many functions in a SIP-based network rely upon complementary protocols,  including IP. Since SIP itself only defines the initiation of a  session, all other parts of the session are covered by other protocols.  The SIP session is described in two levels. The SIP itself contains the  parties&#8216; addresses (caller and callee SIP URIs) and protocol processing  features, but the description of the media streams exchanged between the  parties of a session is defined by another protocol. The SDP [4] is  used for this. The SDP is not a protocol in its sense, but rather a  structured, text-based media description format that can be carried in  the SIP message body. SDP is used to handle the session negotiation  process within a SIP transaction. An SDP message is often carried as the  message body of a SIP request. For the media transport itself is used  another protocol &ndash; the RealTime Transport Protocol (RTP) [6].<br \/>\nThere  have been developed some guidelines from IETF for application protocol  design to make them more NAT friendly [5], but the document was  published sooner as was SIP and SDP specified. Unfortunately, SIP  violates most of these guidelines, e.g. one of the major recommendations  is that the application layer protocols should not transport IP  addresses and port numbers inside of their messages. This makes SIP  great complications when NAT (or firewall) are introduced. Look at the  following example. The session starts by generating SIP INVITE [Fig.1.]  request by a Caller, from behind a NAT. The SDP offer is carried inside,  detailing a number of characteristics that define the proposed session  (such as media and codec types (or media capabilities of the caller),  contact information, IP address and ports to be used). The parameters  are used for media delivery between parties with help of the RTP over  UDP. There is a private address carried inside of Via header field,  inside Contact header field and inside of the SDP message too [Fig.1].<\/div>\n<div style=\"text-align: center;\"><img decoding=\"async\" width=\"350\" height=\"396\" style=\"vertical-align: top;\" src=\"http:\/\/www.kis.fri.uniza.sk\/images\/stories\/clanky\/segec\/SIP-message.png\" alt=\"SIP-message\" \/><\/div>\n<div style=\"text-align: justify;\">Transition of the SIP message through  the NAT cause translation of L3 private IP address inside packet header,  potentially also L4 port number, but IP addresses inside the SIP header  fields and SDP will stay untouched. The session will not be established  because:<\/p>\n<ul>\n<li>The response to this request (200OK) from the Callee could not be  routed back (based on an incorrect Via header) to the Caller because of  the inability to route this private IP address (private range defined  for use on private internal networks).<\/li>\n<li>Future requests of this session, as Re-INVITE and BYE, would be  misrouted, caused by incorrect Contact header field with private IP  address.<\/li>\n<li>RTP packets sent by Callee would be misrouted and media exchange  will not start because connection IP address used for RTP media inside  of SDP field c= is private.<\/li>\n<\/ul>\n<\/div>\n<h1 style=\"text-align: justify;\">4 NAT TRAVERSAL SOLUTIONS<\/h1>\n<div style=\"text-align: justify;\">\nThere are several approaches  possibly used for NAT traversal to solve situations mentioned above [7]:<\/p>\n<ul>\n<li>Modification of SIP signaling, without changing anything in existing  firewalls and NATs.<\/li>\n<li>Modifications to firewalls and NATs so as to make them SIP-aware  NAT.<\/li>\n<li>Firewall traversal using Simple Traversal of UDP through NAT  (STUN), and Traversal Using Relay around NAT (TURN).<\/li>\n<\/ul>\n<\/div>\n<h2 style=\"text-align: justify;\">4.1 Modification of SIP signaling<\/h2>\n<div style=\"text-align: justify;\">\nThe answer to the problem of  misrouting of SIP messages based on Via header containing private IP  address has potentially simple solution inside of SIP. A proxy server or  UA receiving this request would compare the IP address in the Via  header to the source IP address from which the packet was received. If  they are different (they would be if there is a NAT), the correct public  IP address is added to the Via header with a received= parameter. This  public IP address would be used to route the SIP response successfully  back to the NAT, the NAT maintains the same binding between the private  IP address and public IP address and forward the message to the Caller.<br \/>\nProblem  with misrouting of future messages which comes from outside, for  example when session is closing with BYE, could be solved by a  persistent TCP connection, which is permanently open during whole  session. This does not work with UDP, where NAT will filter UDP segments  coming from outside direction because no translation was found.<br \/>\nSolution  to the problem with RTP media session is not easy. One functional  solution is to use the technique known as Symmetrical RTP [8], where RTP  packets using the same UDP port for transmitting and receiving. This is  because RTP and RTCP are not inherently bidirectional protocols, and  UDP is not a bidirectional protocol. This solution should work in  situations, where one endpoint is behind NAT (not both), so the SDP of  the endpoint outside of NAT contains a correct public, routable IP  address and port number and flow in at least one direction is possible.  The use of symmetric RTP would make the recipient of the successful RTP  stream outside to use the received IP address and port number to send  RTP back, ignoring the private IP address in the SDP (which is not  routable).<\/div>\n<h2 style=\"text-align: justify;\">4.2 Simple Traversal of UDP through NAT  (STUN)<\/h2>\n<div style=\"text-align: justify;\">\nSTUN is the IETF standardized  solution [9], which helps to solve the NAT traversal problem. As the  name suggests, STUN is a simple protocol that allows a UA to discover if  it is behind a NAT, what type of NAT it is and what its public IP  address and port is. STUN is using a special entity called STUN server,  which is placed on the public Internet. The UA, which is behind NAT have  to supports STUN protocol and must be configured with or discover  somehow a STUN public IP address (for example using SRV DNS records).  The UA than initiate to open secured connection to the STUN server  (using Shared secret key and TLS) and starts to send STUN packets  directed to a STUN server. The STUN server response the UA and tell it  the public IP address and port that the STUN server received from the  STUN requests. If the sent and received addresses and ports are the  same, there is no NAT. If they are different IP addresses, there is a  NAT between them. So if there is a situation where a UA behind a NAT is  trying to talk to another UA that has a public IP address, through STUN a  UA knows that have to modify all the parts of a SIP and SDP message  with the correct public IP address (Via, Contact and SDP c header  fields).<br \/>\nSTUN does not work if there is a Symmetric NAT, because as  was mentioned, this kind of NAT each request from the same internal IP  address and port to a specific destination IP address and port is mapped  to a unique external source IP address and port, so there is different  mapping for communications between the UA and the STUN server and  another between the UAs themselves. STUN does not work also if both ends  of the SIP and media session are behind NATs. For this, TURN may be  used.<\/div>\n<h2 style=\"text-align: justify;\">\n4.3 Traversal Using Relay around  NAT (TURN)<\/h2>\n<div style=\"text-align: justify;\">The TURN protocol is not published as  the IETF RFC standard yet, but is semifinished as the IETF draft [10].  TURN is a protocol that allows a UA which is behind NAT directly  communicate with other peers located behind other NATs [10]. For this  purpose TURN is also using a special entity, TURN server, which is  placed on the public Internet and which is inserted into the signaling  and media path and acts as a communication relay. TURN protocol allows  the UA to control the operation of the relay and to exchange packets  with its peers using the relay. The TURN supported UA, which is behind  NAT must be configured through some means with the TURN server public IP  address. To this address will UA sends TURN command messages used to  allocate the public relayed transport IP address and port on the TURN  server (the relay). If the UA wants send data to its peer, it will send  it to the server on the obtained relay transport address and TURN server  (the relay), which know from who is the data coming (from the  allocation process), will unambiguously relay it towards UAs peers. In  the reverse direction, peers can send data to the relayed transport  address of the UA. The server will relay this data to the UA as long as  the client explicitly created permission for the IP address of the peer.<\/div>\n<div style=\"text-align: justify;\">\n<h1>5 CONCLUSION<\/h1>\n<\/div>\n<div style=\"text-align: justify;\">Today&rsquo;s IP network administrators have  many possibilities how to extend theirs pure IP data networks with new  IP-based voice and multimedia capabilities and services. Unfortunately,  there are some technical problems which complicate multimedia  implementations and prevent to realize these multimedia networking  benefits. One of the most significant of these is NAT techniques used to  provide secure connection to users behind NAT and firewalls. The NAT  and firewalls breaks the SIP signaling and complicates media delivery.  To solve this situation there are the IETF solutions STUN and TURN.<\/div>\n<h1 style=\"text-align: justify;\">REFERENCES<\/h1>\n<div style=\"text-align: justify;\">[1] ROSENBERG, J., SCHULZRINNE, H.,  CAMARILLO, G., JOHNSTON, A., PETERSON, J., SPARKS, R., HANDLEY, M.,  SCHOOLER, E.: SIP: Session Initiation Protocol, RFC 3261, July 2002<br \/>\n[2]  KLIMO. M, BACHRAT&Aacute;, K.:Impact of correlated samples loss on VoIP  quality [Vplyv korelovan&yacute;ch str&aacute;t na kvalitu VoIP], In: Scientific  Papers of the University of Pardubice : Series B &#8211; The Jan Perner  Transport Faculta 11 (2005). &#8211; Pardubice: University of Pardubice, 2006.  &#8211; ISBN 80-7194-605-2<br \/>\n[3]  http:\/\/en.wikipedia.org\/wiki\/Network_Address_Translation<br \/>\n[4] HANDLEY,  J.: SDP: Session Description Protocol, RFC 2327, April 1998<br \/>\n[5]  SENIE, D., Network Address Translator (NAT)-Friendly Application Design  Guidelines, RFC3235, January 2002<br \/>\n[6] SCHULZRINNE, H., CASNER, S.,  FREDERICK, R., JACOBSON, V.: RTP &ndash; A Transport Protocol for Real Time  Applications, RFC3550, July 2003<br \/>\n[7] SINNREICH, H., JOHNSTON, A.:  Internet Communications Using SIP: Delivering VoIP and Multimedia  Services with Session Initiation Protocol, Second edition, Wiley  Publishing Inc., ISBN: 978-0-471-77657-4<br \/>\n[8] WING, D.: Symmetric RTP \/  RTP Control Protocol (RTCP), RFC4961, July 2007<br \/>\n[9] ROSENBERG, J.,  WEINBERGER, J., HUITEMA, C..: STUN &#8211; Simple Traversal of User Datagram  Protocol (UDP) Through Network Address Translators (NATs), RFC 3489,  March 2003<br \/>\n[10] ROSENBERG, J., MAHY, R., MATTHEWS, P.: &quot;Traversal  Using Relays around NAT (TURN): Relay Extensions to Session Traversal  Utilities for NAT (STUN)&quot;, draft-ietf-behave-turn-09 (work in progress),  July 2008.<\/div>","protected":false},"excerpt":{"rendered":"<blockquote>\n<div><cite><strong>If you use the article, please cite me:<\/strong><\/cite><\/div>\n<div><cite>SIP over NAT [SIP cez NAT] \/ Pavel Sege\u010d. In: Journal of  Information, Control and Management Systems. &#8211; ISSN 1336-1716. &#8211; Vol. 7,  No. 1 (2009), p. 89-95.<\/cite><\/div>\n<\/blockquote>\n<div style=\"text-align: justify;\"><strong>Abstract<\/strong><\/div>","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[783],"tags":[],"class_list":["post-294","post","type-post","status-publish","format-standard","hentry","category-nat-fw"],"taxonomy_info":{"category":[{"value":783,"label":"NAT, FW"}]},"featured_image_src_large":false,"author_info":{"display_name":"admin","author_link":"https:\/\/nil.uniza.sk\/en\/author\/admin\/"},"comment_info":7,"category_info":[{"term_id":783,"name":"NAT, FW","slug":"nat-fw","term_group":0,"term_taxonomy_id":781,"taxonomy":"category","description":"","parent":771,"count":5,"filter":"raw","cat_ID":783,"category_count":5,"category_description":"","cat_name":"NAT, FW","category_nicename":"nat-fw","category_parent":771}],"tag_info":false,"_links":{"self":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/comments?post=294"}],"version-history":[{"count":0,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/posts\/294\/revisions"}],"wp:attachment":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/media?parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/categories?post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/tags?post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}