I tried with the example bellow, and it's forwarding the invite, but, i get request timeout, maybe i need to rewrite some contact headers?
Trace  for Incoming via sip_provider -> proxy -> asterisk:
This is my version: kamailio 5.2.3 (x86_64/linux) c36229

2019/07/30 17:23:18.258880 KAMAILIO_IP:5060 -> ASTERISK_IP:5060
INVITE sip:+XXXXXXXXXXX@KAMAILIO_IP:5060;user=phone SIP/2.0
Record-Route: <sip:KAMAILIO_IP;lr=on>
Via: SIP/2.0/UDP KAMAILIO_IP;branch=z9hG4bK5bf9.bf37af911cb7c8db93893a9ac5e160d3.0
Via: SIP/2.0/UDP PROVIDER_IP:5060;branch=z9hG4bKhfc5o810bggumum4q6g0.1
From: <sip:+ZZZZZZZZZZZ@PROVIDER_IP;user=phone>;tag=01011555152057
To: <sip:+XXXXXXXXXXX@SBC.MNC010.MCC226.3GPPNETWORK.ORG;user=phone>
Max-Forwards: 68
Call-ID: JIbR21823173009wbdGhEfElKfH0k@CLU05.MSCS.MNC010.MCC226.3GPPNETWORK.ORG
CSeq: 58311169 INVITE
P-Asserted-Identity: <sip:+ZZZZZZZZZZZ@PROVIDER_IP;user=phone>
Accept: application/sdp
Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,PRACK,UPDATE
P-Charging-Vector: icid-value=0D3D702000-0730-17231801;icid-generated-at=CLU05.MSCS.MNC010.MCC226.3GPPNETWORK.ORG;orig-ioi=MSCS.MNC010.MCC226.3GPPNETWORK.ORG
P-Early-Media: supported
Supported: 100rel,histinfo
Content-Type: application/sdp
Contact: <sip:+ZZZZZZZZZZZ@PROVIDER_IP:5060;transport=udp>
Content-Length: 561

v=0
o=- 14284082 14284082 IN IP4 PROVIDER_IP
s=-
c=IN IP4 PROVIDER_IP
t=0 0
a=sendrecv
m=audio 56884 RTP/AVP 96 97 98 8 18 99
c=IN IP4 PROVIDER_IP
b=RR:0
b=RS:0
a=rtpmap:96 AMR/8000
a=fmtp:96 mode-set=0,2,4,7;mode-change-period=2;mode-change-capability=2;mode-change-neighbor=1;max-red=0;octet-align=1
a=rtpmap:97 AMR/8000
a=fmtp:97 mode-set=7;max-red=0;octet-align=1
a=rtpmap:98 GSM-EFR/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=yes
a=rtpmap:99 telephone-event/8000
a=fmtp:99 0-15
a=ptime:20
a=maxptime:40
------------------------------------------------------------------------------------------------
#!KAMAILIO
#
# *** To run in debug mode:
#     - define WITH_DEBUG
# - flags
#   FLT_ - per transaction (message) flags
# FLB_ - per branch flags
#!define FLT_ACC 1
#!define FLT_ACCMISSED 2
#!define FLT_ACCFAILED 3

####### Global Parameters #########

#!ifdef WITH_DEBUG
debug=4
log_stderror=yes
#!else
debug=2
log_stderror=no
#!endif

memdbg=5
memlog=5

log_facility=LOG_LOCAL0

fork=yes
children=4
disable_tcp=yes
auto_aliases=no
port=5060
sip_warning=no

####### Modules Section ########
#loadmodule "db_mysql.so"
loadmodule "jsonrpcs.so"
loadmodule "kex.so"
loadmodule "corex.so"
loadmodule "tm.so"
loadmodule "tmx.so"
loadmodule "sl.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "ctl.so"
loadmodule "acc.so"
loadmodule "dispatcher.so"


# ----------------- setting module-specific parameters ---------------
# ----- jsonrpcs params -----
modparam("jsonrpcs", "pretty_format", 1)


# ----- rr params -----
# add value to ;lr param to cope with most of the UAs
modparam("rr", "enable_full_lr", 1)
# do not append from tag to the RR (no need for this script)
modparam("rr", "append_fromtag", 0)

# ----- acc params -----
modparam("acc", "log_flag", FLT_ACC)
modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
modparam("acc", "log_extra","src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd;src_ip=$si")

# ----- tm params -----
modparam("tm", "fr_timer", 2000)
modparam("tm", "fr_inv_timer", 40000)

# ----- dispatcher params -----
modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")
modparam("dispatcher", "flags", 0)


####### Routing Logic ########


# main request routing logic

