summaryrefslogtreecommitdiff
path: root/res/res_pjsip_diversion.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2015-04-15 10:38:02 -0500
committerMatt Jordan <mjordan@digium.com>2015-04-17 15:57:10 -0500
commit4f1a8dbe9241cf967000d9f5f359830948da3c9a (patch)
treea2056f9e99a4bc0272ec4137ea26a1efdc0726b1 /res/res_pjsip_diversion.c
parentb56c1914fa54817e88be92ed8394aa6f64aa26ad (diff)
Detect potential forwarding loops based on count.
A potential problem that can arise is the following: * Bob's phone is programmed to automatically forward to Carol. * Carol's phone is programmed to automatically forward to Bob. * Alice calls Bob. If left unchecked, this results in an endless loops of call forwards that would eventually result in some sort of fiery crash. Asterisk's method of solving this issue was to track which interfaces had been dialed. If a destination were dialed a second time, then the attempt to call that destination would fail since a loop was detected. The problem with this method is that call forwarding has evolved. Some SIP phones allow for a user to manually forward an incoming call to an ad-hoc destination. This can mean that: * There are legitimate use cases where a device may be dialed multiple times, or * There can be human error when forwarding calls. This change removes the old method of detecting forwarding loops in favor of keeping a count of the number of destinations a channel has dialed on a particular branch of a call. If the number exceeds the set number of max forwards, then the call fails. This approach has the following advantages over the old: * It is much simpler. * It can detect loops involving local channels. * It is user configurable. The only disadvantage it has is that in the case where there is a legitimate forwarding loop present, it takes longer to detect it. However, the forwarding loop is still properly detected and the call is cleaned up as it should be. Address review feedback on gerrit. * Correct "mfgium" to "Digium" * Decrement max forwards by one in the case where allocation of the max forwards datastore is required. * Remove irrelevant code change from pjsip_global_headers.c ASTERISK-24958 #close Change-Id: Ia7e4b7cd3bccfbd34d9a859838356931bba56c23
Diffstat (limited to 'res/res_pjsip_diversion.c')
-rw-r--r--res/res_pjsip_diversion.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/res/res_pjsip_diversion.c b/res/res_pjsip_diversion.c
index a4ac157e4..49f789212 100644
--- a/res/res_pjsip_diversion.c
+++ b/res/res_pjsip_diversion.c
@@ -248,6 +248,7 @@ static void add_diversion_header(pjsip_tx_data *tdata, struct ast_party_redirect
pjsip_name_addr *name_addr;
pjsip_sip_uri *uri;
pjsip_param *param;
+ pjsip_fromto_hdr *old_hdr;
struct ast_party_id *id = &data->from;
pjsip_uri *base = PJSIP_MSG_FROM_HDR(tdata->msg)->uri;
@@ -273,6 +274,10 @@ static void add_diversion_header(pjsip_tx_data *tdata, struct ast_party_redirect
pj_list_insert_before(&hdr->other_param, param);
hdr->uri = (pjsip_uri *) name_addr;
+ old_hdr = pjsip_msg_find_hdr_by_name(tdata->msg, &diversion_name, NULL);
+ if (old_hdr) {
+ pj_list_erase(old_hdr);
+ }
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);
}