<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Hi,</p>
    <p>Thanks for all your help, much appreciated. I'll see how I get on
      and will report back.</p>
    <p>Kind regards,</p>
    <p>Iskren<br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 21.7.2017 г. 15:19,
      Daniel-Constantin Mierla wrote:<br>
    </div>
    <blockquote
      cite="mid:4b8d45a2-1c4d-67e4-5caf-699714087616@gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <p>Hello,</p>
      <p>so it seems that FreeSwitch is not handling properly the Path
        header. As you can see, that Path in REGISTER is:</p>
      <p>Path: <a moz-do-not-send="true" class="moz-txt-link-rfc2396E"
href="sip:KAMAILIO_PUBLIC_IP;lr;received=sip:UAC_PUBLIC_IP:5063"><sip:KAMAILIO_PUBLIC_IP;lr;received=sip:UAC_PUBLIC_IP:5063></a><br>
      </p>
      <p>But the INVITE has the ROUTE:</p>
      <p>Route: <a moz-do-not-send="true" class="moz-txt-link-rfc2396E"
          href="sip:KAMAILIO_PUBLIC_IP"><sip:KAMAILIO_PUBLIC_IP></a>;lr;received=<a
          moz-do-not-send="true" class="moz-txt-link-freetext"
          href="sip:UAC_PUBLIC_IP:5063">sip:UAC_PUBLIC_IP:5063</a><br>
      </p>
      <p>The closing '>' is no longer at the end, making lr and
        received header parameters, instead of uri parameters.<br>
      </p>
      If there is nothing easy to fix in freeswitch, you can try to:<br>
        - use add_path() instead of add_path_received()<br>
        - use set_contact_alias() instead of fix_nated_contact() and
      fix_nated_register() and then when the INVITE comes from
      FreeSwitch use handle_ruri_alias()<br>
      <br>
      Because I encountered other sip apps that get confused by the
      value of received parameter in the Path, I added in master branch
      an alternative:<br>
      <br>
        -
      <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="https://www.kamailio.org/docs/modules/devel/modules/path.html#path.p.received_format">https://www.kamailio.org/docs/modules/devel/modules/path.html#path.p.received_format</a><br>
      <br>
      But for this you need to install from git master.<br>
      <br>
      Cheers,<br>
      Daniel<br>
      <br>
      <div class="moz-cite-prefix">On 21.07.17 12:22, Iskren Hadzhinedev
        wrote:<br>
      </div>
      <blockquote type="cite"
        cite="mid:9066e087-3664-cffe-4dc4-c8db1fa1144f@ikiji.com">
        <meta http-equiv="Content-Type" content="text/html;
          charset=utf-8">
        <font face="Calibri">Hi Daniel,<br>
          Yes, those headers are extracted from a wireshark pcap.<br>
          Yes, kamailio is listening on a public IP address without any
          sort of NAT.<br>
          <br>
          Here's the REGISTER sent from kamailio to FreeSWITCH, copied
          from a pcap using wireshark with IPs replaced:<br>
          <br>
        </font><tt>Session Initiation Protocol (REGISTER)</tt><tt><br>
        </tt><tt>    Request-Line: REGISTER <a
            class="moz-txt-link-freetext" href="sip:sip.test.com:5060"
            moz-do-not-send="true">sip:sip.test.com:5060</a> SIP/2.0</tt><tt><br>
        </tt><tt>        Method: REGISTER</tt><tt><br>
        </tt><tt>        Request-URI: <a class="moz-txt-link-freetext"
            href="sip:sip.test.com:5060" moz-do-not-send="true">sip:sip.test.com:5060</a></tt><tt><br>
        </tt><tt>            Request-URI Host Part: sip.test.com</tt><tt><br>
        </tt><tt>            Request-URI Host Port: 5060</tt><tt><br>
        </tt><tt>        [Resent Packet: False]</tt><tt><br>
        </tt><tt>    Message Header</tt><tt><br>
        </tt><tt>        Record-Route: <a class="moz-txt-link-rfc2396E"
            href="sip:KAMAILIO_PUBLIC_IP;lr=on;ftag=1015994109"
            moz-do-not-send="true"><sip:KAMAILIO_PUBLIC_IP;lr=on;ftag=1015994109></a></tt><tt><br>
        </tt><tt>        Via: SIP/2.0/UDP
          KAMAILIO_PUBLIC_IP;branch=z9hG4bKb4a9.4cbfa8e6cdc8083ffe5ff1ea228fea26.0</tt><tt><br>
        </tt><tt>        Via: SIP/2.0/UDP
