From 91bbbcb7fb11235d27676d645834d75b4e90749e Mon Sep 17 00:00:00 2001 From: karl anderson Date: Tue, 1 Oct 2013 20:53:54 -0400 Subject: [PATCH] support associations in the backup list and fix issue with redirect when challenged --- kamailio/default.cfg | 54 +++++++++++++++++++++--------------- kamailio/dispatcher-role.cfg | 48 ++++++++++++++++++++------------ kamailio/roles.cfg | 2 +- 3 files changed, 63 insertions(+), 41 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 3b4f6e2..0d315e0 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -16,6 +16,7 @@ #!define AVP_ROUTE_CNT "route_cnt" #!define AVP_ASSOCIATED_SERVER "associated_server" #!define AVP_ASSOCIATE_CONTACT "associate_contact" +#!define AVP_REDIRECT_KEY "redirect_key" ####### Flags ####### flags @@ -153,6 +154,7 @@ loadmodule "textopsx.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") ######## Pseudo-Variables module ######## loadmodule "pv.so" @@ -310,7 +312,6 @@ route[HANDLE_MOVE_REQUEST] { if (is_method("INVITE") && $rU == "*6683*") { $var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host}); - $var(from_uri) = @from.uri.user + "@" + @from.uri.host; if ($sht(associations=>$var(contact_uri)) != $null) { $sht(associations=>$var(contact_uri)) = $null; @@ -318,12 +319,6 @@ route[HANDLE_MOVE_REQUEST] with media server $sht(associations=>$var(contact_uri))"); } - if ($sht(associations=>$var(from_uri)) != $null) { - $sht(associations=>$var(from_uri)) = $null; - xlog("L_INFO", "$ci|log|removed from association for $var(from_uri) - with media server $sht(associations=>$var(from_uri))"); - } - send_reply("503", "Removed association"); exit; @@ -475,8 +470,17 @@ onreply_route[INTERNAL_REPLY] xlog("L_INFO", "$ci|start|recieved internal reply $T_reply_code $rr"); xlog("L_INFO", "$ci|log|source $si:$sp"); - if (t_check_status("(180)|(183)")) { - xlog("L_INFO", "$ci|log|session progress, only listening for redirects"); + if (is_method("INVITE") && + !isflagset(FLAG_SESSION_PROGRESS) && + t_check_status("(180)|(183)|(200)") + ) { + 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)"); + $sht(redirects=>$avp(AVP_REDIRECT_KEY)) = $null; + } + xlog("L_INFO", "$ci|log|call setup, now ignoring abnormal termination"); setflag(FLAG_SESSION_PROGRESS); } @@ -501,28 +505,32 @@ failure_route[INTERNAL_FAULT] exit; } - # if the failure case was something that we should recover - # from then try to find a new media server + # Handle redirects if (t_check_status("302")) { - ## TODO - test this - ## get_redirects("*"); - + $var(redirect) = @from.uri.user + "@" + @from.uri.host + "->" + + $T_rpl($(ct{tobody.user})) + "@" + $T_rpl($(ct{tobody.host})); if($T_rpl($hdr(X-Redirect-Server)) != $null) { - $var(from_uri) = @from.uri.user + "@" + @from.uri.host; - - $sht(associations=>$var(from_uri)) = $T_rpl($hdr(X-Redirect-Server)); + $sht(redirects=>$var(redirect)) = $T_rpl($hdr(X-Redirect-Server)); + xlog("L_INFO", "$ci|log|stored redirect mapping $var(redirect) to $T_rpl($hdr(X-Redirect-Server))"); + } + } else if (!t_check_status("407") && + $avp(AVP_REDIRECT_KEY) != $null && + $sht(redirects=>$avp(AVP_REDIRECT_KEY)) != $null + ) { + xlog("L_INFO", "$ci|log|removing redirect mapping $avp(AVP_REDIRECT_KEY)"); + $sht(redirects=>$avp(AVP_REDIRECT_KEY)) = $null; + } - xlog("L_INFO", "$ci|log|stored redirect mapping for $var(contact_uri) to $T_rpl($hdr(X-Redirect-Server))"); + remove_hf_re("X-.*"); - remove_hf("X-Redirect-Server"); - } - } - # change 6xx to 4xx if (t_check_status("6[0-9][0-9]")) { $var(new_code) = "4" + $(T_reply_code{s.substr,1,0}); xlog("L_INFO", "$ci|log|sending 6XX reply as $var(new_code) $var(reply_reason)"); - t_reply("$(var(new_code){s.int})", "$var(reply_reason)"); + t_reply("$(var(new_code){s.int})", "$var(reply_reason)"); + + # if the failure case was something that we should recover + # from then try to find a new media server } else if ("$var(reply_reason)" =~ "call barred") { xlog("L_INFO", "$ci|log|failure route ignoring call barred"); } else if (isflagset(FLAG_SESSION_PROGRESS)) { diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index 83cd94b..0be6304 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -50,7 +50,7 @@ route[DISPATCHER_FIND_ROUTES] $du = $sht(failover=>$ci::current); return; } - + $var(ds_group) = 1; #!ifndef PRESENCE-ROLE @@ -81,18 +81,20 @@ route[DISPATCHER_FIND_ROUTES] } $var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host}); - $var(from_uri) = @from.uri.user + "@" + @from.uri.host; - if ($sht(associations=>$var(from_uri)) != $null) { - $var(association) = $var(from_uri); - $var(prefered_route) = $sht(associations=>$var(association)); - xlog("L_INFO", "$ci|log|from uri $var(from_uri) associated with media server $var(prefered_route)"); - route(DISPATCHER_REORDER_ROUTES); - $sht(associations=>$var(from_uri)) = $null; + $var(redirect) = @from.uri.user + "@" + @from.uri.host + "->" + + @ruri.user + "@" + @ruri.host; + if ($sht(redirects=>$var(redirect)) != $null) { + $var(prefered_route) = $sht(redirects=>$var(redirect)); + xlog("L_INFO", "$ci|log|found redirect for $var(redirect)"); + if (route(DISPATCHER_REORDER_ROUTES)) { + $avp(AVP_REDIRECT_KEY) = $var(redirect); + } } else if ($sht(associations=>$var(contact_uri)) != $null) { - $var(association) = $var(contact_uri); - $var(prefered_route) = $sht(associations=>$var(association)); - xlog("L_INFO", "$ci|log|contact uri $var(contact_uri) associated with media server $var(prefered_route)"); - route(DISPATCHER_REORDER_ROUTES); + $var(prefered_route) = $sht(associations=>$var(contact_uri)); + xlog("L_INFO", "$ci|log|found association for contact uri $var(contact_uri)"); + if (!route(DISPATCHER_REORDER_ROUTES)) { + $sht(associations=>$var(association)) = $null; + } } } @@ -109,9 +111,20 @@ route[DISPATCHER_REORDER_ROUTES] $var(i) = $var(i) + 1; } - + + if ($var(ds_group) == 1 && !$var(found) && ds_select_dst("2", "0")) { + $var(i) = 0; + while($(avp(ds_dst)[$var(i)]) != $null) { + if($(avp(ds_dst)[$var(i)]) == $var(prefered_route)) { + xlog("L_INFO", "$ci|log|found associated media server in backup list"); + $var(found) = 1; + break; + } + } + } + if ($var(found)) { - xlog("L_INFO", "$ci|log|re-ordering the dispatcher list to keep associated server first"); + xlog("L_INFO", "$ci|log|re-ordering the dispatcher list to maintain association with $var(prefered_route)"); $(avp(ds_dst)[*]) = $null; @@ -126,10 +139,11 @@ route[DISPATCHER_REORDER_ROUTES] $(avp(tmp_ds_dst)[*]) = $null; } else { - xlog("L_INFO", "$ci|log|associated media server is inactive, moving to $rd"); - - $sht(associations=>$var(association)) = $null; + xlog("L_INFO", "$ci|log|associated media server $var(prefered_route) is inactive, moving to $rd"); + return -1; } + + return 1; } route[DISPATCHER_NEXT_ROUTE] diff --git a/kamailio/roles.cfg b/kamailio/roles.cfg index ebe4fb3..a073084 100644 --- a/kamailio/roles.cfg +++ b/kamailio/roles.cfg @@ -3,6 +3,6 @@ #!trydef NAT-TRAVERSAL-ROLE #!trydef REGISTRAR-ROLE #!trydef PRESENCE-ROLE -#!trydef TRAFFIC-FILTER-ROLE +# # #!trydef TRAFFIC-FILTER-ROLE ## vim:set tabstop=4 softtabstop=4 shiftwidth=4 expandtab