diff --git a/kamailio/default.cfg b/kamailio/default.cfg index cb9db8e..9c7e537 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -168,6 +168,7 @@ loadmodule "sdpops.so" ######## Generic Hash Table container in shared memory ######## loadmodule "htable.so" modparam("htable", "htable", "associations=>size=16;autoexpire=7200") +modparam("htable", "htable", "redirects=>size=16;autoexpire=5") modparam("htable", "db_url", "KAZOO_DB_URL") ####### RTIMER module ########## @@ -762,6 +763,13 @@ onreply_route[INTERNAL_REPLY] ) { xlog("L_INFO", "$ci|log|call setup, now ignoring abnormal termination\n"); setflag(FLAG_SESSION_PROGRESS); + + # clear the redirect + if ($avp(AVP_REDIRECT_KEY) != $null && $sht(redirects=>$avp(AVP_REDIRECT_KEY)) != $null) { + xlog("L_INFO", "$ci|log|removing redirect mapping $avp(AVP_REDIRECT_KEY)\n"); + $sht(redirects=>$avp(AVP_REDIRECT_KEY)) = $null; + } + } if ($rs < 300) { @@ -795,8 +803,14 @@ failure_route[INTERNAL_FAULT] remove_hf_re("^X-.*"); + # handle challenges replies from media server, we want to route to same media server + if (t_check_status("407")) { + xlog("L_INFO", "$ci|log|media $xavp(ds_dst=>uri) challenged the invite, creating redirect\n"); + $var(redirect) = @from.uri.user + "@" + @from.uri.host + "->" + @ruri.user + "@" + @ruri.host; + $sht(redirects=>$var(redirect)) = $xavp(ds_dst=>uri); + # change 6xx to 4xx - if (t_check_status("6[0-9][0-9]") && !t_check_status("600|603|604|606")) { + } else if (t_check_status("6[0-9][0-9]") && !t_check_status("600|603|604|606")) { $var(new_code) = "4" + $(T_reply_code{s.substr,1,0}); xlog("L_INFO", "$ci|failure|sending $T_reply_code reply as $var(new_code) $T_reply_reason\n"); t_reply("$(var(new_code){s.int})", "$T_reply_reason"); @@ -809,7 +823,7 @@ failure_route[INTERNAL_FAULT] xlog("L_INFO", "$ci|failure|ignoring failure after session progress\n"); } else if (t_check_status("403") && $T_reply_reason=="Forbidden") { xlog("L_WARNING", "$ci|failure|Failed auth from IP $si\n"); - } else if (t_check_status("(401)|(407)|(486)")) { + } else if (t_check_status("(401)|(486)")) { xlog("L_INFO", "$ci|failure|auth reply $T_reply_code $T_reply_reason\n"); } else if (t_check_status("402")) { xlog("L_INFO", "$ci|failure|overriding reply code 402 with 486\n"); diff --git a/kamailio/dispatcher-role-5.2.cfg b/kamailio/dispatcher-role-5.2.cfg index 997779d..7c63099 100644 --- a/kamailio/dispatcher-role-5.2.cfg +++ b/kamailio/dispatcher-role-5.2.cfg @@ -146,13 +146,9 @@ route[DISPATCHER_FIND_ROUTES] + @ruri.user + "@" + @ruri.host; if ($sht(redirects=>$var(redirect)) != $null) { $var(prefered_route) = $sht(redirects=>$var(redirect)); - xlog("L_INFO", "$ci|route|found redirect for $var(redirect)\n"); - if (route(DISPATCHER_PREFERRED_ROUTE)) { - $avp(AVP_REDIRECT_KEY) = $var(redirect); - xlog("L_INFO", "$ci|route|REORDER OK $var(redirect)\n"); - } else { - xlog("L_INFO", "$ci|route|REORDER KO $var(redirect)\n"); - } + xlog("L_INFO", "$ci|route|found redirect for $var(redirect) to $var(prefered_route)\n"); + $avp(AVP_REDIRECT_KEY) = $var(redirect); + route(DISPATCHER_PREFERRED_ROUTE); } else if ($sht(associations=>$var(user_source)) != $null) { if($sel(cfg_get.kazoo.dispatcher_route_to_associated_media) == 1) { $var(prefered_route) = $sht(associations=>$var(user_source)); @@ -180,7 +176,6 @@ route[DISPATCHER_PREFERRED_ROUTE] $var(i) = 0; while($var(i) < $xavp(ds_ctx=>cnt)) { if($xavp(ds_dst[$var(i)]=>uri) == $var(prefered_route)) { - xlog("L_INFO", "$ci|route|removing preferred route $xavp(ds_dst[$var(i)]=>uri) from list\n"); $xavp(ds_dst[$var(i)]=>*) = $null; } $var(i) = $var(i) + 1;