192.168.1.200:5063;rport=5063;received=UAC_PUBLIC_IP;branch=z9hG4bK332629336</tt><tt><br>
        </tt><tt>        From: <a class="moz-txt-link-rfc2396E"
            href="sip:1001@sip.test.com" moz-do-not-send="true"><sip:1001@sip.test.com></a>;tag=1015994109</tt><tt><br>
        </tt><tt>        To: <a class="moz-txt-link-rfc2396E"
            href="sip:1001@sip.test.com" moz-do-not-send="true"><sip:1001@sip.test.com></a></tt><tt><br>
        </tt><tt>        Call-ID: <a class="moz-txt-link-abbreviated"
            href="mailto:1821101462@192.168.1.200"
            moz-do-not-send="true">1821101462@192.168.1.200</a></tt><tt><br>
        </tt><tt>        CSeq: 1 REGISTER</tt><tt><br>
        </tt><tt>        Contact: <a class="moz-txt-link-rfc2396E"
            href="sip:1001@192.168.1.200:5063" moz-do-not-send="true"><sip:1001@192.168.1.200:5063></a></tt><tt><br>
        </tt><tt>        Allow: INVITE, INFO, PRACK, ACK, BYE, CANCEL,
          OPTIONS, NOTIFY, REGISTER, SUBSCRIBE, REFER, PUBLISH, UPDATE,
          MESSAGE</tt><tt><br>
        </tt><tt>        Max-Forwards: 69</tt><tt><br>
        </tt><tt>        User-Agent: Yealink SIP-T42G 29.72.23.5</tt><tt><br>
        </tt><tt>        Expires: 3600</tt><tt><br>
        </tt><tt>        Allow-Events:
          talk,hold,conference,refer,check-sync</tt><tt><br>
        </tt><tt>        Content-Length: 0</tt><tt><br>
        </tt><tt>        Path: <a class="moz-txt-link-rfc2396E"
            href="sip:KAMAILIO_PUBLIC_IP;lr;received=sip:UAC_PUBLIC_IP:5063"
            moz-do-not-send="true"><sip:KAMAILIO_PUBLIC_IP;lr;received=sip:UAC_PUBLIC_IP:5063></a></tt><tt><br>
        </tt><tt>            Path URI: <a class="moz-txt-link-freetext"
