Hi,
Just a suggestion to put the contact alias function under the "is_first_hop()" condition. That'll help you in case multiple Kamailios are in the call path. 

if(is_first_hop()){
   add_contact_alias();
}
   
Regards,
Sammy
 

On Thu, Apr 4, 2019 at 6:07 AM Ilie Soltanici <iliusha.md@gmail.com> wrote:
Adding Contact alias in 200 OK, fixed the issue:

if (nat_uac_test(64)) {
add_contact_alias();
}

Thank You.

În mie., 3 apr. 2019 la 23:58, Ilie Soltanici <iliusha.md@gmail.com> a scris:
Hello,

Config is more or less like the standard one:

route[WITHINDLG] {
  if (!has_totag()) return;
if (loose_route()) {
    route(RURIALIAS);
    if ( is_method("ACK") ) {
      xlogl("L_INFO", "[$cfg(route)] ACK is forwarded statelessy\n");
      route(NATMANAGE);
    } else if (is_method("NOTIFY") ) {
# Add Record-Route for in-dialog NOTIFY as per RFC 6665.
route(RECORD_ROUTE);
}
    xlogl("L_INFO", "[$cfg(route)] In Dialog loose_route, Relaying\n");
route(RELAY);
      exit;
    };

    if (is_method("SUBSCRIBE") && uri == myself) {
      xlogl("L_INFO", "[$cfg(route)] in-dialog subscribe requests, Checking Dialog.\n");
      route(PRESENCE);
      exit;
    }

    if ( is_method("ACK") ) {
      if ( t_check_trans() ) {
        xlogl("L_INFO", "[$cfg(route)] ACK in transaction. Relaying\n");
        route(RELAY);
        exit;
        } else {
          xlogl("L_WARN", "[$cfg(route)] ACK without matching transaction ... ignore and discard\n");
          sl_send_reply("606", "Not Acceptable");
          exit;
        }
      }

      xlogl("L_WARN", "[$cfg(route)] Unknown Dialog\n");
      sl_send_reply("404","Not Found");
      exit;
}

route[RURIALIAS] {
    if(isdsturiset() || ($du != "")) {
        xlogl("L_INFO", "[$cfg(route)]: Destination URI is set, no un-aliasing is needed\n");
        return;
    }

    xlogl("L_INFO", "[$cfg(route)] --Start Route--\n");
    xlogl("L_INFO", "[$cfg(route)]: Route using R-URI, any alias on R-URI ('$ru')?\n");

    handle_ruri_alias();
    switch ($rc) {
    case -1:
        xlogl("L_WARN", "[$cfg(route)]: Failed to handle alias of R-URI $ru\n");
        send_reply("400","Bad Request");
        exit;
    case 1:
        xlogl("L_INFO", "[$cfg(route)]: Alias parsed, routing $rm from $fu to $du\n");
        break;
    case 2:
        xlogl("L_INFO", "[$cfg(route)]: Alias not found, routing $rm from $fu to $ru\n");
        break;
    };

    return;
}

route[NATMANAGE] {
if(has_body("application/sdp")) {
      route(RTPMANAGE);
    }

    # Set FLB_NATB? Only in within-dialog request with nat=yes on Route header initiated by AS
    if (is_request() && has_totag() && check_route_param("nat=yes") && isflagset(FLS_FROM_ASTERISK)) {
       setbflag(FLB_NATB);
    }

    # Return unless FLT_NATS or FLB_NATB are set
    if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))) {
        xlogl("L_INFO", "[$cfg(route)] No endpoint is behind NAT, return\n");
        if(nat_uac_test("1")) {
          xlogl("L_INFO", "[$cfg(route)] Contact is behind NAT, Fixing\n");
          fix_nated_contact();
        }
        return;
    } else {
        xlogl("L_INFO", "[$cfg(route)] One or both endpoints are behind NAT, continue!\n");
    }

    # Add nat=yes in record-route? Only in initial requests when called from branch_route
    if (is_request() && !has_totag() && t_is_branch_route()) {
        xlogl("L_INFO", "[$cfg(route)] Add nat=yes to record-route (reason: initial request called from branch route)\n");
        add_rr_param(";nat=yes");
    }

  if (is_reply()) {
      if(isbflagset(FLB_NATB)) {
      fix_nated_contact();
      }
    }
}

route[RELAY] {
route(SETUP_BY_TRANSPORT);

if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {
if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");
}
if (is_method("INVITE|SUBSCRIBE|UPDATE")) {
if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");
}
if (is_method("INVITE")) {
if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
}

if (!t_relay()) {
sl_reply_error();
}
exit;
}

}

route[SETUP_BY_TRANSPORT] {

 if ($ru =~ "transport=ws") {
  xlogl("L_INFO","[$cfg(route)] Request going to WS");
if(sdp_with_transport("RTP/SAVPF")) {
          xlogl("L_INFO","[$cfg(route)] Request going from WS to WS");
          rtpengine_manage("force trust-address replace-origin replace-session-connection ICE=force");
          t_on_reply("REPLY_WS_TO_WS");
          return;
        }
  xlogl("L_INFO","[$cfg(route)] Request going to WS from AS");
rtpengine_manage("rtcp-mux-offer generate-mid DTLS=passive SDES-off ICE=force RTP/SAVPF");
  force_send_socket(tls:MY_EXTERNAL_IP_ADDR:10443);
t_on_reply("REPLY_FROM_WS");
}
else if ($proto =~ "ws") {
xlog("L_INFO", "Request coming from WS");
rtpengine_manage("rtcp-mux-demux DTLS=off SDES-off ICE=remove RTP/AVP");
t_on_reply("REPLY_TO_WS");
}
else {
xlog("L_INFO", "This is a classic phone call");
rtpengine_manage("replace-origin replace-session-connection");
t_on_reply("MANAGE_CLASSIC_REPLY");
}
}

onreply_route[REPLY_TO_WS] {

xlog("L_INFO", "Reply from softphone: $rs");

if (t_check_status("183")) {
change_reply_status("180", "Ringing");
remove_body();
exit;
}

if(!(status=~"[12][0-9][0-9]"))
return;

# rtpengine_manage("froc+SP");
xlogl("L_INFO","Fixing ICE/SAVPF Parameters");
rtpengine_manage("rtcp-mux-offer generate-mid DTLS=passive SDES-off ICE=force RTP/SAVPF");

}

onreply_route[REPLY_FROM_WS] {

xlog("L_INFO", "Reply from webrtc client: $rs");

if(status=~"[12][0-9][0-9]") {
rtpengine_manage("force trust-address replace-origin replace-session-connection ICE=remove RTP/AVP");
# rtpengine_manage("froc-sp");
route(NATMANAGE);
}
}

onreply_route[MANAGE_CLASSIC_REPLY] {
xlog("L_INFO", "Boring reply from softphone: $rs");

if(status=~"[12][0-9][0-9]") {
rtpengine_manage("replace-origin replace-session-connection");
# rtpengine_manage("co");
route(NATMANAGE);
}
}

onreply_route[REPLY_WS_TO_WS] {
        xlog("L_INFO", "WS to WS");
        if(status=~"[12][0-9][0-9]") {
        rtpengine_manage("force trust-address replace-origin replace-session-connection ICE=force");
                route(NATMANAGE);
        }
}

Thank you.
_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users