<div dir="ltr"><div>Liviu thank you for your assistance, It looks like I've got my script working correctly now :)<br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 22, 2018 at 12:53 AM, Liviu Chircu <span dir="ltr"><<a href="mailto:liviu@opensips.org" target="_blank">liviu@opensips.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <p><tt>Hi John,</tt></p>
    <p><tt>By any chance, does your OpenSIPS spew out errors such as the
        following?</tt></p>
    <p><tt>"ERROR:SCRIPT BUG - second attempt to change URI Contact"</tt></p>
    <p><tt>If yes, then this is expected. You should address your NAT
        traversal issue with fix_nated_register(), which is compatible
        with mid_registrar_save().<br>
      </tt></p>
    <p><tt>Best regards,</tt><br>
    </p>
    <pre class="m_6902749602060170833moz-signature" cols="72">Liviu Chircu
OpenSIPS Developer
<a class="m_6902749602060170833moz-txt-link-freetext" href="http://www.opensips-solutions.com" target="_blank">http://www.opensips-solutions.<wbr>com</a></pre><div><div class="h5">
    <div class="m_6902749602060170833moz-cite-prefix">On 19.03.2018 21:16, John Kiniston
      wrote:<br>
    </div>
    </div></div><blockquote type="cite"><div><div class="h5">
      <div dir="ltr">
        <div>
          <div>I'm working on setting up mid_registrar and it's mostly
            working but I have a problem with RTP being sent to the
            wrong address.<br>
            <br>
          </div>
          I'm trying to fix this by using fix_contact in my script but
          it doesn't appear to be rewriting the contact when the
          registrar is sent on to my Asterisk box.<br>
          <br>
        </div>
        I see the request from my phone to my proxy:<br>
        <div><br>
          U 2018/03/19 12:04:54.650203 X.X.X.X:5060 -> <a href="http://192.168.69.159:5060" target="_blank">192.168.69.159:5060</a><br>
          REGISTER sip:<a href="http://pi.lzrd.net:5060" target="_blank">pi.lzrd.net:5060</a> SIP/2.0.<br>
          Via: SIP/2.0/UDP
          172.16.52.76:5060;branch=<wbr>z9hG4bK2864496306;rport.<br>
          From: "John Kiniston" <<a href="http://sip:7002kiniston@pi.lzrd.net:5060" target="_blank">sip:7002kiniston@pi.lzrd.net:<wbr>5060</a>>;tag=2815321839.<br>
          To: "John Kiniston" <<a href="http://sip:7002kiniston@pi.lzrd.net:5060" target="_blank">sip:7002kiniston@pi.lzrd.net:<wbr>5060</a>>.<br>
          Call-ID: <a href="mailto:0_2089376052@172.16.52.76" target="_blank">0_2089376052@172.16.52.76</a>.<br>
          CSeq: 1 REGISTER.<br>
          Contact: <<a href="http://sip:7002kiniston@172.16.52.76:5060" target="_blank">sip:7002kiniston@172.16.52.<wbr>76:5060</a>>.<br>
          Allow: INVITE, INFO, PRACK, ACK, BYE, CANCEL, OPTIONS, NOTIFY,
          REGISTER, SUBSCRIBE, REFER, PUBLISH, UPDATE, MESSAGE.<br>
          Max-Forwards: 70.<br>
          User-Agent: Yealink SIP-T42S 66.81.0.110.<br>
          Expires: 0.<br>
          Allow-Events: talk,hold,conference,refer,<wbr>check-sync.<br>
          Mac: 00:15:65:b4:d3:d3.<br>
          Line: 1.<br>
          Content-Length: 0.<br>
          .<br>
          <br>
        </div>
        <div>And here is the request from my proxy to my PBX:<br>
        </div>
        <div><br>
          U 2018/03/19 12:04:54.808558 <a href="http://192.168.69.159:5060" target="_blank">192.168.69.159:5060</a>
          -> <a href="http://64.119.36.19:5060" target="_blank">64.119.36.19:5060</a><br>
          REGISTER sip:<a href="http://pi.lzrd.net" target="_blank">pi.lzrd.net</a> SIP/2.0.<br>
          Via: SIP/2.0/UDP
          64.119.34.211:5060;branch=<wbr>z9hG4bK0e8e.34dfaf97.0.<br>
          Via: SIP/2.0/UDP
          172.16.52.76:5060;received=x.<wbr>x.x.x;branch=<wbr>z9hG4bK2864496306;rport=5060.<br>
          From: "John Kiniston" <<a href="http://sip:7002kiniston@pi.lzrd.net:5060" target="_blank">sip:7002kiniston@pi.lzrd.net:<wbr>5060</a>>;tag=2815321839.<br>
          To: "John Kiniston" <<a href="http://sip:7002kiniston@pi.lzrd.net:5060" target="_blank">sip:7002kiniston@pi.lzrd.net:<wbr>5060</a>>.<br>
          Call-ID: <a href="mailto:0_2089376052@172.16.52.76" target="_blank">0_2089376052@172.16.52.76</a>.<br>
          CSeq: 1 REGISTER.<br>
          Contact: <<a href="http://sip:7002kiniston@192.168.69.159:5060" target="_blank">sip:7002kiniston@192.168.69.<wbr>159:5060</a>>.<br>
          Allow: INVITE, INFO, PRACK, ACK, BYE, CANCEL, OPTIONS, NOTIFY,
          REGISTER, SUBSCRIBE, REFER, PUBLISH, UPDATE, MESSAGE.<br>
          Max-Forwards: 69.<br>
          User-Agent: Yealink SIP-T42S 66.81.0.110.<br>
          Expires: 0.<br>
          Allow-Events: talk,hold,conference,refer,<wbr>check-sync.<br>
          Mac: 00:15:65:b4:d3:d3.<br>
          Line: 1.<br>
          Content-Length: 0.<br>
          Path: <a class="m_6902749602060170833moz-txt-link-rfc2396E"><sip:64.119.34.211:5060;lr></a>.<br>
          <br>
        </div>
        <div>Shouldn't the Contact be rewritten with the source IP of
          the request from the phone to X.X.X.X?<br>
          <br>
          <br>
          OpenSIPS$:ul show<br>
          Domain:: location table=512 records=1<br>
                  AOR:: 7002kiniston<br>
                          Contact:: <a class="m_6902749602060170833moz-txt-link-freetext">sip:7002kiniston@X.X.X.X:5060</a> Q=<br>
                                  ContactID:: 2933602576022647686<br>
                                  Expires:: 3330<br>
                                  Callid:: <a href="mailto:0_2936163010@172.16.52.76" target="_blank">0_2936163010@172.16.52.76</a><br>
                                  Cseq:: 2<br>
                                  User-agent:: Yealink SIP-T42S
          66.81.0.110<br>
                                  State:: CS_NEW<br>
                                  Flags:: 0<br>
                                  Cflags::<br>
                                  Socket:: udp:X.X.X.X:5060<br>
                                  Methods:: 16383<br>
          <br>
        </div>
        <div>
          <div>
            <div><br>
            </div>
            <div>In my main script I have:<br>
              <br>
                      if ($si == "X.X.X.X"){<br>
                              route(FromEndPoint);<br>
                      }<br>
              <br>
            </div>
            <div><br>
              route[FromEndPoint]{<br>
                  route("nat_test_and_correct");<br>
                      if (is_method("INVITE")){<br>
                              if (is_registered("location","$<wbr>fu")) {<br>
                                      route(outbound);<br>
                              } else {<br>
                                      t_reply("503","Authentication
              failed");<br>
                              }<br>
                      }<br>
                      if (is_method("SUBSCRIBE|NOTIFY|<wbr>MESSAGE")){<br>
                              route(outbound);<br>
                      };<br>
                      if (is_method("REGISTER")) {<br>
                              route(register);<br>
                      }<br>
              <br>
              }<br>
              <br>
              route[register]{<br>
                      if (is_method("REGISTER")) {<br>
                              xlog("L_INFO","Saving location to
              mid_registrar");<br>
                              mid_registrar_save("location")<wbr>;<br>
                              switch ($retcode) {<br>
                                      case 1:<br>
                                            <wbr>  xlog("forwarding REGISTER
              to main registrar($$ci=$ci) $ru\n");<br>
                                            <wbr>  $ru = "sip:" + $td:$rp;<br>
                                            <wbr>  t_relay();<br>
                                            <wbr>  break;<br>
                                      case 2:<br>
                                            <wbr>  xlog("absorbing REGISTER!
              ($$ci=$ci)\n");<br>
                                            <wbr>  break;<br>
                                      default:<br>
                                            <wbr>  xlog("failed to save
              registration! ($$ci=$ci)\n");<br>
                                      }<br>
                                      exit;<br>
                      }<br>
              }<br>
              <br>
              <br>
              route[outbound]{<br>
                      t_relay();<br>
                      exit;<br>
              }<br>
              <br>
              route[nat_test_and_correct] {<br>
                      if ((method=="REGISTER|SUBSCRIBE|<wbr>INVITE")
              && !has_totag() && client_nat_test("3")) {<br>
                              nat_keepalive();<br>
                      }<br>
                      if (client_nat_test("3")) {<br>
                              force_rport();<br>
                              fix_contact();<br>
                      }<br>
              }<br>
              <br>
              <br>
              -- <br>
              <div class="m_6902749602060170833gmail_signature">A human being should be able
                to change a diaper, plan an invasion, butcher a hog,
                conn a ship, design a building, write a sonnet, balance
                accounts, build a wall, set a bone, comfort the dying,
                take orders, give orders, cooperate, act alone, solve
                equations, analyze a new problem, pitch manure, program
                a computer, cook a tasty meal, fight efficiently, die
                gallantly. Specialization is for insects.<br>
                ---Heinlein</div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="m_6902749602060170833mimeAttachmentHeader"></fieldset>
      <br>
      </div></div><pre>______________________________<wbr>_________________
Users mailing list
<a class="m_6902749602060170833moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org" target="_blank">Users@lists.opensips.org</a>
<a class="m_6902749602060170833moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-<wbr>bin/mailman/listinfo/users</a>
</pre>
    </blockquote>
    <br>
  </div>

<br>______________________________<wbr>_________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a><br>
<a href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" rel="noreferrer" target="_blank">http://lists.opensips.org/cgi-<wbr>bin/mailman/listinfo/users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.<br>---Heinlein</div>
</div>