request_route {

# per request initial checks
route(REQINIT);

# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans()) {
route(RELAY);
}
exit;
}

# handle retransmissions
if (!is_method("ACK")) {
if(t_precheck_trans()) {
t_check_trans();
exit;
}
t_check_trans();
}

# handle requests within SIP dialogs
route(WITHINDLG);

### only initial requests (no To tag)

# record routing for dialog forming requests (in case they are routed)
# - remove preloaded route headers
remove_hf("Route");
if (is_method("INVITE|SUBSCRIBE")) {
record_route();
}

# account only INVITEs
if (is_method("INVITE")) {
setflag(FLT_ACC); # do accounting
}

if (is_method("OPTIONS")) {
sl_send_reply("200","Keepalive");
exit;
}

# handle presence related requests
route(PRESENCE);

# handle registrations
route(REGISTRAR);

if ($rU==$null) {
# request with no Username in RURI
sl_send_reply("484","Address Incomplete");
exit;
}

# dispatch destinations
route(DISPATCH);
}


route[RELAY] {
if (!t_relay()) {
sl_reply_error();
}
exit;
}

# Per SIP request initial checks
route[REQINIT] {
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}

if(!sanity_check("1511", "7")) {
xlog("Malformed SIP message from $si:$sp\n");
exit;
}
}

# Handle requests within SIP dialogs
route[WITHINDLG] {
if (has_totag()) {
# sequential request withing a dialog should
# take the path determined by record-routing
if (loose_route()) {
if (is_method("BYE")) {
setflag(FLT_ACC); # do accounting ...
setflag(FLT_ACCFAILED); # ... even if the transaction fails
}
route(RELAY);
} else {
if (is_method("SUBSCRIBE") && uri == myself) {
# in-dialog subscribe requests
route(PRESENCE);
exit;
}
if ( is_method("ACK") ) {
if ( t_check_trans() ) {
# non loose-route, but stateful ACK;
# must be ACK after a 487 or e.g. 404 from upstream server
t_relay();
exit;
} else {
# ACK without matching transaction ... ignore and discard.
exit;
}
}
sl_send_reply("404","Not here");
}
exit;
}
}

# Handle SIP registrations
route[REGISTRAR] {
if(!is_method("REGISTER"))
return;

sl_send_reply("404", "No registrar");
exit;
}

# Presence server route
route[PRESENCE] {
if(!is_method("PUBLISH|SUBSCRIBE"))
return;

sl_send_reply("404", "Not here");
exit;
}

# Dispatch requests
route[DISPATCH] {
# round robin dispatching on gateways group '1'
if(!ds_select_dst("1", "4")) {
send_reply("404", "No SIP destionations alive");
exit;
}
xdbg("--- SCRIPT: going to <$ru> via <$du> (attrs: $xavp(_dsdst_=>attrs))\n");
t_on_failure("RTF_DISPATCH");
route(RELAY);
exit;
}

# Try next destionations in failure route
failure_route[RTF_DISPATCH] {
if (t_is_canceled()) {
exit;
}
# next DST - only for 500 or local timeout
if (t_check_status("500")
or (t_branch_timeout() and !t_branch_replied())) {
if(ds_next_dst()) {
xdbg("--- SCRIPT: retrying to <$ru> via <$du> (attrs: $xavp(_dsdst_=>attrs))\n");
t_on_failure("RTF_DISPATCH");
route(RELAY);
exit;
}
}
}

On Fri, Jul 26, 2019 at 12:28 AM Mihai Cezar <m@mokalife.ro> wrote:
I did test without the drop(); same result.
Will try with this https://kamailio.org/docs/modules/5.2.x/modules/dispatcher.html#dispatcher.ex.config, but i don't use register the sip trunk using IP authentication (there is no nat in this scenario, all private IPs I wanted to avoid rtpproxy/rtpengine).

Thanks!


On Thu, Jul 25, 2019 at 11:51 PM Henning Westerholt <hw@skalatan.de> wrote:

Hi Mihai,

indeed sounds like this. :-) There is a drop call in your cfg in the path that is taken in your sip trace. This will cause a drop of the message that is currently processed.

The default cfg is a bit larger with all the #!ifdef cases, and maybe a bit difficult to understand. Have you tried this cfg:

https://kamailio.org/docs/modules/5.2.x/modules/dispatcher.html#dispatcher.ex.config

This is just a simple kamailio dispatcher cfg (stateful forwarding and record routing). Just add your asterisk server to a dispatcher.list file and it should work. This cfg will block REGISTER and presence requests, but you can easily deactivate it.

Cheers,

Henning


Am 25.07.19 um 21:12 schrieb Mihai Cezar:
No, it dosen't forward it to the SIP provider, it basicaly loops, i am guessing that my config its the problem...

