{"id":358,"date":"2010-12-02T14:07:41","date_gmt":"2010-12-02T13:07:41","guid":{"rendered":""},"modified":"2019-11-19T10:08:45","modified_gmt":"2019-11-19T09:08:45","slug":"configuring-nat-traversal-using-kamailio-31-and-rtpproxy-server","status":"publish","type":"post","link":"https:\/\/nil.uniza.sk\/en\/configuring-nat-traversal-using-kamailio-31-and-rtpproxy-server\/","title":{"rendered":"Configuring NAT traversal using Kamailio 3.1 and the Rtpproxy server"},"content":{"rendered":"<p>This article continues on series of articles about the Kamailio 3.1.x   SIP proxy server deployed on the debian lenny and its features. In previous   articles we have focused on:<\/p>\n<p>1) <a href=\"..\/..\/..\/..\/..\/..\/installing-kamailio-31-debian-lenny\">installing clear Kamailio 3.1.x server&nbsp;<\/a><\/p>\n<p>2) <a href=\"..\/..\/..\/..\/..\/..\/sip\/kamailio\/adding-mysql-support-kamailio-31-debian-lenny\">adding of the Mysql support <\/a>for persistance location storage<\/p>\n<p>3) <a href=\"..\/..\/..\/..\/..\/..\/sip\/kamailio\/installing-siremis-20-kamailio-web-management-interface-debian-lenny-how\">installing of the SIREMIS web management interface for our Kamailio server<\/a>.<\/p>\n<p>4) <a href=\"https:\/\/nil.uniza.sk\/en\/instant-messaging\/simple\/configuring-im-and-presence-kamailio-31-howto\/\">configuring the IM and presence service on Kamailio 3.1 &#8211; Howto<\/a><\/p>\n<p>5) <a href=\"https:\/\/nil.uniza.sk\/en\/instant-messaging\/simple\/configuring-xcap-support-im-and-presence-over-kamailio-31-debian-lenny\/\">configuring the XCAP support for SIMPLE<\/a>.<\/p>\n<p>6) <a href=\"https:\/\/nil.uniza.sk\/en\/sip\/kamailio\/configuring-tls-support-kamailio-31-howto\/\">configuring TLS support<\/a><\/p>\n<p>Now we will take a closer look on the NAT traversal solution with the usage of the Rtpproxy server.<\/p>\n<h2>Prerequisities<\/h2>\n<p>1) Installed and working <a rel=\"nofollow\" title=\"http:\/\/www.kamailio.org\" class=\"urlextern\" href=\"http:\/\/www.kamailio.org\/\">Kamailio (OpenSER) 3.1.0<\/a>&nbsp;server.<\/p>\n<p>2) <a href=\"https:\/\/nil.uniza.sk\/en\/sip\/nat-fw\/rtpproxy-server-debian-lenny\/\">Installed and running<\/a> rtpproxy server. For this guide (as you see at the end, rtpproxy 1.2.1 does not work, 1.1.2 does)<\/p>\n<p>3) <a href=\"http:\/\/www.kamailio.org\/docs\/modules\/stable\/modules_k\/usrloc.html\">usrloc (user location) module<\/a> of the kamailio loaded<\/p>\n<h2>&nbsp;Configuration<\/h2>\n<p>Kamailio 3.1 has for the NAT&nbsp;traversal preconfigured zone block prepared for the the rtpproxy server usage. So open \/etc\/kamailio\/kamailio.cfg and find lines starting with:<\/p>\n<pre># *** To enable nat traversal execute:\n#     - define WITH_NAT\n#     - install RTPProxy: http:\/\/www.rtpproxy.org\n#     - start RTPProxy:\n#        rtpproxy -l _your_public_ip_ -s udp:localhost:7722\n<\/pre>\n<p>They recommends to define &#8222;WITH_NAT&#8220; directive and to install rtpproxy with recommended parameters. We have rtpproxy already installed, thus we need to define the zone block directive only<\/p>\n<pre>#!define WITH_NAT\n<\/pre>\n<p>Going next, in module loading part of the config file, we may find zone block:<\/p>\n<pre>#!ifdef WITH_NAT\nloadmodule \"nathelper.so\"\nloadmodule \"rtpproxy.so\"\n#!endif\n<\/pre>\n<p>which will load modules (<a href=\"http:\/\/www.kamailio.org\/docs\/modules\/stable\/modules_k\/nathelper.html\">nathelper <\/a>and <a href=\"http:\/\/www.kamailio.org\/docs\/modules\/stable\/modules_k\/rtpproxy.html\">rtpproxy<\/a>) required for the NAT traversal,&nbsp; conditional of the WITH_NAT directive defined. We did it in previous step, so following modules will be loaded during the next restart of the Kamailio server.<\/p>\n<p>Going next, in module param section of the kamailio.cfg we will find zone block:<\/p>\n<pre>#!ifdef WITH_NAT\n# ----- rtpproxy params -----\nmodparam(\"rtpproxy\", \"rtpproxy_sock\", \"udp:127.0.0.1:<span style=\"background-color:#FFFF99;\">7722<\/span>\")\n\n# ----- nathelper params -----\nmodparam(\"nathelper\", \"natping_interval\", 30)\nmodparam(\"nathelper\", \"ping_nated_only\", 1)\nmodparam(\"nathelper\", \"sipping_bflag\", FLB_NATSIPPING)\nmodparam(\"nathelper\", \"sipping_from\", \"sip:pinger@kamailio.org\")\n\n# params needed for NAT traversal in other modules\nmodparam(\"nathelper|registrar\", \"received_avp\", \"$avp(RECEIVED)\")\nmodparam(\"usrloc\", \"nat_bflag\", FLB_NATB)\n#!endif\n<\/pre>\n<p>This part of the Kamailio config file we have to modify slightly. Our topology is using the Kamamilio and the Rtpproxy running in the same machine, and they will communicate between each other using the localhost IP&nbsp;address. So, if we are using the Rtpproxy server with default configuration, we have to open \/etc\/default\/rtpproxy file and uncomment following line regarding of udp socket, that will be sued for interconnection:<\/p>\n<pre>CONTROL_SOCK=udp:127.0.0.1:22222\n<\/pre>\n<p>and than we have to modify first modparam line from above kamailio.cfg block to reflect the actual rtpproxy configuration:<\/p>\n<pre>modparam(\"rtpproxy\", \"rtpproxy_sock\", \"udp:127.0.0.1:<span style=\"background-color:#FFFF99;\">22222<\/span>\")<\/pre>\n<p>Next line of the configuration,&nbsp;<em>modparam(&#8222;nathelper&#8220;, &#8222;natping_interval&#8220;, 30)<\/em> define<em> <\/em>in seconds how often NAT ping will be send to keep NAT binding opened, here 30second. We do not need to modify it.<\/p>\n<p>Line <em>modparam(&#8222;nathelper&#8220;, &#8222;ping_nated_only&#8220;, 1)<\/em> define, that only SIP&nbsp;UAs which are behind NAT&nbsp;will be pinged. We do not need to modify it.<\/p>\n<p>Line <em>modparam(&#8222;nathelper&#8220;, &#8222;sipping_bflag&#8220;, FLB_NATSIPPING)<\/em><em> <\/em>define which branch flag of nat-ed client will be used for nat pinging. We do not need to modify it. By default the 7th flag is set and is named FLB_NATSIPPING, we may find it in&nbsp; ####### Defined Values ######### part of the kamailo.cfg<\/p>\n<pre># - flags\n#&nbsp;&nbsp; FLT_ - per transaction (message) flags\n#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FLB_ - per branch flags\n#!define FLT_ACC 1\n#!define FLT_ACCMISSED 2\n#!define FLT_ACCFAILED 3\n#!define FLT_NATS 5\n#!define FLB_NATB 6\n<span style=\"background-color: rgb(255, 255, 153);\">#!define FLB_NATSIPPING 7<\/span><\/pre>\n<p>Tutorial about Kamailio flags is available at <a href=\"http:\/\/www.kamailio.org\/dokuwiki\/doku.php\/tutorials:openser-flag-operations\">the link<\/a>. Currently there are 31 tags defined, which can be named (like here).<\/p>\n<p>&nbsp;<\/p>\n<p>Next line<em> modparam(&#8222;nathelper&#8220;, &#8222;sipping_from&#8220;, &#8222;sip:pinger@kamailio.org&#8220;)<\/em>&nbsp; I will change to reflect my server DNS&nbsp;name:<\/p>\n<pre>modparam(\"nathelper\", \"sipping_from\", \"sip:pinger@ps.sip.uniza.sk\")<\/pre>\n<p>Line <em>modparam(&#8222;nathelper|registrar&#8220;, &#8222;received_avp&#8220;, &#8222;$avp(RECEIVED)&#8220;)<\/em> define, I cited module documentation:<\/p>\n<blockquote><p><em>name of the Attribute-Value-Pair (AVP) used to store the URI  \t\tcontaining the received IP, port, and protocol. The URI is created  \t\tby fix_nated_register function of nathelper module and the attribute  \t\tis then used by the registrar to store the received parameters. Do  \t\tnot forget to change the value of corresponding parameter in \t\tregistrar module if you change the value of this parameter. \t\t<\/em><\/p><\/blockquote>\n<p>Line <em>modparam(&#8222;usrloc&#8220;, &#8222;nat_bflag&#8220;, FLB_NATB)<\/em>&nbsp; tell to the <em>usrloc <\/em>module to save branch parameter, that will be used as the NAT marker (decide if the contact  \t\tis or not natted). This is a branch flag and it will be imported and  \t\tused by nathelper module.<\/p>\n<h3>Route logic<\/h3>\n<h4>route[NAT]<\/h4>\n<p>The first routing logic which is working with NAT traversal is the <em>route [NAT]<\/em> called from the main route logic. <em>route [NAT] <\/em>detects if a caller is behind a NAT. It is used for all methods which are generated from an UAC.<\/p>\n<pre># Caller NAT detection route\nroute[NAT] {\n#!ifdef WITH_NAT\n        force_rport();\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (nat_uac_test(\"19\")) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (method==\"REGISTER\") {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fix_nated_register();\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fix_nated_contact();\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setflag(FLT_NATS);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\n#!endif\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;\n}\n<\/pre>\n<p>Function <a href=\"http:\/\/www.kamailio.org\/dokuwiki\/doku.php\/core-cookbook:3.0.x#force_rport\">force_rport()<\/a> adds the rport parameter to the first Via header of the received message. <a href=\"http:\/\/tools.ietf.org\/html\/rfc3581\">Rport parameters <\/a>cause that proxy will send subsequence responses back to this source port (this is the &#8222;public&#8220; port after NAT-ing).<\/p>\n<p>Then inside of the logic test if UAC is behind NAT is done (<a href=\"http:\/\/www.kamailio.org\/docs\/modules\/stable\/modules_k\/nathelper.html#id2753635\">nat_uac_test(&#8222;19&#8220;)<\/a>), from the docu 19 = 1 + 2 + 16 (i.e.<\/p>\n<div class=\"itemizedlist\">\n<ul>\n<li><span style=\"background-color: rgb(255, 255, 153);\"><span class=\"emphasis\"><em>1<\/em><\/span> &#8211;  Contact header field is searched  \t\t\tfor occurrence of RFC1918 addresses. \t\t\t<\/span><\/li>\n<li><span style=\"background-color: rgb(255, 255, 153);\"> \t\t\t<span class=\"emphasis\"><em>2<\/em><\/span> &#8211;  the &#8222;received&#8220; test is used: address \t\t\tin Via is compared against source IP address of signaling \t\t\t<\/span><\/li>\n<li><span class=\"emphasis\"><em>4<\/em><\/span> &#8211;  Top Most VIA is searched  \t\t\tfor occurrence of RFC1918 addresses<\/li>\n<li><span class=\"emphasis\"><em>8<\/em><\/span> &#8211;  SDP is searched for occurrence of  \t\t\tRFC1918 addresses<\/li>\n<li><span style=\"background-color: rgb(255, 255, 153);\"><span class=\"emphasis\"><em>16<\/em><\/span> &#8211;  test if the source port is different \t\t\tfrom the port in Via  \t\t\t<\/span><\/li>\n<li><span class=\"emphasis\"><em>32<\/em><\/span> &#8211;  test if the source IP address of \t\t\tsignaling is a RFC1918 address<\/li>\n<\/ul>\n<\/div>\n<p>)<\/p>\n<p>and if the SIP&nbsp;method is REGISTER, the function <em>fix_nated_register()<\/em> creates a URI consisting of the source IP, port, and  \t\tprotocol and stores the URI in an Attribute-Value-Pair ($avp(RECEIVED) in our case). The registrar will store the URI in the received column inside of the location table.<\/p>\n<p>Otherwise the Contact header field of the SIP message will be rewritten to contain request&#8217;s source  \t\taddress:port (fix_nated_contact()).<\/p>\n<p>As the last step, the flag FLT_NATS is setted up to one as a mark that NATing is used.<\/p>\n<h4>Registration handling &#8211; route [REGISTRAR]<\/h4>\n<p>During the UA registration the registrar have to adjust flags indicating that a client is behind a NAT and to save branch param. Registrar has to setup B flag also, which is used by the nathelper module.<\/p>\n<p>Route logic executed during a registation is by default:<\/p>\n<pre># Handle SIP registrations\nroute[REGISTRAR] {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (is_method(\"REGISTER\"))\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(isflagset(FLT_NATS))\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setbflag(FLB_NATB);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # uncomment next line to do SIP NAT pinging\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ## setbflag(FLB_NATSIPPING);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!save(\"location\"))\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sl_reply_error();\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\n}\n<\/pre>\n<p>and we have to uncomment the line:<\/p>\n<pre>setbflag(FLB_NATSIPPING);<\/pre>\n<p>to start pinging the NAT performed by the nathelper module (performed if FLB_NATSIPPING is setted up).<\/p>\n<p>The server during the registration phase check if the 5th flag is set (line <em>isflagset(FLT_NATS)<\/em>), and since it is (setted up in <em>route[NAT]<\/em>), as a next step the Branch flag named FLB_NATB is set (the 5th flag), together with the flag FLB_NATSIPPING (7th flag) (nat pinging required). Branch param will be saved to (usrloc) and logic execution is stopped.<\/p>\n<p>The module responsible for working with Kamailio flags is <a href=\"http:\/\/www.kamailio.org\/docs\/modules\/3.0.x\/modules_k\/kex.html\">KEx module<\/a>.<\/p>\n<h4>Dialog initialization &#8211; route [RELAY]<\/h4>\n<p>This route logic is called few times:<\/p>\n<ul>\n<li>for methods which does not contain &#8222;to_tag&#8220;,\n<ul>\n<li>it is usually during dialog initialization (it is from the second route[RELAY] of the main route logic),<\/li>\n<li>or for methods that are statefully relayed to the destination (interdomain call),<\/li>\n<li>or for methods for local domain users<\/li>\n<\/ul>\n<\/li>\n<li>and then it is called again for messages exchanged within dialog.<\/li>\n<\/ul>\n<p>From the NAT traversal point of view the logic setup the branch flag and if prerequsities for detecting NAT is fulfilled it call the rtpproxy logic<\/p>\n<pre>route[RELAY] {\n<span style=\"background-color: rgb(255, 255, 153);\">#!ifdef WITH_NAT\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (check_route_param(\"nat=yes\")) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setbflag(FLB_NATB);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (isflagset(FLT_NATS) || isbflagset(FLB_NATB)) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; route(RTPPROXY);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\n#!endif<\/span>\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/* example how to enable some additional event routes *\/\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (is_method(\"INVITE\")) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #t_on_branch(\"BRANCH_ONE\");\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t_on_reply(\"REPLY_ONE\");\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t_on_failure(\"FAIL_ONE\");\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!t_relay()) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sl_reply_error();\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit;\n}&nbsp;<\/pre>\n<h4>The rtpproxy logic<\/h4>\n<p>The logic is called from the RELAY route and it is used to rewrite private addresses inside of the SDP body (<em>force_rtp_proxy()<\/em>) of the message or at the end of a call to close down a RTPproxy session.<\/p>\n<pre># RTPProxy control\nroute[RTPPROXY] {\n#!ifdef WITH_NAT\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (is_method(\"BYE\")) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unforce_rtp_proxy();\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else if (is_method(\"INVITE\")){\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; force_rtp_proxy();\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!has_totag()) add_rr_param(\";nat=yes\");\n#!endif\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;\n}\n\n<\/pre>\n<h2>&nbsp;Testing<\/h2>\n<p>This testing was done for the Kamailio 3.1 and the Rtpproxy 1.2.1<\/p>\n<h3>UAC behind nat without NAT traversal support on Kamailio<\/h3>\n<p>Usrloc record made for registration of the Client behind nat looks like:<\/p>\n<pre>AOR:: jan\n                Contact:: sip:jan@10.0.2.15 Q=\n                        Expires:: 3441\n                        Callid:: zbkhwyxuwuthbgv@bell.netlab.kis.fri.uniza.sk\n                        Cseq:: 224\n                        User-agent:: Twinkle\/1.4.2\n                        State:: CS_SYNC\n                        Flags:: 0\n                        Cflag:: 0\n                        Socket:: udp:158.193.139.51:5060\n                        Methods:: 6111\n<\/pre>\n<p>&nbsp;the REGISTER method received from the UAC behind NAT contain private addresses. The registration process was sucessfull<\/p>\n<pre>REGISTER sip:ps.sip.uniza.sk SIP\/2.0.\nVia: SIP\/2.0\/UDP 10.0.2.15;rport;branch=z9hG4bKwyecvlbs.\nMax-Forwards: 70.\nTo: \"jan\" &lt;sip:jan@ps.sip.uniza.sk&gt;.\nFrom: \"jan\" &lt;sip:jan@ps.sip.uniza.sk&gt;;tag=hxwkx.\nCall-ID: zbkhwyxuwuthbgv@bell.netlab.kis.fri.uniza.sk.\nCSeq: 224 REGISTER.\nContact: &lt;sip:jan@10.0.2.15&gt;;expires=3600.\nAuthorization: Digest username=\"jan\",realm=\"ps.sip.uniza.sk\",nonce=\"TPiqzUz4qaGMhfAopOhr80LB7LZ22p1r\",uri=\"sip:ps.sip.uniza.sk\",response=\"b18c53a210525abb334cff1f28cc0fe7\",algorithm=MD5.\nAllow: INVITE,ACK,BYE,CANCEL,OPTIONS,PRACK,REFER,NOTIFY,SUBSCRIBE,INFO,MESSAGE.\nUser-Agent: Twinkle\/1.4.2.\nContent-Length: 0.\n.\n\n\nU 158.193.139.51:5060 -&gt; 158.193.139.235:60361\nSIP\/2.0 200 OK.\nVia: SIP\/2.0\/UDP 10.0.2.15;rport=60361;branch=z9hG4bKwyecvlbs;received=158.193.139.235.\nTo: \"jan\" &lt;sip:jan@ps.sip.uniza.sk&gt;;tag=f11c829fa10fd0f1cba4621773c131eb.1e7c.\nFrom: \"jan\" &lt;sip:jan@ps.sip.uniza.sk&gt;;tag=hxwkx.\nCall-ID: zbkhwyxuwuthbgv@bell.netlab.kis.fri.uniza.sk.\nCSeq: 224 REGISTER.\nContact: &lt;sip:jan@10.0.2.15&gt;;expires=3600.\nServer: kamailio (3.1.0 (x86_64\/linux)).\nContent-Length: 0.&nbsp;<\/pre>\n<h3>UAC behind nat with NAT traversal support on Kamailio<\/h3>\n<p>Now we will start the kamailio with NAT support and we will observe the changes.<\/p>\n<p>The Usrloc is changed a &nbsp;little be, Received parameter was added and the Cflag is changed:<\/p>\n<pre>AOR:: jan\n                Contact:: sip:jan@10.0.2.15 Q=\n                        Expires:: 3586\n                        Callid:: zbkhwyxuwuthbgv@bell.netlab.kis.fri.uniza.sk\n                        Cseq:: 234\n                        User-agent:: Twinkle\/1.4.2\n                        <span style=\"background-color: rgb(255, 255, 153);\">Received:: sip:158.193.139.235:62055 <\/span>                        State:: CS_NEW\n                        Flags:: 0\n                        Cflag:: 192\n                        Socket:: udp:158.193.139.51:5060\n                        Methods:: 6111\n<\/pre>\n<p>During of the register message exchange, inside of the 200 Ok message the <em>received <\/em>parameter is inserted<\/p>\n<pre>REGISTER sip:ps.sip.uniza.sk SIP\/2.0.\nVia: SIP\/2.0\/UDP 10.0.2.15;rport;branch=z9hG4bKskrtfzbd.\nMax-Forwards: 70.\nTo: \"jan\" &lt;sip:jan@ps.sip.uniza.sk&gt;.\nFrom: \"jan\" &lt;sip:jan@ps.sip.uniza.sk&gt;;tag=dohaq.\nCall-ID: zbkhwyxuwuthbgv@bell.netlab.kis.fri.uniza.sk.\nCSeq: 234 REGISTER.\nContact: &lt;sip:jan@10.0.2.15&gt;;expires=3600.\nAuthorization: Digest username=\"jan\",realm=\"ps.sip.uniza.sk\",nonce=\"TPitRkz4rBoh5k2qVS7QRyL9FjFXuI1Y\",uri=\"sip:ps.sip.uniza.sk\",response=\"d807146af45f4ce248738f6b7fe4d411\",algorithm=MD5.\nAllow: INVITE,ACK,BYE,CANCEL,OPTIONS,PRACK,REFER,NOTIFY,SUBSCRIBE,INFO,MESSAGE.\nUser-Agent: Twinkle\/1.4.2.\nContent-Length: 0.\n.\n\n\nU 158.193.139.51:5060 -&gt; 158.193.139.235:62055\nSIP\/2.0 200 OK.\nVia: SIP\/2.0\/UDP 10.0.2.15;rport=62055;branch=z9hG4bKskrtfzbd;received=158.193.139.235.\nTo: \"jan\" &lt;sip:jan@ps.sip.uniza.sk&gt;;tag=f11c829fa10fd0f1cba4621773c131eb.36d7.\nFrom: \"jan\" &lt;sip:jan@ps.sip.uniza.sk&gt;;tag=dohaq.\nCall-ID: zbkhwyxuwuthbgv@bell.netlab.kis.fri.uniza.sk.\nCSeq: 234 REGISTER.\nContact: &lt;sip:jan@10.0.2.15&gt;;expires=3600;<span style=\"background-color: rgb(255, 255, 153);\">received=\"sip:158.193.139.235:62055\".<\/span>\nServer: kamailio (3.1.0 (x86_64\/linux)).\nContent-Length: 0.\n\n<\/pre>\n<p>Registration was sucesfull (as usually).<\/p>\n<h3>Call from public UA<\/h3>\n<p>The INVITE message arrived to the server, signalling works, media does&#8217;t<\/p>\n<pre>T 158.193.139.192:49260 -&gt; 158.193.139.51:5060 [AP]\nINVITE sip:jan@ps.sip.uniza.sk SIP\/2.0.\nVia: SIP\/2.0\/TCP 158.193.139.192:49918;branch=z9hG4bK-d8754z-975d22393e6c4702-1---d8754z-;rport.\nMax-Forwards: 70.\nContact: &lt;sip:jojo@158.193.139.192:49260;transport=TCP&gt;.\nTo: &lt;sip:jan@ps.sip.uniza.sk&gt;.\nFrom: \"jojo\"&lt;sip:jojo@ps.sip.uniza.sk&gt;;tag=73203c66.\nCall-ID: N2M1MTc4MzAyNjI4ZTViZTA1NDE5MjAzZDc4ZWU3NjA..\nCSeq: 2 INVITE.\nAllow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO.\nContent-Type: application\/sdp.\nProxy-Authorization: Digest username=\"jojo\",realm=\"ps.sip.uniza.sk\",nonce=\"TPizQUz4shXsqLjd3BfmYyVrrljigrVn\",uri=\"sip:jan@ps.sip.uniza.sk\",response=\"60829a1aaccdd15f8d183c3f98f32277\",algorithm=MD5.\nSupported: replaces.\nUser-Agent: Bria Professional release 2.4 stamp 49381.\nContent-Length: 451.\n.\nv=0.\no=- 5 2 IN IP4 158.193.139.192.\ns=CounterPath Bria Professional.\nc=IN IP4 158.193.139.192.\nt=0 0.\nm=audio 27460 RTP\/AVP 107 119 100 106 0 98 8 18 101.\na=fmtp:18 annexb=yes.\na=fmtp:101 0-15.\na=rtpmap:107 BV32\/16000.\na=rtpmap:119 BV32-FEC\/16000.\na=rtpmap:100 SPEEX\/16000.\na=rtpmap:106 SPEEX-FEC\/16000.\na=rtpmap:98 iLBC\/8000.\na=rtpmap:18 G729\/8000.\na=rtpmap:101 telephone-event\/8000.\na=sendrecv.\na=x-rtp-session-id:8767743075B64036B830760C208977F5.\n\n<\/pre>\n<p>INVITE is redirected to the UA behind a NAT and is sent to <span style=\"background-color: rgb(255, 255, 153);\">158.193.139.235:62055<\/span><\/p>\n<pre>U 158.193.139.51:5060 -&gt; 158.193.139.235:62055\nINVITE sip:<span style=\"background-color: rgb(255, 255, 153);\">jan@10.0.2.15<\/span> SIP\/2.0.\nRecord-Route: &lt;sip:158.193.139.51;r2=on;lr=on;nat=yes&gt;.\nRecord-Route: &lt;sip:158.193.139.51;transport=tcp;r2=on;lr=on;nat=yes&gt;.\nVia: SIP\/2.0\/UDP 158.193.139.51;branch=z9hG4bK45bf.d8da62b.0;i=1.\nVia: SIP\/2.0\/TCP 158.193.139.192:49918;branch=z9hG4bK-d8754z-975d22393e6c4702-1---d8754z-;rport=49260.\nMax-Forwards: 69.\nContact: &lt;sip:jojo@158.193.139.192:49260;transport=TCP&gt;.\nTo: &lt;sip:jan@ps.sip.uniza.sk&gt;.\nFrom: \"jojo\"&lt;sip:jojo@ps.sip.uniza.sk&gt;;tag=73203c66.\nCall-ID: N2M1MTc4MzAyNjI4ZTViZTA1NDE5MjAzZDc4ZWU3NjA..\nCSeq: 2 INVITE.\nAllow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO.\nContent-Type: application\/sdp.\nSupported: replaces.\nUser-Agent: Bria Professional release 2.4 stamp 49381.\nContent-Length: 451.\n.\nv=0.\no=- 5 2 IN IP4 158.193.139.192.\ns=CounterPath Bria Professional.\nc=IN IP4 158.193.139.192.\nt=0 0.\nm=audio 27460 RTP\/AVP 107 119 100 106 0 98 8 18 101.\na=fmtp:18 annexb=yes.\na=fmtp:101 0-15.\na=rtpmap:107 BV32\/16000.\na=rtpmap:119 BV32-FEC\/16000.\na=rtpmap:100 SPEEX\/16000.\na=rtpmap:106 SPEEX-FEC\/16000.\na=rtpmap:98 iLBC\/8000.\na=rtpmap:18 G729\/8000.\na=rtpmap:101 telephone-event\/8000.\na=sendrecv.\na=x-rtp-session-id:8767743075B64036B830760C208977F5.\n\n<\/pre>\n<p>200 Ok came to the server from the client behind NAT<\/p>\n<pre>U 158.193.139.235:62055 -&gt; 158.193.139.51:5060\nSIP\/2.0 200 OK.\nVia: SIP\/2.0\/UDP 158.193.139.51;branch=z9hG4bK45bf.d8da62b.0;i=1,SIP\/2.0\/TCP 158.193.139.192:49918;rport=49260;branch=z9hG4bK-d8754z-975d22393e6c4702-1---d8754z-.\nRecord-Route: &lt;sip:158.193.139.51;r2=on;lr=on;nat=yes&gt;,&lt;sip:158.193.139.51;transport=tcp;r2=on;lr=on;nat=yes&gt;.\nTo: &lt;sip:jan@ps.sip.uniza.sk&gt;;tag=helfk.\nFrom: \"jojo\" &lt;sip:jojo@ps.sip.uniza.sk&gt;;tag=73203c66.\nCall-ID: N2M1MTc4MzAyNjI4ZTViZTA1NDE5MjAzZDc4ZWU3NjA..\nCSeq: 2 INVITE.\nContact: &lt;<span style=\"background-color: rgb(255, 255, 153);\">sip:jan@10.0.2.15&gt;.<\/span>\nContent-Type: application\/sdp.\nAllow: INVITE,ACK,BYE,CANCEL,OPTIONS,PRACK,REFER,NOTIFY,SUBSCRIBE,INFO,MESSAGE.\nServer: Twinkle\/1.4.2.\nSupported: replaces,norefersub.\nContent-Length: 192.\n.\nv=0.\no=twinkle 63212600 546185878 IN IP4 <span style=\"background-color: rgb(255, 255, 153);\">10.0.2.15.<\/span>\ns=-.\nc=IN IP4 <span style=\"background-color: rgb(255, 255, 153);\">10.0.2.15.<\/span>\nt=0 0.\nm=audio 8000 RTP\/AVP 100 101.\na=rtpmap:100 speex\/16000.\na=rtpmap:101 telephone-event\/8000.\na=fmtp:101 0-15. \n<\/pre>\n<p>200 OK is redirected to the calling public UA, contact is rewrited, SDP is not<\/p>\n<pre>T 158.193.139.51:5060 -&gt; 158.193.139.192:49260 [AP]\nSIP\/2.0 200 OK.\nVia: SIP\/2.0\/TCP 158.193.139.192:49918;rport=49260;branch=z9hG4bK-d8754z-975d22393e6c4702-1---d8754z-.\nRecord-Route: &lt;sip:158.193.139.51;r2=on;lr=on;nat=yes&gt;,&lt;sip:158.193.139.51;transport=tcp;r2=on;lr=on;nat=yes&gt;.\nTo: &lt;sip:jan@ps.sip.uniza.sk&gt;;tag=helfk.\nFrom: \"jojo\" &lt;sip:jojo@ps.sip.uniza.sk&gt;;tag=73203c66.\nCall-ID: N2M1MTc4MzAyNjI4ZTViZTA1NDE5MjAzZDc4ZWU3NjA..\nCSeq: 2 INVITE.\nContact: <span style=\"background-color: rgb(255, 255, 153);\">&lt;sip:jan@158.193.139.235:62055&gt;.<\/span>\nContent-Type: application\/sdp.\nAllow: INVITE,ACK,BYE,CANCEL,OPTIONS,PRACK,REFER,NOTIFY,SUBSCRIBE,INFO,MESSAGE.\nServer: Twinkle\/1.4.2.\nSupported: replaces,norefersub.\nContent-Length: 192.\n.\nv=0.\no=twinkle 63212600 546185878 IN IP4 <span style=\"background-color: rgb(255, 153, 0);\">10.0.2.15.<\/span>\ns=-.\nc=IN IP4 <span style=\"background-color: rgb(255, 153, 0);\">10.0.2.15.<\/span>\nt=0 0.\nm=audio 8000 RTP\/AVP 100 101.\na=rtpmap:100 speex\/16000.\na=rtpmap:101 telephone-event\/8000.\na=fmtp:101 0-15.\n<\/pre>\n<h4>Troubleshooting<\/h4>\n<p>The usage of the rtpproxy 1.2.1 leads to some problems, described next. I reccommend, as the working solution, to install rtpproxy 1.1.2 from the main debian repository.<\/p>\n<h5>rtpproxy 1.2.1 built from the git is unusable<\/h5>\n<ol>\n<li>First of all, rtpproxy 1.2.1 built from the git will not start as the service, Caused that \/etc\/init.d\/rtpproxy script is pointing to other folder where  rtpproxy binary is not. Script is pointing to the \/usr\/sbin, but after compilation rtpproxy is in \/usr\/local\/bin.<\/li>\n<li>If we change it, the init.d script\/rtpproxy will find and start the proxy server, but the rtpproxy server when is contacting by the kamailio fell with segmentation fault error<\/li>\n<\/ol>\n<pre>Dec  3 11:29:23 pstest \/usr\/sbin\/kamailio[5567]: ERROR: &lt;core&gt; [tcp_read.c:882]: ERROR: tcp_read_req: error reading\nDec  3 11:29:34 pstest kernel: [1285797.388217] rtpproxy[5529]: <span style=\"background-color: rgb(255, 204, 153);\">segfault at 0 <\/span>ip 409468 sp 7fffe8208d70 error 4 in rtpproxy[400000+f000]<\/pre>\n<h3>Solution<\/h3>\n<p>Go back to the standard rtpproxy debian package version 1.1.2, installed with<\/p>\n<pre>apt-get install rtpproxy\n<\/pre>\n<p>and change \/etc\/default\/rtpproxy to<\/p>\n<pre># Defaults for rtpproxy\n\n# The control socket.\n#CONTROL_SOCK=\"unix:\/var\/run\/rtpproxy\/rtpproxy.sock\"\n# To listen on an UDP socket, uncomment this line:\n\nLISTEN_ADDR=158.193.139.51\nCONTROL_SOCK=\"udp:localhost:22222\"\n\n# Additional options that are passed to the daemon.\nEXTRA_OPTS=\"-l ${LISTEN_ADDR}\"\n<\/pre>\n<p>Setup correctly and restart kamailio&#8230;it work now!!!!<\/p>\n<p>&nbsp;<\/p>\n<p>log tutorial http:\/\/www.kamailio.org\/dokuwiki\/doku.php\/tutorials:debug-syslog-messages<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>This article continues on series of articles about the Kamailio 3.1.x   SIP proxy server deployed on the debian lenny and its features. In previous   articles we have focused on:<\/p>\n<p>1) <a href=\"..\/..\/..\/..\/..\/..\/installing-kamailio-31-debian-lenny\">installing clear Kamailio 3.1.x server&nbsp;<\/a><\/p>\n<p>2) <a href=\"..\/..\/..\/..\/..\/..\/sip\/kamailio\/adding-mysql-support-kamailio-31-debian-lenny\">adding of the Mysql support <\/a>for persistance location storage<\/p>","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-358","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":14,"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\/358","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=358"}],"version-history":[{"count":0,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/posts\/358\/revisions"}],"wp:attachment":[{"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/media?parent=358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/categories?post=358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nil.uniza.sk\/en\/wp-json\/wp\/v2\/tags?post=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}