Hi List!
I try to use the dispatcher module to route calls to my ivr systems. But it didnt load the gateway. I didnt see my xlog message after the ds_select_dst()
Any hints? Gateway is Active and Probing.
#!ifdef WITH_DISPATCHER if (!lookup("location")) { if(ds_select_dst("1", "4")) xlog("DISPATCHER ds_select_dst\n");
#forward(); } #!endif
[root@kamailio1 log]# kamctl fifo ds_list SET_NO:: 1 SET:: 1 URI:: sip:172.20.100.61:5060 flags=AP priority=0 attrs=
Hello,
On 4/16/12 12:25 PM, Karsten Horsmann wrote:
Hi List!
I try to use the dispatcher module to route calls to my ivr systems. But it didnt load the gateway. I didnt see my xlog message after the ds_select_dst()
Any hints? Gateway is Active and Probing.
#!ifdef WITH_DISPATCHER if (!lookup("location")) { if(ds_select_dst("1", "4")) xlog("DISPATCHER ds_select_dst\n");
#forward(); }
#!endif
[root@kamailio1 log]# kamctl fifo ds_list SET_NO:: 1 SET:: 1 URI:: sip:172.20.100.61:5060 flags=AP priority=0 attrs=
are you forwarding the requests somehow? the forward() action in your example above is comented.
Cheers, Daniel
Hi Daniel,
if i forward it - then it loops to itself. And the if condition tolds me that i didnt work :(
Hi,
you should distinguish between ds_select_dst and ds_select_domain: ds_select_dst only sets $du (Next Hop) while ds_select_domain actually rewrites the Request URI (like a lookup would do). Maybe this is your problem.
Thanks, Carsten
2012/4/16 Karsten Horsmann khorsmann@gmail.com:
Hi Daniel,
if i forward it - then it loops to itself. And the if condition tolds me that i didnt work :(
-- Mit freundlichen Grüßen *Karsten Horsmann*
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Hi Carsten,
its still the same if i use ds_select_domain to rewrite the ruri. It seems not to fetch the values from the database.
#!ifdef WITH_DISPATCHER if (!lookup("location")) { if(ds_select_domain("1", "4")) { xlog("DISPATCHER ds_select_dst\n"); forward(); } } #!endif
2012/4/16 Carsten Bock carsten@ng-voice.com:
Hi,
you should distinguish between ds_select_dst and ds_select_domain: ds_select_dst only sets $du (Next Hop) while ds_select_domain actually rewrites the Request URI (like a lookup would do). Maybe this is your problem.
Hi,
When you use forward( ) it loops itself since the dispatcher function is not selecting a destination, and the SIP request is destined to your server. Do you have any error in your log file?
Reda
On Mon, Apr 16, 2012 at 14:31, Karsten Horsmann khorsmann@gmail.com wrote:
Hi Carsten,
its still the same if i use ds_select_domain to rewrite the ruri. It seems not to fetch the values from the database.
#!ifdef WITH_DISPATCHER if (!lookup("location")) { if(ds_select_domain("1", "4")) { xlog("DISPATCHER ds_select_dst\n"); forward(); } } #!endif
2012/4/16 Carsten Bock carsten@ng-voice.com:
Hi,
you should distinguish between ds_select_dst and ds_select_domain: ds_select_dst only sets $du (Next Hop) while ds_select_domain actually rewrites the Request URI (like a lookup would do). Maybe this is your problem.
-- Mit freundlichen Grüßen *Karsten Horsmann*
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Hi Reda,
there is no error in the log file. Its hard to debug this function.
2012/4/16 Reda Aouad reda.aouad@gmail.com:
Hi,
When you use forward( ) it loops itself since the dispatcher function is not selecting a destination, and the SIP request is destined to your server. Do you have any error in your log file?
Reda
Can you try another algorithm? Can you set debug=3 and see what's happening?
Reda
On Mon, Apr 16, 2012 at 14:54, Karsten Horsmann khorsmann@gmail.com wrote:
Hi Reda,
there is no error in the log file. Its hard to debug this function.
2012/4/16 Reda Aouad reda.aouad@gmail.com:
Hi,
When you use forward( ) it loops itself since the dispatcher function is
not
selecting a destination, and the SIP request is destined to your server.
Do
you have any error in your log file?
Reda
-- Mit freundlichen Grüßen *Karsten Horsmann*
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Hi Reda,
my pitfall was that the probing takes 30seconds until the gateway is active until startup. So if i test it right after kamctl restart the gateway was inactive.
Now i seems that my working multihomed config needs some help to fix nat for dispatching. For locatet user it works, for dispatching i run into nat-nightmare again (wrong Contact Header on private ip side and so one)....
Any hints?
# Main SIP request routing logic # - processing of any incoming SIP request starts with this route # - note: this is the same as route { ... } request_route { xlog("begin routing\n"); setflag(1); # log this msg
#acc: setflag(2); setflag(3); setflag(4);
# ----------------------------------------------------------------- # Sanity Check Section # ----------------------------------------------------------------- # per request initial checks route(REQINIT);
# ----------------------------------------------------------------- # Record Route Section # ----------------------------------------------------------------- if (method!="REGISTER") { record_route(); };
if (method=="BYE" || method=="CANCEL") { unforce_rtp_proxy(); xlog("L_DBG","BYE OR CANCEL. Dialog lifetime: $DLG_lifetime Status: $DLG_status\n"); if ($DLG_status==5) { route(6); } }
# ----------------------------------------------------------------- # Loose Route Section # ----------------------------------------------------------------- if (loose_route()) { xlog("loose_route ***************\n"); if ((method=="INVITE" || method=="REFER") && !has_totag()) { sl_send_reply("403", "Forbidden"); return; };
if (method=="BYE" && $DLG_status==5) { xlog("L_DBG","BYE. Dialog lifetime: $DLG_lifetime Status: $DLG_status\n"); route(6); }
if (method=="INVITE") { route(5);
if (!proxy_authorize("$td","subscriber")) { proxy_challenge("$td","0"); return; } else if (!check_from()) { sl_send_reply("403", "Use From=ID"); return; };
consume_credentials(); setflag(6); force_rport(); fix_nated_contact();
if (dst_ip == 172.20.100.74){ rtpproxy_manage("fiewc","212.59.42.189"); } else { rtpproxy_manage("feiwc","172.20.100.74"); } }; route(1); return; };
if (method=="CANCEL") { xlog("L_DBG","CANCEL. Dialog lifetime: $DLG_lifetime Status: $DLG_status\n"); route(6); }
# ----------------------------------------------------------------- # Call Type Processing Section # ----------------------------------------------------------------- xlog("call type processing\n"); if (uri!=myself) { route(4); route(1); return; };
if (method=="ACK") { route(1); return; } else if (method=="CANCEL") { route(1); return; } else if (method=="INVITE") { route(5); route(3); return; } else if (method=="REGISTER") { route(2); return; };
xlog("lookup aliases\n"); lookup("aliases"); if (uri!=myself) { route(4); route(1); return; };
xlog("!lookup location\n"); if (!lookup("location")) { sl_send_reply("404", "User Not Found"); return; };
route(1); }
route[1] {
# ----------------------------------------------------------------- # Default Message Handler # -----------------------------------------------------------------
t_on_reply("1");
if (!t_relay()) { if (method=="INVITE" && isflagset(6)) { unforce_rtp_proxy(); }; sl_reply_error(); }; }
route[2] {
# ----------------------------------------------------------------- # REGISTER Message Handler # ----------------------------------------------------------------
setflag(6); fix_nated_register(); force_rport();
sl_send_reply("100", "Trying");
if (!www_authorize("$td","subscriber")) { www_challenge("$td","0"); return; };
if (!check_to()) { sl_send_reply("401", "Unauthorized"); return; };
consume_credentials(); if (!save("location")) { log(1,"Error :-(.\n"); sl_reply_error(); }; }
route[3] {
# ----------------------------------------------------------------- # INVITE Message Handler # ----------------------------------------------------------------- xlog("route-3\n"); setflag(6); lookup("aliases"); if (uri!=myself) { route(4); route(1); return; };
#!ifdef WITH_DISPATCHER if (!lookup("location")) { if(ds_select_domain("1", "4")) { xlog("DISPATCHER ds_select_dst\n"); route(4); #route(1); forward(); return; } } #!endif
if (!lookup("location")) { xlog("404 User not found\n"); sl_send_reply("404", "User Not Found"); return; };
route(4); route(1); }
route[4] {
# ----------------------------------------------------------------- # NAT Traversal Section # -----------------------------------------------------------------
force_rport(); fix_nated_contact(); if (dst_ip == 172.20.100.74){ xlog("INVITE 4 intern extern\n"); rtpproxy_manage("fiewc","222.222.222.222"); } else { xlog("INVITE 4 extern intern\n"); rtpproxy_manage("feiwc","172.20.100.74"); } }
route[5] {
# ---------------------------------------------------------------- # Save here CDR Variables # ----------------------------------------------------------------
#save sourceIP $sht(a=>$ci::srcip) = $si; $sht(a=>$ci::fromdplname) = $fn; $sht(a=>$ci::touri) = $tu; $sht(a=>$ci::fromuri) = $fu; $sht(a=>$ci::useragent) = $ua; }
route[6] {
# ---------------------------------------------------------------- # Write CDR via Perl and free previously CDR Variables # ----------------------------------------------------------------
#save variables from htable in AVPs, so we can access them from perl (without memory leak) $avp(s:4com_srcip)=$sht(a=>$ci::srcip); $avp(s:4com_fromdplname)=$sht(a=>$ci::fromdplname); $avp(s:4com_touri)=$sht(a=>$ci::touri); $avp(s:4com_fromuri)=$sht(a=>$ci::fromuri); $avp(s:4com_useragent)=$sht(a=>$ci::useragent); $avp(s:4com_invtrytime)=$sht(a=>$ci::invtrytime);
#write CDR perl_exec("write_cdr");
#free all variables saved in hashtable sht_rm_name_re("a=>$ci::.*"); }
onreply_route[1] {
rtpproxy_manage("fwc"); fix_nated_contact();
#if (is_gflag("0")) log(1,"-- 0 ist gesetzt.\n"); #if (is_gflag("1")) log(1,"-- 1 ist gesetzt.\n"); #if (is_gflag("2")) log(1,"-- 2 ist gesetzt.\n"); #if (is_gflag("3")) log(1,"-- 3 ist gesetzt.\n");
#if (is_gflag("1")) #{ # log(1,"Recording this Call\n"); # start_recording(); #} #else #{ # log(1,"NOT recording this Call\n"); #}
xlog("L_DBG", "-- Status: $rs METHOD $rm Reason $rr\n"); if ($rm=="INVITE") { xlog("L_DBG", "Method is INVITE\n"); if ($rs=~"1[0-9][0-9]") { xlog("L_DBG", "Status is in 100-class Trying\n"); $sht(a=>$ci::invtrytime) = $Ts; #perl_exec("got_invite_trying"); } else if ($rs=~"4[0-9][0-9]") { xlog("L_DBG", "Status is in 400-class - ClientErrors\n"); #xlog("L_DBG", "SI aus shared: $sht(a=>$ci::srcip)\n"); #perl_exec("write_cdr"); #sht_rm_name_re("a=>$ci::.*"); route(6); } } }
#### # Per SIP request initial checks route[REQINIT] { #!ifdef WITH_ANTIFLOOD # flood dection from same IP and traffic ban for a while # be sure you exclude checking trusted peers, such as pstn gateways # - local host excluded (e.g., loop to self) if(src_ip!=myself) { if($sht(ipban=>$si)!=$null) { # ip is already blocked xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n"); exit; } if (!pike_check_req()) { xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n"); $sht(ipban=>$si) = 1; exit; } } #!endif
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; } }
Well, 30 seconds seems to be the timeout of your SIP client: I suspect your client sends a 200OK but doesn't receive the ACK for it, and hence times out 30 seconds after and terminates the call. You can run ngrep to trace the call and see where the ACK is routed, and if it is routed to the correct address, if anything is not correct in its header. Personally, I run wireshark over an X11 tunnel for the GUI which helps a lot. If you provide ngrep trace, we may help you better.
I had the exact same problem once, but don't remember what the reason was.. maybe incorrect loose routing section.. Also try another client to make sure yours isn't broken..
Reda
On Mon, Apr 16, 2012 at 16:40, Karsten Horsmann khorsmann@gmail.com wrote:
Hi Reda,
my pitfall was that the probing takes 30seconds until the gateway is active until startup. So if i test it right after kamctl restart the gateway was inactive.
Now i seems that my working multihomed config needs some help to fix nat for dispatching. For locatet user it works, for dispatching i run into nat-nightmare again (wrong Contact Header on private ip side and so one)....
Any hints?
# Main SIP request routing logic # - processing of any incoming SIP request starts with this route # - note: this is the same as route { ... } request_route { xlog("begin routing\n"); setflag(1); # log this msg
#acc: setflag(2); setflag(3); setflag(4);
# ----------------------------------------------------------------- # Sanity Check Section # ----------------------------------------------------------------- # per request initial checks route(REQINIT); # ----------------------------------------------------------------- # Record Route Section # ----------------------------------------------------------------- if (method!="REGISTER") { record_route(); }; if (method=="BYE" || method=="CANCEL") { unforce_rtp_proxy(); xlog("L_DBG","BYE OR CANCEL. Dialog lifetime:
$DLG_lifetime Status: $DLG_status\n"); if ($DLG_status==5) { route(6); } }
# ----------------------------------------------------------------- # Loose Route Section # ----------------------------------------------------------------- if (loose_route()) { xlog("loose_route ***************\n"); if ((method=="INVITE" || method=="REFER") && !has_totag()) { sl_send_reply("403", "Forbidden"); return; }; if (method=="BYE" && $DLG_status==5) { xlog("L_DBG","BYE. Dialog lifetime: $DLG_lifetime
Status: $DLG_status\n"); route(6); }
if (method=="INVITE") { route(5); if (!proxy_authorize("$td","subscriber")) { proxy_challenge("$td","0"); return; } else if (!check_from()) { sl_send_reply("403", "Use From=ID"); return; }; consume_credentials(); setflag(6); force_rport(); fix_nated_contact(); if (dst_ip == 172.20.100.74){ rtpproxy_manage("fiewc","212.59.42.189"); } else { rtpproxy_manage("feiwc","172.20.100.74"); } }; route(1); return; }; if (method=="CANCEL") { xlog("L_DBG","CANCEL. Dialog lifetime: $DLG_lifetime
Status: $DLG_status\n"); route(6); }
# ----------------------------------------------------------------- # Call Type Processing Section # ----------------------------------------------------------------- xlog("call type processing\n"); if (uri!=myself) { route(4); route(1); return; }; if (method=="ACK") { route(1); return; } else if (method=="CANCEL") { route(1); return; } else if (method=="INVITE") { route(5); route(3); return; } else if (method=="REGISTER") { route(2); return; }; xlog("lookup aliases\n"); lookup("aliases"); if (uri!=myself) { route(4); route(1); return; }; xlog("!lookup location\n"); if (!lookup("location")) { sl_send_reply("404", "User Not Found"); return; }; route(1);
}
route[1] {
# ----------------------------------------------------------------- # Default Message Handler # ----------------------------------------------------------------- t_on_reply("1"); if (!t_relay()) { if (method=="INVITE" && isflagset(6)) { unforce_rtp_proxy(); }; sl_reply_error(); };
}
route[2] {
# ----------------------------------------------------------------- # REGISTER Message Handler # ---------------------------------------------------------------- setflag(6); fix_nated_register(); force_rport(); sl_send_reply("100", "Trying"); if (!www_authorize("$td","subscriber")) { www_challenge("$td","0"); return; }; if (!check_to()) { sl_send_reply("401", "Unauthorized"); return; }; consume_credentials(); if (!save("location")) { log(1,"Error :-(.\n"); sl_reply_error(); };
}
route[3] {
# ----------------------------------------------------------------- # INVITE Message Handler # ----------------------------------------------------------------- xlog("route-3\n"); setflag(6); lookup("aliases"); if (uri!=myself) { route(4); route(1); return; };
#!ifdef WITH_DISPATCHER if (!lookup("location")) { if(ds_select_domain("1", "4")) { xlog("DISPATCHER ds_select_dst\n"); route(4); #route(1); forward(); return; } } #!endif
if (!lookup("location")) { xlog("404 User not found\n"); sl_send_reply("404", "User Not Found"); return; }; route(4); route(1);
}
route[4] {
# ----------------------------------------------------------------- # NAT Traversal Section # ----------------------------------------------------------------- force_rport(); fix_nated_contact(); if (dst_ip == 172.20.100.74){ xlog("INVITE 4 intern extern\n"); rtpproxy_manage("fiewc","222.222.222.222"); } else { xlog("INVITE 4 extern intern\n"); rtpproxy_manage("feiwc","172.20.100.74"); }
}
route[5] {
# ---------------------------------------------------------------- # Save here CDR Variables # ---------------------------------------------------------------- #save sourceIP $sht(a=>$ci::srcip) = $si; $sht(a=>$ci::fromdplname) = $fn; $sht(a=>$ci::touri) = $tu; $sht(a=>$ci::fromuri) = $fu; $sht(a=>$ci::useragent) = $ua;
}
route[6] {
# ---------------------------------------------------------------- # Write CDR via Perl and free previously CDR Variables # ---------------------------------------------------------------- #save variables from htable in AVPs, so we can access them from perl
(without memory leak) $avp(s:4com_srcip)=$sht(a=>$ci::srcip); $avp(s:4com_fromdplname)=$sht(a=>$ci::fromdplname); $avp(s:4com_touri)=$sht(a=>$ci::touri); $avp(s:4com_fromuri)=$sht(a=>$ci::fromuri); $avp(s:4com_useragent)=$sht(a=>$ci::useragent); $avp(s:4com_invtrytime)=$sht(a=>$ci::invtrytime);
#write CDR perl_exec("write_cdr"); #free all variables saved in hashtable sht_rm_name_re("a=>$ci::.*");
}
onreply_route[1] {
rtpproxy_manage("fwc"); fix_nated_contact(); #if (is_gflag("0")) log(1,"-- 0 ist gesetzt.\n"); #if (is_gflag("1")) log(1,"-- 1 ist gesetzt.\n"); #if (is_gflag("2")) log(1,"-- 2 ist gesetzt.\n"); #if (is_gflag("3")) log(1,"-- 3 ist gesetzt.\n"); #if (is_gflag("1")) #{ # log(1,"Recording this Call\n"); # start_recording(); #} #else #{ # log(1,"NOT recording this Call\n"); #} xlog("L_DBG", "-- Status: $rs METHOD $rm Reason $rr\n"); if ($rm=="INVITE") { xlog("L_DBG", "Method is INVITE\n"); if ($rs=~"1[0-9][0-9]") { xlog("L_DBG", "Status is in 100-class Trying\n"); $sht(a=>$ci::invtrytime) = $Ts; #perl_exec("got_invite_trying"); } else if ($rs=~"4[0-9][0-9]") { xlog("L_DBG", "Status is in 400-class -
ClientErrors\n"); #xlog("L_DBG", "SI aus shared: $sht(a=>$ci::srcip)\n"); #perl_exec("write_cdr"); #sht_rm_name_re("a=>$ci::.*"); route(6); } } }
#### # Per SIP request initial checks route[REQINIT] { #!ifdef WITH_ANTIFLOOD # flood dection from same IP and traffic ban for a while # be sure you exclude checking trusted peers, such as pstn gateways # - local host excluded (e.g., loop to self) if(src_ip!=myself) { if($sht(ipban=>$si)!=$null) { # ip is already blocked xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n"); exit; } if (!pike_check_req()) { xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n"); $sht(ipban=>$si) = 1; exit; } } #!endif
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; }
}
-- Mit freundlichen Grüßen *Karsten Horsmann*
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Hi Reda,
i fix it. forward() is stateless and so one then i breaks many things in my multihomed setup. I use transaction for it and then it works.
To prevent internal Invites to get dispatched, i used the dst_ip. I just want external incoming calls to be dispatched.
route[INVITE] {
# ----------------------------------------------------------------- # INVITE Message Handler # ----------------------------------------------------------------- setflag(6);
lookup("aliases"); if (uri!=myself) { route(NAT); route(RELAY); return; };
#!ifdef WITH_DISPATCHER if (lookup("location") && (dst_ip==222.222.222.222)) { if(ds_select_domain("1", "4")) { xlog("DISPATCHER ds_select_domain\n"); route(NAT); xlog("DISPATCHER was in route-NAT now route-RELAY\n"); route(RELAY); xlog("DISPATCHER was in route-RELAY\n"); return; } } #!endif
if (!lookup("location")) { xlog("404 User not found\n"); sl_send_reply("404", "User Not Found"); return; };
route(NAT); route(RELAY); }
route[RELAY] {
# ----------------------------------------------------------------- # Default Message Handler # -----------------------------------------------------------------
t_on_reply("1");
if (!t_relay()) { if (method=="INVITE" && isflagset(6)) { unforce_rtp_proxy(); }; sl_reply_error(); }; }