On Thu, Jul 25, 2019 at 9:53 PM Henning Westerholt <hw@skalatan.de> wrote:

Hello Mihai,

your trace just shows the INVITE, 100,  183. There is no 200 OK, therefore also no ACK.

Is there some thing missing? Does the called side actually accept the call?

Cheers,

Henning

Am 25.07.19 um 19:23 schrieb Mihai Cezar:
Well, i've tried both opensips and kamailio but with kamailio i got the most far.
Bellow it's a trace of an outgoing call, the trace is from kamailio box. 

Legend: 10.1.1.10 is the Asterisk Box, 10.1.1.4 is Kamailio.

2019/07/25 20:16:24.479179 10.1.1.10:5060 -> 10.1.1.4:5060
INVITE sip:+40XXXXXXXXX@10.1.1.4;user=phone SIP/2.0
Via: SIP/2.0/UDP 10.1.1.10:5060;branch=z9hG4bK3ecba174;rport
Max-Forwards: 70
From: "test" <sip:+40YYYYYYYY@10.1.1.10>;tag=as5ce97f3d
To: <sip:+40XXXXXXXXX@10.1.1.4;user=phone>
Contact: <sip:+40YYYYYYYY@10.1.1.10:5060>
Call-ID: 7c1169bf0b7a09472dd455d76b6c12bb@10.1.1.10
CSeq: 102 INVITE
User-Agent: Asterisk PBX
Date: Thu, 25 Jul 2019 17:16:09 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 238

2019/07/25 20:16:24.482259 10.1.1.4:5060 -> 10.1.1.10:5060
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.1.1.10:5060;branch=z9hG4bK3ecba174;rport=5060;received=10.1.1.10
From: "test" <sip:+40YYYYYYYY@10.1.1.10>;tag=as5ce97f3d
To: <sip:+40XXXXXXXXX@10.1.1.4;user=phone>
Call-ID: 7c1169bf0b7a09472dd455d76b6c12bb@10.1.1.10
CSeq: 102 INVITE
Server: kamailio (5.2.3 (x86_64/linux))
Content-Length: 0


2019/07/25 20:16:24.482385 10.1.1.4:5060 -> 10.1.1.10:5060
SIP/2.0 183 Outgoing session to Avoxi
Via: SIP/2.0/UDP 10.1.1.10:5060;branch=z9hG4bK3ecba174;rport=5060;received=10.1.1.10
From: "test" <sip:+40YYYYYYYY@10.1.1.10>;tag=as5ce97f3d
To: <sip:+40XXXXXXXXX@10.1.1.4;user=phone>;tag=e68db714ad3ba80833ca2c670d982872.aebb
Call-ID: 7c1169bf0b7a09472dd455d76b6c12bb@10.1.1.10
CSeq: 102 INVITE
Server: kamailio (5.2.3 (x86_64/linux))
Content-Length: 0

On Thu, Jul 25, 2019 at 7:53 PM Sergiu Pojoga <pojogas@gmail.com> wrote:
Have you tried changing the trunk's name from opensips-trunk to kamailio-trunk?

On the serious side, a SIP trace would help.
 

On Thu, Jul 25, 2019 at 12:26 PM Mihai Cezar <cezar@mokalife.ro> wrote:
Hi all,

I've tried to create a reverse proxy to forward incoming request that came from SIP provider to Asterisk PBX and forward the requests from asterisk to kamailio then sip provider.
What i get is that I see the invite, but is like no ACK.
Thanks in advance.
M


kamailio.cfg:

#!KAMAILIO
#

####### Defined Values #########
# - flags
#   FLT_ - per transaction (message) flags
# FLB_ - per branch flags
#!define FLT_ACC 1
#!define FLT_ACCMISSED 2
#!define FLT_ACCFAILED 3
#!define FLT_NATS 5

#!define FLB_NATB 6
#!define FLB_NATSIPPING 7

####### Global Parameters #########
### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
debug=3
log_stderror=yes
memdbg=5
memlog=5

log_facility=LOG_LOCAL0
log_prefix="{$mt $hdr(CSeq) $ci} "
children=1

server_id = 10
xavp_via_params = "via"
disable_tcp=yes
auto_aliases=no
listen=udp:0.0.0.0:5060 

####### Modules Section ########

loadmodule "jsonrpcs.so"
loadmodule "kex.so"
loadmodule "corex.so"
loadmodule "tm.so"
loadmodule "tmx.so"
loadmodule "sl.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "ctl.so"
loadmodule "cfg_rpc.so"
loadmodule "acc.so"
loadmodule "counters.so"

