<div dir="ltr"><div>Hello,</div><div><br></div><div>I hope somebody could help me.<br></div><div><br></div><div>This is my scheme. <br></div><div>User-agent is behind NAT1. Kamailio and pbx are behind NAT2<br></div><div>[Client ip-phone 192.168.89.213 without stun] - LAN1 - NAT1(46.0.0.30) - (internet) - (51.0.0.60)NAT2 - Local2 - (10.130.0.23:5060)kamailio(<a href="http://10.130.0.23:5070" target="_blank">10.130.0.23:5070</a>) - pbx</div><div><br></div><div></div><div><b>Questions</b>:<br></div><div><b>1</b>. The VIA header (with 10.130.0.23 and 51.0.0.60) wasn't included in SIP packets.  Why? For example 200OK reply. It came from pbx through kamailio. Which setting could break it?</div><div><br></div><div>Session Initiation Protocol (200)<br>    Status-Line: SIP/2.0 200 OK<br>    Message Header<br>        Via: SIP/2.0/UDP 192.168.89.213:5060;rport=9570;received=46.0.0.30;branch=z9hG4bK2480172053<br>        Record-Route: <sip:c172.19.19.111.8348.call.cgatepro;lr><br>        Record-Route: <sip:172.19.19.111:5060;lr><br>        Record-Route: <sip:10.130.0.23:5070;r2=on;lr;ftag=4268683942;nat=yes>,<sip:51.0.0.60;r2=on;lr;ftag=4268683942;nat=yes><br>        From: "Aleksey" <<a href="http://sip:a.yakimkin@mail.domain.ru:5060" target="_blank">sip:a.yakimkin@mail.domain.ru:5060</a>>;tag=4268683942<br>        To: <<a href="http://sip:2961@mail.domain.ru:5060" target="_blank">sip:2961@mail.domain.ru:5060</a>>;tag=A03E2397-404246-FA7543E4_jizmelr-582D<br>        Call-ID: <a href="mailto:6_1903330087@192.168.89.213" target="_blank">6_1903330087@192.168.89.213</a><br>        [Generated Call-ID: <a href="mailto:6_1903330087@192.168.89.213" target="_blank">6_1903330087@192.168.89.213</a>]<br>        CSeq: 2 INVITE<br>        Contact: <<a href="mailto:sip%3Asignode-404246-FA7543E4_jizmelr-582D@172.19.19.111" target="_blank">sip:signode-404246-FA7543E4_jizmelr-582D@172.19.19.111</a>;alias=51.0.0.60~5060~1><br>        Supported: 100rel,timer,replaces,histinfo,precondition<br>        Allow: INVITE,BYE,CANCEL,ACK,OPTIONS,INFO,MESSAGE,PRACK,UPDATE,REFER<br>        Session-Expires: 1800;refresher=uas<br>        Content-Type: application/sdp<br>        Content-Length: 1170<br>    Message Body</div><div><br></div><div><br></div><div><b>2</b>. About Registrar, Path and $du. <br></div><div>Phone set Register with headers:</div><div>                                    Via: SIP/2.0/UDP 192.168.89.213:5060;branch=z9hG4bK2691182696<br>        From: "Aleksey" <<a href="http://sip:a.yakimkin@mail.domain.ru:5060">sip:a.yakimkin@mail.domain.ru:5060</a>>;tag=3926879477<br>        To: "Aleksey" <<a href="http://sip:a.yakimkin@mail.domain.ru:5060">sip:a.yakimkin@mail.domain.ru:5060</a>><br>        Contact: <<a href="http://sip:a.yakimkin@192.168.89.213:5060">sip:a.yakimkin@192.168.89.213:5060</a>><br>Kamailio respond<br>        Via: SIP/2.0/UDP 192.168.89.213:5060;rport=9570;received=46.0.0.30;branch=z9hG4bK617463686<br>        Path: <sip:10.130.0.23:5070;lr;received=46.0.0.30~9570~1;r2=on>,<sip:51.0.0.60;lr;received=46.0.0.30~9570~1;r2=on><br>        From: "Aleksey" <<a href="http://sip:a.yakimkin@mail.domain.ru:5060">sip:a.yakimkin@mail.domain.ru:5060</a>>;tag=3926879477<br>        To: "Aleksey" <<a href="http://sip:a.yakimkin@mail.domain.ru:5060">sip:a.yakimkin@mail.domain.ru:5060</a>>;tag=194ED16D<br>        Contact: <<a href="http://sip:a.yakimkin@192.168.89.213:5060">sip:a.yakimkin@192.168.89.213:5060</a>>;expires=360<br>        Contact: <<a href="http://sip:2447@192.168.89.221:5060">sip:2447@192.168.89.221:5060</a>>;expires=247<br>        Contact: <<a href="http://sip:2447@192.168.9.16:5060">sip:2447@192.168.9.16:5060</a>>;expires=2116</div><div><br></div><div>I try to make a call from pbx to ip phone. <br></div><div>pbx inserts in Invite header Route: <sip:10.130.0.23:5070;lr;received=46.0.0.30~9570~1;r2=on></div><div>But kamailio relayed Invite direct to 192.168.89.213. (There is network connectivity  between ip-phone and kamailio  through vpn). The code below helps me to solve my issue. I saw mail-list with similar trouble. But no setting could get kamailio to relay Invite to "Route-received" ip.<br></div><div><br></div><div><br></div><div>        $var(the_route) = $hdr(Route);<br>        $var(route0) = $(var(the_route){s.select,0,,});<br>        $var(new_host) = $(var(route0){param.value,received}{s.select,0,~});<br>        $var(new_port) = $(var(route0){param.value,received}{s.select,1,~});<br>        if (!strempty($var(new_host)) && !strempty($var(new_port)) ) {<br>                $du = "sip:" + $var(new_host) + ":" + $var(new_port);   <br>        } <br></div><div><br></div><div><b>Kamailio settings:</b></div><div><div>I have such listeners</div><div>listen=udp:<a href="http://10.130.0.23:5070" target="_blank">10.130.0.23:5070</a> # to local network<br>listen=udp:<a href="http://10.130.0.23:5060" target="_blank">10.130.0.23:5060</a> advertise <a href="http://51.0.0.60:5060" target="_blank">51.0.0.60:5060</a> # to internet</div><div><br></div><div>#MODULE SETTING</div><div>#---<br></div><div># ----- jsonrpcs params -----<br>modparam("jsonrpcs", "pretty_format", 1)<br>/* set the path to RPC fifo control file */<br># modparam("jsonrpcs", "fifo_name", "/var/run/kamailio/kamailio_rpc.fifo")<br>/* set the path to RPC unix socket control file */<br># modparam("jsonrpcs", "dgram_socket", "/var/run/kamailio/kamailio_rpc.sock")<br><br>modparam("path", "use_received", 1)<br>modparam("path", "enable_r2", 1)<br>modparam("path", "received_format", 1)<br><br># ----- ctl params -----<br>/* set the path to RPC unix socket control file */<br># modparam("ctl", "binrpc", "unix:/var/run/kamailio/kamailio_ctl")<br><br># ----- tm params -----<br># auto-discard branches from previous serial forking leg<br>modparam("tm", "failure_reply_mode", 3)<br># default retransmission timeout: 30sec<br>modparam("tm", "fr_timer", 30000)<br># default invite retransmission timeout after 1xx: 120sec<br>modparam("tm", "fr_inv_timer", 120000)<br>modparam("tm", "auto_inv_100_reason", "Trying")<br><br># ----- rr params -----<br># set next param to 1 to add value to ;lr param (helps with some UAs)<br>modparam("rr", "enable_full_lr", 0)<br># do not append from tag to the RR (no need for this script)<br>modparam("rr", "append_fromtag", 1)<br>modparam("rr", "enable_double_rr", 2)<br>modparam("rr", "force_send_socket", 1)<br><br># ----- registrar params -----<br>modparam("registrar", "method_filtering", 1)<br>/* uncomment the next line to disable parallel forking via location */<br># modparam("registrar", "append_branches", 0)<br>/* uncomment the next line not to allow more than 10 contacts per AOR */<br># modparam("registrar", "max_contacts", 10)<br>/* max value for expires of registrations */<br>modparam("registrar", "max_expires", 3600)<br>/* set it to 1 to enable GRUU */<br>modparam("registrar", "gruu_enabled", 0)<br></div><div><br></div><div>modparam("registrar", "use_path", 1)<br>modparam("registrar", "path_use_received", 1)<br>modparam("registrar", "path_mode", 0)</div><div>#---<br></div><div><br></div><div>For register I use this code</div><div>route[REGISTRAR] {</div><div>...<br></div><div>add_path_received();<br>       set_send_socket("udp:<a href="http://10.130.0.23:5070" target="_blank">10.130.0.23:5070</a>");<br>route(DISPATCH);</div><div>...</div><div>}</div><div>route[RELAY] {</div><div>...<br>        if ($Ru eq "sip:<a href="http://10.130.0.23:5070" target="_blank">10.130.0.23:5070</a>") {<br>                $fs = "udp:<a href="http://10.130.0.23:5060" target="_blank">10.130.0.23:5060</a>";<br>        } else {<br>                $fs = "udp:<a href="http://10.130.0.23:5070" target="_blank">10.130.0.23:5070</a>";<br>        }</div><div>...</div><div>}</div><div>route[NATMANAGE] {<br>#!ifdef WITH_NAT<br>        if (is_request()) {<br>                if(has_totag()) {<br>                        if(check_route_param("nat=yes")) {<br>                                setbflag(FLB_NATB);<br>                        }<br>                }<br>        }<br>        if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))) return;<br></div><div>        <br></div><div>        #send INVITE to IP:PROT from Route:...;received=</div><div>        $var(the_route) = $hdr(Route);<br>        $var(route0) = $(var(the_route){s.select,0,,});<br>        $var(new_host) = $(var(route0){param.value,received}{s.select,0,~});<br>        $var(new_port) = $(var(route0){param.value,received}{s.select,1,~});<br>        if (!strempty($var(new_host)) && !strempty($var(new_port)) ) {<br>                $du = "sip:" + $var(new_host) + ":" + $var(new_port);   <br>        }<br></div><div>        if (client_nat_test("3")) {<br><br>                if(nat_uac_test("18")) {<br>                        if ($Ru == "sip:<a href="http://10.130.0.23:5070" target="_blank">10.130.0.23:5070</a>") {<br>                                rtpproxy_manage("co", "51.0.0.60"); # fix_nated_sdp<br>                        } else {<br>                                rtpproxy_manage("co");<br>                        }<br><br>                        if (is_method("REGISTER")) {<br>                                #if ($Ru == "sip:<a href="http://10.130.0.23:5070" target="_blank">10.130.0.23:5070</a>") {<br>                                #       fix_nated_contact();<br>                                #} else {<br>                                #       set_contact_alias();<br>                                #}<br>                                set_contact_alias();<br>                        } else {<br>                                if(is_first_hop()) {<br>                                        set_contact_alias();<br>                                } else {<br>                                        add_contact_alias("51.0.0.60", "5060", "udp");<br>                                        #fix_nated_contact();<br>                                }<br>                        }<br>                } else {<br>                        if ($Ru == "sip:<a href="http://10.130.0.23:5070" target="_blank">10.130.0.23:5070</a>") {<br>                                rtpproxy_manage("cor", "51.0.0.60"); # fix_nated_sdp<br>                        } else {<br>                                rtpproxy_manage("cor");<br>                        }<br>                }<br>        } else {<br>                rtpproxy_manage("co");<br>        }</div><div>        if (is_request()) {<br>                if (!has_totag()) {<br>                        if(t_is_branch_route()) {<br>                                add_rr_param(";nat=yes");<br>                                #fix_contact();<br>                        }<br>                }<br>        }<br>        if (is_reply()) {<br>                if(isbflagset(FLB_NATB)) {<br>                        if(is_first_hop())<br>                                set_contact_alias();<br>                        #} else {<br>                                #fix_contact();<br>                        #}<br>                }<br>        }<br>#!endif<br>        return;<br>}</div></div><div><br></div><div>Thank you.</div><div><br></div><div>-- <br><div dir="ltr" data-smartmail="gmail_signature">Best regards,</div><div dir="ltr" data-smartmail="gmail_signature">Alex<br></div></div></div>