From d6f9581d9b8518be2b8bf0e447095882146c3fb2 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 | 46 ++++++++++++++++----------------- kamailio/dispatcher-role.cfg | 49 +++++++++++++++++++++++------------- 2 files changed, 53 insertions(+), 42 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index cd37565..0d315e0 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -154,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" @@ -311,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; @@ -319,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; @@ -476,14 +470,18 @@ 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)|(200)")) { - xlog("L_INFO", "$ci|log|call setup, only listening for redirects"); - setflag(FLAG_SESSION_PROGRESS); - - if ($avp(AVP_REDIRECT_KEY) != $null) { - xlog("L_INFO", "$ci|log|removing redirect mapping for $avp(AVP_REDIRECT_KEY)"); - $sht(associations=>$avp(AVP_REDIRECT_KEY)) = $null; + 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); } if ($rs < 300) { @@ -508,19 +506,19 @@ failure_route[INTERNAL_FAULT] } # Handle redirects - $var(redirect) = @from.uri.user + "@" + @from.uri.host + "->" - + @contact.uri.user + "@" + @contact.uri.host; if (t_check_status("302")) { + $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) { - $sht(associations=>$var(redirect)) = $T_rpl($hdr(X-Redirect-Server)); - xlog("L_INFO", "$ci|log|stored redirect mapping for $var(redirect) to $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))"); } - - add_rcv_param("1"); - - } else if (!t_check_status("407")) { - xlog("L_INFO", "$ci|log|removing redirect mapping for $var(redirect)"); - $sht(associations=>$var(redirect)) = $null; + } 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; } remove_hf_re("X-.*"); diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index 3457578..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,19 +81,20 @@ route[DISPATCHER_FIND_ROUTES] } $var(contact_uri) = $(ct{tobody.user}) + "@" + $(ct{tobody.host}); - $var(redirect) = @from.uri.user + "@" + @from.uri.host + "->" - + @ruri.user + "@" + @ruri.host; - if ($sht(associations=>$var(redirect)) != $null) { - $var(association) = $var(redirect); - $var(prefered_route) = $sht(associations=>$var(association)); - xlog("L_INFO", "$ci|log|found redirect mapping for $var(redirect) and associated with media server $var(prefered_route)"); - route(DISPATCHER_REORDER_ROUTES); - $avp(AVP_REDIRECT_KEY) = $var(redirect); + $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; + } } } @@ -110,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; @@ -127,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]