# ----------------- setting module-specific parameters ---------------


# ----- jsonrpcs params -----
modparam("jsonrpcs", "pretty_format", 1)
modparam("jsonrpcs", "fifo_name", "/var/run/kamailio/kamailio_rpc.fifo")
modparam("jsonrpcs", "dgram_socket", "/var/run/kamailio/kamailio_rpc.sock")
modparam("ctl", "binrpc", "unix:/var/run/kamailio/kamailio_ctl")

# ----- tm params -----
modparam("tm", "failure_reply_mode", 3)
modparam("tm", "fr_timer", 30000)
modparam("tm", "fr_inv_timer", 120000)
modparam("rr", "enable_full_lr", 0)
modparam("rr", "append_fromtag", 0)
modparam("acc", "early_media", 0)
modparam("acc", "report_ack", 0)
modparam("acc", "report_cancels", 0)
modparam("acc", "detect_direction", 0)
modparam("acc", "log_flag", FLT_ACC)
modparam("acc", "log_missed_flag", FLT_ACCMISSED)
modparam("acc", "log_extra",
"src_user=$fU;src_domain=$fd;src_ip=$si;"
"dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)

####### Routing Logic ########

request_route {

# per request initial checks
route(REQINIT);

# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans()) {
route(RELAY);
}
exit;
}

# handle retransmissions
if (!is_method("ACK")) {
if(t_precheck_trans()) {
t_check_trans();
exit;
}
t_check_trans();
}

# handle requests within SIP dialogs
route(WITHINDLG);

# record routing for dialog forming requests (in case they are routed)
remove_hf("Route");
if (is_method("INVITE|SUBSCRIBE|REFER")) {
record_route();
}

# account only INVITEs
if (is_method("INVITE")) {
setflag(FLT_ACC);
sl_send_reply("100","Trying");

if ($si == "172.16.16.1") {
sl_send_reply("183","Incoming session from Avoxi");
rewritehost("10.1.1.10");
#exit;
}
else if ($si == "10.1.1.10"){
# receiving response from client
sl_send_reply("183","Outgoing session to Avoxi");
#rewritehost("172.16.16.1");
drop;
exit;
}
else {
sl_send_reply("500","No configured IP!");
drop;
exit;
}
}

if ($rU==$null) {
sl_send_reply("484","Address Incomplete");
exit;
}

# received from main server - send to client and add via tokens for anycast handling
via_add_srvid("1");
$xavp(via=>node) = "10.1.1.4";
via_add_xavp_params("1");
route(RELAY);
exit;
}

# Wrapper for relaying requests
route[RELAY] {

# enable additional event routes for forwarded requests
# - serial forking, RTP relaying handling, a.s.o.
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;
}

# Per SIP request initial checks
route[REQINIT] {
if($ua =~ "friendly-scanner|sipcli|VaxSIPUserAgent") {
# silent drop for scanners - uncomment next line if want to reply
sl_send_reply("200", "OK");
exit;
}

if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}

if(is_method("OPTIONS") && uri==myself && $rU==$null) {
sl_send_reply("200","Keepalive");
exit;
}

if(!sanity_check("1511", "7")) {
xlog("Malformed SIP message from $si:$sp\n");
exit;
}

if ($si == "10.1.1.4") {
                xlog("L_WARN", "$ci|end|dropping message");
                exit;
    }

}

# Handle requests within SIP dialogs
route[WITHINDLG] {
if (!has_totag()) return;
if (loose_route()) {
if (is_method("BYE")) {
setflag(FLT_ACC);
setflag(FLT_ACCFAILED);
} else if ( is_method("NOTIFY") ) {
record_route();
}
route(RELAY);
exit;
}

if ( is_method("ACK") ) {
if ( t_check_trans() ) {
route(RELAY);
exit;
} else {
exit;
}
}
sl_send_reply("400","Loop detected");
exit;
}

# TM manage for outgoing branches
branch_route[MANAGE_BRANCH] {
xdbg("new branch [$T_branch_idx] to $ru\n");
}

# TM manage for incoming replies
onreply_route[MANAGE_REPLY] {
xdbg("incoming reply\n");
}

# TM manage for failure routing cases
failure_route[MANAGE_FAILURE] {
if (t_is_canceled()) exit;
}


asterisk - sip.conf

[opensips-trunk](sip-provider)
fromdomain=10.1.1.10
host=10.1.1.4
context=from-trunk
type=friend
insecure=invite,port
trunk=yes
_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users

_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
-- 
Henning Westerholt - https://skalatan.de/blog/
Kamailio services - https://skalatan.de/services
-- 
Henning Westerholt - https://skalatan.de/blog/
Kamailio services - https://skalatan.de/services