href="sip:KAMAILIO_PUBLIC_IP;lr;received=sip:UAC_PUBLIC_IP:5063"
            moz-do-not-send="true">sip:KAMAILIO_PUBLIC_IP;lr;received=sip:UAC_PUBLIC_IP:5063</a></tt><tt><br>
        </tt><tt>                Path Host Part: KAMAILIO_PUBLIC_IP</tt><tt><br>
        </tt><tt>                Path URI parameter: lr</tt><tt><br>
        </tt><tt>                Path URI parameter: received=<a
            class="moz-txt-link-freetext" href="sip:UAC_PUBLIC_IP:5063"
            moz-do-not-send="true">sip:UAC_PUBLIC_IP:5063</a></tt><tt><br>
        </tt><font face="Calibri"><br>
          And this is the test INVITE from FreeSWITCH to kamailio:<br>
          <br>
        </font><tt>Session Initiation Protocol (INVITE)</tt><tt><br>
        </tt><tt>    Request-Line: INVITE <a
            class="moz-txt-link-freetext"
            href="sip:1001@192.168.1.200:5063" moz-do-not-send="true">sip:1001@192.168.1.200:5063</a>
          SIP/2.0</tt><tt><br>
        </tt><tt>    Message Header</tt><tt><br>
        </tt><tt>        Via: SIP/2.0/UDP
          FREESWITCH_PUBLIC_IP;rport;branch=z9hG4bK543jg8S9Ng8gm</tt><tt><br>
        </tt><tt>        Route: <a class="moz-txt-link-rfc2396E"
            href="sip:KAMAILIO_PUBLIC_IP" moz-do-not-send="true"><sip:KAMAILIO_PUBLIC_IP></a>;lr;received=<a
            class="moz-txt-link-freetext" href="sip:UAC_PUBLIC_IP:5063"
            moz-do-not-send="true">sip:UAC_PUBLIC_IP:5063</a></tt><tt><br>
        </tt><tt>        Max-Forwards: 70</tt><tt><br>
        </tt><tt>        From: "" <a class="moz-txt-link-rfc2396E"
            href="sip:0000000000@FREESWITCH_PUBLIC_IP"
            moz-do-not-send="true"><sip:0000000000@FREESWITCH_PUBLIC_IP></a>;tag=DyFB81r40609Q</tt><tt><br>
        </tt><tt>        To: <a class="moz-txt-link-rfc2396E"
            href="sip:1001@192.168.1.200:5063" moz-do-not-send="true"><sip:1001@192.168.1.200:5063></a></tt><tt><br>
        </tt><tt>        Call-ID: fad5ae53-e89d-1235-d8b5-00163e50ea42</tt><tt><br>
        </tt><tt>        CSeq: 109979488 INVITE</tt><tt><br>
        </tt><tt>        Contact: <a class="moz-txt-link-rfc2396E"
            href="sip:mod_sofia@FREESWITCH_PUBLIC_IP:5060"
            moz-do-not-send="true"><sip:mod_sofia@FREESWITCH_PUBLIC_IP:5060></a></tt><tt><br>
        </tt><tt>        User-Agent: FreeSWITCH-1.6.9-16-d574870~64bit</tt><tt><br>
        </tt><tt>        Allow: INVITE, ACK, BYE, CANCEL, OPTIONS,
          MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH,
          SUBSCRIBE</tt><tt><br>
        </tt><tt>        Supported: timer, path, replaces</tt><tt><br>
        </tt><tt>        Allow-Events: talk, hold, conference, presence,
          as-feature-event, dialog, line-seize, call-info, sla,
          include-session-description, presence.winfo, message-summary,
          refer</tt><tt><br>
        </tt><tt>        Content-Type: application/sdp</tt><tt><br>
        </tt><tt>        Content-Disposition: session</tt><tt><br>
        </tt><tt>        Content-Length: 319</tt><tt><br>
        </tt><tt>        X-FS-Support: update_display,send_info</tt><tt><br>
        </tt><tt>    Message Body</tt><tt><br>
        </tt><tt>        Session Description Protocol</tt><tt><br>
        </tt><tt>            Session Description Protocol Version (v): 0</tt><tt><br>
        </tt><tt>            Owner/Creator, Session Id (o): FreeSWITCH
          1500611681 1500611682 IN IP4 FREESWITCH_PUBLIC_IP</tt><tt><br>
        </tt><tt>            Session Name (s): FreeSWITCH</tt><tt><br>
        </tt><tt>            Connection Information (c): IN IP4
          FREESWITCH_PUBLIC_IP</tt><tt><br>
        </tt><tt>            Time Description, active time (t): 0 0</tt><tt><br>
        </tt><tt>            Media Description, name and address (m):
          audio 19424 RTP/AVP 9 0 8 3 101 13</tt><tt><br>
        </tt><tt>            Media Attribute (a): rtpmap:9 G722/8000</tt><tt><br>
        </tt><tt>            Media Attribute (a): rtpmap:0 PCMU/8000</tt><tt><br>
        </tt><tt>            Media Attribute (a): rtpmap:8 PCMA/8000</tt><tt><br>
        </tt><tt>            Media Attribute (a): rtpmap:3 GSM/8000</tt><tt><br>
        </tt><tt>            Media Attribute (a): rtpmap:101
          telephone-event/8000</tt><tt><br>
        </tt><tt>            Media Attribute (a): fmtp:101 0-16</tt><tt><br>
        </tt><tt>            Media Attribute (a): rtpmap:13 CN/8000</tt><tt><br>
        </tt><tt>            Media Attribute (a): ptime:20</tt><tt><br>
        </tt><font face="Calibri"><br>
          As always, thanks for all your help!<br>
          <br>
          Kind regards,<br>
        </font>
        <div class="moz-signature">
          <meta http-equiv="content-type" content="text/html;
            charset=utf-8">
          <div class="moz-signature">
            <meta http-equiv="content-type" content="text/html;
              charset=utf-8">
            <title></title>
            Iskren<br>
            <br>
          </div>
        </div>
        <div class="moz-cite-prefix">On 21.7.2017 г. 11:42,
          Daniel-Constantin Mierla wrote:<br>
        </div>
        <blockquote type="cite"
          cite="mid:4fb9d947-8297-3f79-aec8-9587aa38c8c9@gmail.com">
          <meta http-equiv="Content-Type" content="text/html;
            charset=utf-8">
          <p>Hello,</p>
          <p>are you sure that the Route is like that? The lr parameter
            and received should be between angle brakets <> along
            with the sip uri.</p>
          <p>Maybe you should paste here the full REGISTER sent to sip
            server after adding the path as well as the INVITE received
            later. You can replace the IP addresses that are sensitive
            for you, but keel everything else as it is in order to see
            if there is something wrong in the headers.</p>
          <p>Btw, the To header has nothing to do with routing, the
            R-URI will be also relevant in this case.</p>
          <p>Is kamailio listening directly on a public ip?<br>
          </p>
          <p>Cheers,<br>
            Daniel<br>
          </p>
          <br>
          <div class="moz-cite-prefix">On 20.07.17 17:18, Iskren
            Hadzhinedev wrote:<br>
          </div>
          <blockquote type="cite"
            cite="mid:6dea34b0-c326-da12-c49a-3feef9b9f55c@ikiji.com">
            <meta http-equiv="content-type" content="text/html;
              charset=utf-8">
            <p>Hello,</p>
            <p>I have a kamailio proxy in front of FreeSWITCH.</p>
            <p>Whenever FreeSWITCH initiates the dialog (e.g. sends an
              INVITE), kamailio doesn't use the 'received' parameter and
              it forwards to the RFC1918 IP address. The initial INVITE
              from FreeSWITCH has the following headers:</p>
            <tt>To: <a class="moz-txt-link-rfc2396E"
                href="sip:1001@192.168.1.200:5063"
                moz-do-not-send="true"><sip:1001@192.168.1.200:5063></a></tt><tt><br>
            </tt><tt>Route: <a class="moz-txt-link-rfc2396E"
                href="sip:1.2.3.4" moz-do-not-send="true"><sip:1.2.3.4></a>;lr;received=<a
                class="moz-txt-link-freetext" href="sip:5.6.7.8:5063"
                moz-do-not-send="true">sip:5.6.7.8:5063</a></tt><br>
            <br>
            Where <tt>1.2.3.4</tt> is the kamailio public IP and<tt>
              5.6.7.8</tt> is the public IP of the UAC behind NAT.<br>
            I have <tt>modparam("path", "use_received", 1)</tt> in my
            config file and to my understanding that should be
            sufficient to route to the proper IP, but kamailio keeps
            sending INVITEs to <tt>192.168.1.200</tt>.<br>
            <br>
            Can anyone tell me what am I missing?<br>
            Thanks!<br>
            <br>
            Kind regards,<br>
            Iskren<br>
            <br>
            <fieldset class="mimeAttachmentHeader"></fieldset>
            <br>
            <pre wrap="">_______________________________________________
Kamailio (SER) - Users Mailing List
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org" moz-do-not-send="true">sr-users@lists.kamailio.org</a>
<a class="moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" moz-do-not-send="true">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
          </blockquote>
          <br>
          <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda" moz-do-not-send="true">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda" moz-do-not-send="true">www.linkedin.com/in/miconda</a>
Kamailio Advanced Training - <a class="moz-txt-link-abbreviated" href="http://www.asipto.com" moz-do-not-send="true">www.asipto.com</a>
Kamailio World Conference - <a class="moz-txt-link-abbreviated" href="http://www.kamailioworld.com" moz-do-not-send="true">www.kamailioworld.com</a></pre>
        </blockquote>
        <br>
      </blockquote>
      <br>
      <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a>
Kamailio Advanced Training - <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
Kamailio World Conference - <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="http://www.kamailioworld.com">www.kamailioworld.com</a></pre>
    </blockquote>
  </body>
</html>