summaryrefslogtreecommitdiff
path: root/apps/app_followme.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:58:07 -0500
commitaae45acbda1f6100cd9de816855166a32b991ce0 (patch)
tree2918ec6fd544abaf89f52d21db4790fc03750139 /apps/app_followme.c
parent60d1911482c1dcf44d34e30f252857d75f5d5d77 (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 'apps/app_followme.c')
-rw-r--r--apps/app_followme.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/apps/app_followme.c b/apps/app_followme.c
index 4a2e569df..5fd5d15ba 100644
--- a/apps/app_followme.c
+++ b/apps/app_followme.c
@@ -64,6 +64,7 @@ ASTERISK_REGISTER_FILE()
#include "asterisk/dsp.h"
#include "asterisk/app.h"
#include "asterisk/stasis_channels.h"
+#include "asterisk/max_forwards.h"
/*** DOCUMENTATION
<application name="FollowMe" language="en_US">
@@ -1069,6 +1070,7 @@ static struct ast_channel *findmeexec(struct fm_args *tpargs, struct ast_channel
ast_connected_line_copy_from_caller(ast_channel_connected(outbound), ast_channel_caller(caller));
ast_channel_inherit_variables(caller, outbound);
ast_channel_datastore_inherit(caller, outbound);
+ ast_max_forwards_decrement(outbound);
ast_channel_language_set(outbound, ast_channel_language(caller));
ast_channel_req_accountcodes(outbound, caller, AST_CHANNEL_REQUESTOR_BRIDGE_PEER);
ast_channel_musicclass_set(outbound, ast_channel_musicclass(caller));
@@ -1304,12 +1306,23 @@ static int app_exec(struct ast_channel *chan, const char *data)
AST_APP_ARG(options);
);
char *opt_args[FOLLOWMEFLAG_ARG_ARRAY_SIZE];
+ int max_forwards;
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "%s requires an argument (followmeid)\n", app);
return -1;
}
+ ast_channel_lock(chan);
+ max_forwards = ast_max_forwards_get(chan);
+ ast_channel_unlock(chan);
+
+ if (max_forwards <= 0) {
+ ast_log(LOG_WARNING, "Unable to execute FollowMe on channel %s. Max forwards exceeded\n",
+ ast_channel_name(chan));
+ return -1;
+ }
+
argstr = ast_strdupa((char *) data);
AST_STANDARD_APP_ARGS(args, argstr);