<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body>
    <p>Hello,</p>
    <p><br>
    </p>
    <p>hard to track the execution path without a test environment ... I
      would suggest to load debugger module and enable cfgtrace for it
      to see what actions in configuration file are executed, to be sure
      it gets to the fix_nated_sdp().</p>
    <p><br>
    </p>
    <p>Cheers,<br>
      Daniel</p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 04.08.20 10:44, Edward Romanenco
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:VE1PR04MB67015310CBBF03292EA74E70C74A0@VE1PR04MB6701.eurprd04.prod.outlook.com">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        I tried using nathelper in the following way - 
        fix_nated_sdp("2","XX.XX.XX.XX"); - it still shows my internal
        IP.<br>
      </div>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        Attaching my request routes, can you kindly check and see if I
        am using it correctly?</div>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        <br>
      </div>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        <b>SDP</b></div>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        .
        <div style="">v=0.</div>
        <div style="">o=FreeSWITCH 1596486133 1596486134 IN IP4
          172.18.0.40.</div>
        <div style="">s=FreeSWITCH.</div>
        <div style="">c=IN IP4 172.18.0.40.</div>
        <div style="">t=0 0.</div>
        <div style="">m=audio 43954 RTP/AVP 8 101.</div>
        <div style="">a=rtpmap:8 PCMA/8000.</div>
        <div style="">a=rtpmap:101 telephone-event/8000.</div>
        <div style="">a=fmtp:101 0-16.</div>
        <div style="">a=ptime:20.</div>
        <br>
        <br>
      </div>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        <b>REQUEST ROUTES</b></div>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        request_route {
        <div>    setflag(22);</div>
        <div>    route(REQINIT);</div>
        <div><br>
        </div>
        <div>    if (is_method("CANCEL")) {</div>
        <div>        if (t_check_trans()) {</div>
        <div>            route(RELAY);</div>
        <div>        }</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    route(WITHINDLG);</div>
        <div><br>
        </div>
        <div>    if(t_precheck_trans()) {</div>
        <div>        t_check_trans();</div>
        <div>        exit;</div>
        <div>    }</div>
        <div>    t_check_trans();</div>
        <div><br>
        </div>
        <div>    remove_hf("Route");</div>
        <div>    if (is_method("INVITE|SUBSCRIBE")){// &&
          is_present_hf("X-SESSION-ID")){</div>
        <div>      record_route();</div>
        <div>    }</div>
        <div>    if (is_method("INVITE")) {</div>
        <div>        setflag(FLT_ACC);</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if ($rU==$null) {</div>
        <div>        sl_send_reply("484","Address Incomplete");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    route(OUTGOING);</div>
        <div>    route(PSTN);</div>
        <div>    route(INCOMING);</div>
        <div>    route(RELAY);</div>
        <div>}</div>
        <div><br>
        </div>
        <div>route[REMOVE_X_HEADERS] {</div>
        <div>if(is_present_hf("X-SESSION-ID")) {</div>
        <div>        remove_hf("X-FS-Support");</div>
        <div>   remove_hf("X-Src");</div>
        <div>   remove_hf("X-DESTINATIONS");</div>
        <div>   remove_hf("X-SESSION-ID");</div>
        <div>    }</div>
        <div>        xinfo("Remove X Headers; Contact Header is $ct");</div>
        <div>}</div>
        <div><br>
        </div>
        <div>route[INCOMING] {</div>
        <div>    if(is_present_hf("X-SESSION-ID")) {</div>
        <div>      return;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>if(ds_is_from_list("4")) {</div>
        <div>route(TRANSLATE_SRC_IN);</div>
        <div>}</div>
        <div><br>
        </div>
        <div>route(REQUEST_PERMISSIONS);</div>
        <div>fix_nated_sdp("2","XX.XX.XX.XX");</div>
        <div>    exit;</div>
        <div>}</div>
        <div><br>
        </div>
        <div>route[REQUEST_PERMISSIONS] {</div>
        <div>    $var(body) = 0;</div>
        <div>    $var(from) = $fU;</div>
        <div><br>
        </div>
        <div>    if($(var(from){s.substr,1,4})=="0972") {</div>
        <div>        $var(from)=$(var(from){s.substr,2,0});</div>
        <div>        $fU = $var(from);</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    jansson_set("string", "from", "$var(from)",
          "$var(body)");</div>
        <div><br>
        </div>
        <div>    if(is_present_hf("Diversion")) {</div>
        <div>        xlog("L_INFO", "Call has been forwarded.");</div>
        <div>        jansson_set("string","to","$oU","$var(body)");</div>
        <div>    } else {</div>
        <div>   jansson_set("string","to","$tU","$var(body)");</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    jansson_set("string","forcepstn","false","$var(body)");</div>
        <div>    jansson_set("string", "source", "EGRESS",
          "$var(body)");</div>
        <div>    $http_req(all) = $null;</div>
        <div>    $http_req(method) = "POST";</div>
        <div>    $http_req(hdr) = "Content-Type: application/json";</div>
        <div>    $http_req(hdr) = "Accept: application/json";</div>
        <div>    $http_req(hdr) = "Connection: keep-alive";</div>
        <div>    $http_req(body) = $var(body);</div>
        <div>    $var(re_url)= <a class="moz-txt-link-rfc2396E" href="https://VNVHOST/voiceandvideo/makeCall">"https://VNVHOST/voiceandvideo/makeCall"</a>;</div>
        <div>    t_newtran();</div>
        <div><br>
        </div>
        <div>    if (http_async_query("$var(re_url)",
          "REQUEST_PERMISSIONS_REPLY") < 0) {</div>
        <div>        t_reply("500", "Server Internal Error");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div>}</div>
        <div><br>
        </div>
        <div>route[REQUEST_PERMISSIONS_REPLY] {</div>
        <div>    if ($(http_err{s.len})) {</div>
        <div>        xlog("L_ERR","Got error from server 1");</div>
        <div>   t_reply("500", "Server Internal Error");</div>
        <div>        exit;</div>
        <div>    } else if ($http_rs != 200) {</div>
        <div>        xlog("L_ERR","Got error from server 2");</div>
        <div>        t_reply("500", "Server Error");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    # Populate dialog variables for CDR Creation</div>
        <div>    $var(count) = 0;</div>
        <div>   
          jansson_get("list",$http_rb,"$dlg_var(destinations_array)");</div>
        <div>    jansson_get("msgID", $http_rb, "$dlg_var(session_id)");</div>
        <div>   
          jansson_get("resultCode",$http_rb,"$dlg_var(resultCode)");</div>
        <div><br>
        </div>
        <div>    if($dlg_var(resultCode)!=0) {</div>
        <div>        t_reply("500","Server Internal Error");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    ## EGRESS Server Information</div>
        <div>    route(ADD_TELEMESSAGE_HDRS);</div>
        <div>    $var(setid) = "1";</div>
        <div><br>
        </div>
        <div>    if(!ds_select_dst("1", "4")) {</div>
        <div>        send_reply("404", "No destination");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    route(RELAY);</div>
        <div>    exit;</div>
        <div>}</div>
        <div><br>
        </div>
        <div>route[RELAY] {</div>
        <div>    if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {</div>
        <div>        if(!t_is_set("branch_route")) {</div>
        <div>            t_on_branch("MANAGE_BRANCH");</div>
        <div>        }</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if (is_method("INVITE|SUBSCRIBE|UPDATE")) {</div>
        <div>        if(!t_is_set("onreply_route")) {</div>
        <div>            t_on_reply("MANAGE_REPLY");</div>
        <div>        }</div>
        <div>    }</div>
        <div>    if (is_method("INVITE")) {</div>
        <div>        if(!t_is_set("failure_route")) {</div>
        <div>            t_on_failure("MANAGE_FAILURE");</div>
        <div>        }</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if (!t_relay()) {</div>
        <div>        sl_reply_error();</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    exit;</div>
        <div>}</div>
        <div><br>
        </div>
        <div># Per SIP request initial checks</div>
        <div>route[REQINIT] {</div>
        <div>#!ifdef WITH_ANTIFLOOD</div>
        <div>    # flood detection from same IP and traffic ban for a
          while</div>
        <div>    # be sure you exclude checking trusted peers, such as
          pstn gateways</div>
        <div>    # - local host excluded (e.g., loop to self)</div>
        <div>    if(src_ip!=myself) {</div>
        <div>        if($sht(ipban=>$si)!=$null) {</div>
        <div>            # ip is already blocked</div>
        <div>            xdbg("request from blocked IP - $rm from $fu
          (IP:$si:$sp)\n");</div>
        <div>            exit;</div>
        <div>        }</div>
        <div>        if (!pike_check_req()) {</div>
        <div>            xlog("L_ALERT","ALERT: pike blocking $rm from
          $fu (IP:$si:$sp)\n");</div>
        <div>            $sht(ipban=>$si) = 1;</div>
        <div>            exit;</div>
        <div>        }</div>
        <div>    }</div>
        <div>#!endif</div>
        <div>    if($ua =~ "friendly-scanner|sipcli|VaxSIPUserAgent") {</div>
        <div>        # silent drop for scanners - uncomment next line if
          want to reply</div>
        <div>        # sl_send_reply("200", "OK");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if (!mf_process_maxfwd_header("10")) {</div>
        <div>        sl_send_reply("483","Too Many Hops");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if(is_method("OPTIONS") && uri==myself
          && $rU==$null) {</div>
        <div>        sl_send_reply("200","Keepalive");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if(!sanity_check("1511", "7")) {</div>
        <div>        xlog("Malformed SIP message from $si:$sp\n");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div>}</div>
        <div><br>
        </div>
        <div># Handle requests within SIP dialogs</div>
        <div>route[WITHINDLG] {</div>
        <div>    xlog("L_ERR","Entering withindlgs");</div>
        <div>    if (!has_totag()) return;</div>
        <div><br>
        </div>
        <div>    # sequential request withing a dialog should</div>
        <div>    # take the path determined by record-routing</div>
        <div>    if (loose_route()) {</div>
        <div>        xlog("L_ERR","loose route");</div>
        <div>        route(DLGURI);</div>
        <div>        if (is_method("BYE")) {</div>
        <div>            xlog("L_ERR","BYE recevied in loose route");</div>
        <div>            setflag(FLT_ACC); # do accounting ...</div>
        <div>            setflag(FLT_ACCFAILED); # ... even if the
          transaction fails</div>
        <div>        } else if ( is_method("ACK") ) {</div>
        <div>            # ACK is forwarded statelessly</div>
        <div>            route(NATMANAGE);</div>
        <div>        } else if ( is_method("NOTIFY") ) {</div>
        <div>            # Add Record-Route for in-dialog NOTIFY as per
          RFC 6665.</div>
        <div>            xlog("L_ERR","*****************1 Adding rr");</div>
        <div>          record_route();</div>
        <div>        }</div>
        <div><br>
        </div>
        <div>        route(RELAY);</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if (is_method("SUBSCRIBE") && uri == myself) {</div>
        <div>        # in-dialog subscribe requests</div>
        <div>        route(PRESENCE);</div>
        <div>        exit;</div>
        <div>    }</div>
        <div>    if ( is_method("ACK") ) {</div>
        <div>        if ( t_check_trans() ) {</div>
        <div>            # no loose-route, but stateful ACK;</div>
        <div>            # must be an ACK after a 487</div>
        <div>            # or e.g. 404 from upstream server</div>
        <div>            route(RELAY);</div>
        <div>            exit;</div>
        <div>        } else {</div>
        <div>            # ACK without matching transaction ... ignore
          and discard</div>
        <div>            exit;</div>
        <div>        }</div>
        <div>    }</div>
        <div>    sl_send_reply("404","Not here");</div>
        <div>    exit;</div>
        <div>}</div>
        <div><br>
        </div>
        <div># Handle SIP registrations</div>
        <div>route[REGISTRAR] {</div>
        <div>    if (!is_method("REGISTER")) return;</div>
        <div><br>
        </div>
        <div>    if(isflagset(FLT_NATS)) {</div>
        <div>        setbflag(FLB_NATB);</div>
        <div>#!ifdef WITH_NATSIPPING</div>
        <div>        # do SIP NAT pinging</div>
        <div>        setbflag(FLB_NATSIPPING);</div>
        <div>#!endif</div>
        <div>    }</div>
        <div>    if (!save("location")) {</div>
        <div>        sl_reply_error();</div>
        <div>    }</div>
        <div>    exit;</div>
        <div>}</div>
        <div><br>
        </div>
        <div># User location service</div>
        <div>route[LOCATION] {</div>
        <div><br>
        </div>
        <div>#!ifdef WITH_SPEEDDIAL</div>
        <div>    # search for short dialing - 2-digit extension</div>
        <div>    if($rU=~"^[0-9][0-9]$") {</div>
        <div>        if(sd_lookup("speed_dial")) {</div>
        <div>            route(SIPOUT);</div>
        <div>        }</div>
        <div>    }</div>
        <div>#!endif</div>
        <div><br>
        </div>
        <div>#!ifdef WITH_ALIASDB</div>
        <div>    # search in DB-based aliases</div>
        <div>    if(alias_db_lookup("dbaliases")) {</div>
        <div>        route(SIPOUT);</div>
        <div>    }</div>
        <div>#!endif</div>
        <div><br>
        </div>
        <div>    $avp(oexten) = $rU;</div>
        <div>    if (!lookup("location")) {</div>
        <div>        $var(rc) = $rc;</div>
        <div>        route(TOVOICEMAIL);</div>
        <div>        t_newtran();</div>
        <div>        switch ($var(rc)) {</div>
        <div>            case -1:</div>
        <div>            case -3:</div>
        <div>                send_reply("404", "Not Found");</div>
        <div>                exit;</div>
        <div>            case -2:</div>
        <div>                send_reply("405", "Method Not Allowed");</div>
        <div>                exit;</div>
        <div>        }</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if (is_method("INVITE")) {</div>
        <div>        setflag(FLT_ACCMISSED);</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    route(RELAY);</div>
        <div>    exit;</div>
        <div>}</div>
        <div><br>
        </div>
        <div># Presence server processing</div>
        <div>route[PRESENCE] {</div>
        <div>    if(!is_method("PUBLISH|SUBSCRIBE")) return;</div>
        <div><br>
        </div>
        <div>    if(is_method("SUBSCRIBE") &&
          $hdr(Event)=="message-summary") {</div>
        <div>        route(TOVOICEMAIL);</div>
        <div>        # returns here if no voicemail server is configured</div>
        <div>        sl_send_reply("404", "No voicemail service");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>#!ifdef WITH_PRESENCE</div>
        <div>    if (!t_newtran()) {</div>
        <div>        sl_reply_error();</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if(is_method("PUBLISH")) {</div>
        <div>        handle_publish();</div>
        <div>        t_release();</div>
        <div>    } else if(is_method("SUBSCRIBE")) {</div>
        <div>        handle_subscribe();</div>
        <div>        t_release();</div>
        <div>    }</div>
        <div>    exit;</div>
        <div>#!endif</div>
        <div><br>
        </div>
        <div>    # if presence enabled, this part will not be executed</div>
        <div>    if (is_method("PUBLISH") || $rU==$null) {</div>
        <div>        sl_send_reply("404", "Not here");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div>    return;</div>
        <div>}</div>
        <div><br>
        </div>
        <div># IP authorization and user authentication</div>
        <div>route[AUTH] {</div>
        <div>#!ifdef WITH_AUTH</div>
        <div><br>
        </div>
        <div>#!ifdef WITH_IPAUTH</div>
        <div>    if((!is_method("REGISTER")) &&
          allow_source_address()) {</div>
        <div>        # source IP allowed</div>
        <div>        return;</div>
        <div>    }</div>
        <div>#!endif</div>
        <div><br>
        </div>
        <div>    if (is_method("REGISTER") || from_uri==myself) {</div>
        <div>        # authenticate requests</div>
        <div>        if (!auth_check("$fd", "subscriber", "1")) {</div>
        <div>            auth_challenge("$fd", "0");</div>
        <div>            exit;</div>
        <div>        }</div>
        <div>        # user authenticated - remove auth header</div>
        <div>        if(!is_method("REGISTER|PUBLISH"))</div>
        <div>            consume_credentials();</div>
        <div>    }</div>
        <div>    # if caller is not local subscriber, then check if it
          calls</div>
        <div>    # a local destination, otherwise deny, not an open
          relay here</div>
        <div>    if (from_uri!=myself && uri!=myself) {</div>
        <div>        sl_send_reply("403","Not relaying");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>#!endif</div>
        <div>    return;</div>
        <div>}</div>
        <div><br>
        </div>
        <div># Caller NAT detection</div>
        <div>route[NATDETECT] {</div>
        <div>#!ifdef WITH_NAT</div>
        <div>    force_rport();</div>
        <div>    if (nat_uac_test("19")) {</div>
        <div>        if (is_method("REGISTER")) {</div>
        <div>            fix_nated_register();</div>
        <div>        } else {</div>
        <div>            if(is_first_hop()) {</div>
        <div>                set_contact_alias();</div>
        <div>            }</div>
        <div>        }</div>
        <div>        setflag(FLT_NATS);</div>
        <div>    }</div>
        <div>#!endif</div>
        <div>    return;</div>
        <div>}</div>
        <div><br>
        </div>
        <div># RTPProxy control and signaling updates for NAT traversal</div>
        <div>route[NATMANAGE] {</div>
        <div>#!ifdef WITH_NAT</div>
        <div>    if (is_request()) {</div>
        <div>        if(has_totag()) {</div>
        <div>            if(check_route_param("nat=yes")) {</div>
        <div>                setbflag(FLB_NATB);</div>
        <div>            }</div>
        <div>        }</div>
        <div>    }</div>
        <div>    if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))
          return;</div>
        <div><br>
        </div>
        <div>    if(nat_uac_test("8")) {</div>
        <div>if(ds_is_from_list()){</div>
        <div>xdbg("__META rtpengine priv->pub");</div>
        <div>rtpengine_manage("replace-session-connection replace-origin
          direction=priv direction=pub");</div>
        <div>} else {</div>
        <div>xdbg("__META rtpengine pub->priv");</div>
        <div>rtpengine_manage("replace-session-connection replace-origin
          direction=pub direction=priv");</div>
        <div>}</div>
        <div>    } else {</div>
        <div>if(ds_is_from_list()) {</div>
        <div>xdbg("__META rtpengine priv->pub");</div>
        <div>rtpengine_manage("replace-session-connection replace-origin
          trust-address direction=priv direction=pub");</div>
        <div>} else {</div>
        <div>xdbg("__META rtpengine pub->priv");</div>
        <div>rtpengine_manage("replace-session-connection replace-origin
          trust-address direction=pub direction=priv");</div>
        <div>}</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if (is_request()) {</div>
        <div>        if (!has_totag()) {</div>
        <div>            if(t_is_branch_route()) {</div>
        <div>                add_rr_param(";nat=yes");</div>
        <div>            }</div>
        <div>        }</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if (is_reply()) {</div>
        <div>        if(isbflagset(FLB_NATB)) {</div>
        <div>            if(is_first_hop())</div>
        <div>                set_contact_alias();</div>
        <div>        }</div>
        <div>xlog("L_ERR","20202020 in is_reply");</div>
        <div>    }</div>
        <div>#!endif</div>
        <div>    return;</div>
        <div>}</div>
        <div><br>
        </div>
        <div># URI update for dialog requests</div>
        <div>route[DLGURI] {</div>
        <div>#!ifdef WITH_NAT</div>
        <div>    if(!isdsturiset()) {</div>
        <div>        handle_ruri_alias();</div>
        <div>    }</div>
        <div>#!endif</div>
        <div>    return;</div>
        <div>}</div>
        <div><br>
        </div>
        <div># Routing to foreign domains</div>
        <div>route[SIPOUT] {</div>
        <div>    if (uri==myself) return;</div>
        <div>    append_hf("P-hint: outbound\r\n");</div>
        <div>    route(RELAY);</div>
        <div>    exit;</div>
        <div>}</div>
        <div><br>
        </div>
        <div># PSTN GW routing</div>
        <div>route[PSTN] {</div>
        <div>#!ifdef WITH_PSTN</div>
        <div>    # check if PSTN GW IP is defined</div>
        <div>    if (strempty($sel(cfg_get.pstn.gw_ip))) {</div>
        <div>        xlog("SCRIPT: PSTN routing enabled but pstn.gw_ip
          not defined\n");</div>
        <div>        return;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    # route to PSTN dialed numbers starting with '+' or
          '00'</div>
        <div>    #     (international format)</div>
        <div>    # - update the condition to match your dialing rules
          for PSTN routing</div>
        <div>    if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$")) return;</div>
        <div><br>
        </div>
        <div>    # only local users allowed to call</div>
        <div>    if(from_uri!=myself) {</div>
        <div>        sl_send_reply("403", "Not Allowed");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    if (strempty($sel(cfg_get.pstn.gw_port))) {</div>
        <div>        $ru = "sip:" + $rU + "@" +
          $sel(cfg_get.pstn.gw_ip);</div>
        <div>    } else {</div>
        <div>        $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip)
          + ":"</div>
        <div>                    + $sel(cfg_get.pstn.gw_port);</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>    route(RELAY);</div>
        <div>    exit;</div>
        <div>#!endif</div>
        <div><br>
        </div>
        <div>    return;</div>
        <div>}</div>
        <div><br>
        </div>
        <div># XMLRPC routing</div>
        <div>#!ifdef WITH_XMLRPC</div>
        <div>route[XMLRPC] {</div>
        <div>    # allow XMLRPC from localhost</div>
        <div>    if ((method=="POST" || method=="GET")</div>
        <div>            && (src_ip==127.0.0.1)) {</div>
        <div>        # close connection only for xmlrpclib user agents
          (there is a bug in</div>
        <div>        # xmlrpclib: it waits for EOF before interpreting
          the response).</div>
        <div>        if ($hdr(User-Agent) =~ "xmlrpclib")</div>
        <div>            set_reply_close();</div>
        <div>        set_reply_no_connect();</div>
        <div>        dispatch_rpc();</div>
        <div>        exit;</div>
        <div>    }</div>
        <div>    send_reply("403", "Forbidden");</div>
        <div>    exit;</div>
        <div>}</div>
        <div>#!endif</div>
        <div><br>
        </div>
        <div># Routing to voicemail server</div>
        <div>route[TOVOICEMAIL] {</div>
        <div>#!ifdef WITH_VOICEMAIL</div>
        <div>    if(!is_method("INVITE|SUBSCRIBE")) return;</div>
        <div><br>
        </div>
        <div>    # check if VoiceMail server IP is defined</div>
        <div>    if (strempty($sel(cfg_get.voicemail.srv_ip))) {</div>
        <div>        xlog("SCRIPT: VoiceMail routing enabled but IP not
          defined\n");</div>
        <div>        return;</div>
        <div>    }</div>
        <div>    if(is_method("INVITE")) {</div>
        <div>        if($avp(oexten)==$null) return;</div>
        <div><br>
        </div>
        <div>        $ru = "sip:" + $avp(oexten) + "@" +
          $sel(cfg_get.voicemail.srv_ip)</div>
        <div>                + ":" + $sel(cfg_get.voicemail.srv_port);</div>
        <div>    } else {</div>
        <div>        if($rU==$null) return;</div>
        <div><br>
        </div>
        <div>        $ru = "sip:" + $rU + "@" +
          $sel(cfg_get.voicemail.srv_ip)</div>
        <div>                + ":" + $sel(cfg_get.voicemail.srv_port);</div>
        <div>    }</div>
        <div>    route(RELAY);</div>
        <div>    exit;</div>
        <div>#!endif</div>
        <div><br>
        </div>
        <div>    return;</div>
        <div>}</div>
        <div><br>
        </div>
        <div>//convert phone number from international to internal</div>
        <div>//+972112223344 <-> 011222334</div>
        <div>route[TRANSLATE_DST_OUT] {</div>
        <div>        xinfo("__META TRANSLATE_DST_OUT");</div>
        <div>        xdbg("__META To: $hdr(To)");</div>
        <div>        xdbg("__META Regexp: NUM_TRANSLATE_OUT_RE");</div>
        <div><br>
        </div>
        <div>        if(subst_uri("/NUM_TRANSLATE_OUT_RE/0\2/"))</div>
        <div>                xdbg("__META URI translated");</div>
        <div>        else</div>
        <div>                xdbg("__META Not translating number in
          URI");</div>
        <div><br>
        </div>
        <div>        if(subst_hf("To", "/NUM_TRANSLATE_OUT_RE/0\2/",
          "a"))</div>
        <div>                xdbg("__META To header translated");</div>
        <div>        else</div>
        <div>                xdbg("__META Not translating number in to
          header");</div>
        <div>}</div>
        <div><br>
        </div>
        <div>//convert phone number from internal format to
          international</div>
        <div>//011222334 <-> +<972>112223344</div>
        <div>route[TRANSLATE_SRC_IN] {</div>
        <div>$var(number)=$rU;</div>
        <div>        if($(var(number){s.substr,1,4})=="+972") {</div>
        <div> $rU="0"+$(var(number){s.substr,5,0});</div>
        <div>}</div>
        <div>}</div>
        <div>/////////////////////////////////////////////////////////////////////////////</div>
        <div><br>
        </div>
        <div># Manage outgoing branches</div>
        <div>branch_route[MANAGE_BRANCH] {</div>
        <div>    xdbg("new branch [$T_branch_idx] to $ru\n");</div>
        <div>    route(NATMANAGE);</div>
        <div>}</div>
        <div><br>
        </div>
        <div># Manage incoming replies</div>
        <div>onreply_route[MANAGE_REPLY] {</div>
        <div>    xdbg("incoming reply\n");</div>
        <div><br>
        </div>
        <div>    // fix_nated_contact();</div>
        <div>    xlog("L_ERR","2020202020202 Got reply $ct");</div>
        <div><br>
        </div>
        <div>    if(status=~"[12][0-9][0-9]") {</div>
        <div>        route(NATMANAGE);</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>if(is_method("INVITE") &&
          is_present_hf("P-Asserted-Identity")) {</div>
        <div>remove_hf("P-Asserted-Identity");</div>
        <div>}</div>
        <div>}</div>
        <div><br>
        </div>
        <div># Manage failure routing cases</div>
        <div>failure_route[MANAGE_FAILURE] {</div>
        <div>    xlog("Failure! Going to failure route.");</div>
        <div>    route(NATMANAGE);</div>
        <div>    if (t_is_canceled()) exit;</div>
        <div><br>
        </div>
        <div>#!ifdef WITH_BLOCK3XX</div>
        <div>    # block call redirect based on 3xx replies.</div>
        <div>    if (t_check_status("3[0-9][0-9]")) {</div>
        <div>        t_reply("404","Not found");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div>#!endif</div>
        <div><br>
        </div>
        <div>#!ifdef WITH_BLOCK401407</div>
        <div>    # block call redirect based on 401, 407 replies.</div>
        <div>    if (t_check_status("401|407")) {</div>
        <div>        t_reply("404","Not found");</div>
        <div>        exit;</div>
        <div>    }</div>
        <div>#!endif</div>
        <div><br>
        </div>
        <div>#!ifdef WITH_VOICEMAIL</div>
        <div>    # serial forking</div>
        <div>    # - route to voicemail on busy or no answer (timeout)</div>
        <div>    if (t_check_status("486|408")) {</div>
        <div>        $du = $null;</div>
        <div>        route(TOVOICEMAIL);</div>
        <div>        exit;</div>
        <div>    }</div>
        <div>#!endif</div>
        <div>}</div>
        <div><br>
        </div>
        <div>event_route[topoh:msg-outgoing] {</div>
        <div>  if($sndto(ip)=="freeswitch") {</div>
        <div>    drop;</div>
        <div>  }</div>
        <div>  if($sndto(ip)=="81.24.193.248") {</div>
        <div>    drop;</div>
        <div>  }</div>
        }<br>
      </div>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        <br>
      </div>
      <div style="font-family: Calibri, Arial, Helvetica, sans-serif;
        font-size: 12pt; color: rgb(0, 0, 0);">
        Edward</div>
      <hr style="display:inline-block;width:98%" tabindex="-1">
      <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
          face="Calibri, sans-serif" color="#000000"><b>From:</b>
          Daniel-Constantin Mierla <a class="moz-txt-link-rfc2396E" href="mailto:miconda@gmail.com"><miconda@gmail.com></a><br>
          <b>Sent:</b> Tuesday, August 4, 2020 11:19 AM<br>
          <b>To:</b> Kamailio (SER) - Users Mailing List
          <a class="moz-txt-link-rfc2396E" href="mailto:sr-users@lists.kamailio.org"><sr-users@lists.kamailio.org></a>; Edward Romanenco
          <a class="moz-txt-link-rfc2396E" href="mailto:edward@telemessage.com"><edward@telemessage.com></a><br>
          <b>Subject:</b> Re: [SR-Users] Manipulating SDP IP for Inbound
          Calls</font>
        <div> </div>
      </div>
      <div>
        <p>Hello,</p>
        <p>the mangler module does not have any idea of inbound/outbound
          directions, so you can use it for any of them.</p>
        <p><br>
        </p>
        <p>Also, the nathelper module should have a function allowing to
          change the ip in the sdp, iirc.</p>
        <p><br>
        </p>
        <p>On the other hand, if you use rtppengine for the calls, then
          the ips should be replaced by it.</p>
        <p><br>
        </p>
        <p>Do not forget to use msg_apply_changes() in case you want
          those changes to be visible immediately in the configuration
          file.</p>
        <p><br>
        </p>
        <p>Cheers,<br>
          Daniel<br>
        </p>
        <p><br>
        </p>
        <div class="x_moz-cite-prefix">On 29.07.20 13:18, Edward
          Romanenco wrote:<br>
        </div>
        <blockquote type="cite">
          <style type="text/css" style="display:none">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
          <div style="font-family:Calibri,Arial,Helvetica,sans-serif;
            font-size:12pt; color:rgb(0,0,0)">
            Hey guys,</div>
          <div style="font-family:Calibri,Arial,Helvetica,sans-serif;
            font-size:12pt; color:rgb(0,0,0)">
            <br>
          </div>
          <div style="font-family:Calibri,Arial,Helvetica,sans-serif;
            font-size:12pt; color:rgb(0,0,0)">
            <div style="margin:0px; font-size:12pt;
              font-family:Calibri,Arial,Helvetica,sans-serif;
              color:black; background-color:rgb(255,255,255)">
              I am working on a project involving<span> </span><span
                style="margin:0px">Kamailio</span><span> </span>dockerezation,
              which is meant to run alongside Freeswitch and RTPEngine
              containers, on the basis of a Docker-Compose file which is
              launched on top of a CentOS 7.7 host system<span
                style="margin:0px">.</span></div>
            <br>
          </div>
          <div style="font-family:Calibri,Arial,Helvetica,sans-serif;
            font-size:12pt; color:rgb(0,0,0)">
            Anyway, I would love to know if there is any way to
            manipulate / mask the IP addresses that are being appended
            to a status 183 response for an incoming invite.</div>
          <div style="font-family:Calibri,Arial,Helvetica,sans-serif;
            font-size:12pt; color:rgb(0,0,0)">
            <br>
          </div>
          <div style="font-family:Calibri,Arial,Helvetica,sans-serif;
            font-size:12pt; color:rgb(0,0,0)">
            <span style="color:rgb(0,0,0);
              font-family:Calibri,Arial,Helvetica,sans-serif;
              font-size:12pt">For some reason which I am trying to
              figure out in parallel, Freeswitch uses the local network
              bridge subnet instead of the defined external RTP IPs, and
              I was wondering - Can I manipulate them using Kamailio? I
              know that </span><span style="color:rgb(0,0,0);
              font-family:Calibri,Arial,Helvetica,sans-serif;
              font-size:12pt">Mangler module can do it for outbound
              calls, but can I do the same for inbound?</span><br>
          </div>
          <div style="font-family:Calibri,Arial,Helvetica,sans-serif;
            font-size:12pt; color:rgb(0,0,0)">
            <br>
          </div>
          <div style="font-family:Calibri,Arial,Helvetica,sans-serif;
            font-size:12pt; color:rgb(0,0,0)">
            <span>v=0.<br>
            </span>
            <div>o=FreeSWITCH 1595974788 1595974789 IN IP4 172.18.0.40.<br>
            </div>
            <div>s=FreeSWITCH.<br>
            </div>
            <div>c=IN IP4 172.18.0.40.<br>
            </div>
            <div>t=0 0.<br>
            </div>
            <div>m=audio 45878 RTP/AVP 8 101.<br>
            </div>
            <div>a=rtpmap:8 PCMA/8000.<br>
            </div>
            <div>a=rtpmap:101 telephone-event/8000.<br>
            </div>
            <span>a=fmtp:101 0-16</span><br>
          </div>
          <div style="font-family:Calibri,Arial,Helvetica,sans-serif;
            font-size:12pt; color:rgb(0,0,0)">
            <span><br>
            </span></div>
          <div style="font-family:Calibri,Arial,Helvetica,sans-serif;
            font-size:12pt; color:rgb(0,0,0)">
            <span>Edward</span></div>
          <br>
          <fieldset class="x_mimeAttachmentHeader"></fieldset>
          <pre class="x_moz-quote-pre">_______________________________________________
Kamailio (SER) - Users Mailing List
<a class="x_moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org" moz-do-not-send="true">sr-users@lists.kamailio.org</a>
<a class="x_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>
        <pre class="x_moz-signature" cols="72">-- 
Daniel-Constantin Mierla -- <a class="x_moz-txt-link-abbreviated" href="http://www.asipto.com" moz-do-not-send="true">www.asipto.com</a>
<a class="x_moz-txt-link-abbreviated" href="http://www.twitter.com/miconda" moz-do-not-send="true">www.twitter.com/miconda</a> -- <a class="x_moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda" moz-do-not-send="true">www.linkedin.com/in/miconda</a>
Funding: <a class="x_moz-txt-link-freetext" href="https://www.paypal.me/dcmierla" moz-do-not-send="true">https://www.paypal.me/dcmierla</a></pre>
      </div>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla -- <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a>
Funding: <a class="moz-txt-link-freetext" href="https://www.paypal.me/dcmierla">https://www.paypal.me/dcmierla</a></pre>
  </body>
</html>