From 20a14e568f64de25326d794768790351cb703330 Mon Sep 17 00:00:00 2001 From: Matthew Jordan Date: Sun, 8 Jun 2014 18:12:53 +0000 Subject: bridges/bridge_native_rtp: Reconfigure bridge on removal of framehook This patch is a re-do of r414122. When r414122 was merged, a major problem with it was uncovered. UNBRIDGE soft hangup flags have a catastrophic effect on the pbx core if they leak out from the bridge layer: the channel gets hung up. With the number of threads involved in a blind transfer, and with the initial patch, it was likely that this would occur. This caused a large number of test failures This patch is nearly identical with the one proposed in r414122, save for the following changes: - We explicitly clear the UNBRIDGE flag when setting an after goto on a channel in a bridge - Defensively, if we encounter an UNBRIDGE flag in the pbx core, we handle it https://reviewboard.asterisk.org/r/3585/ ........ Merged revisions 415443 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@415444 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/bridge_after.c | 5 +++++ main/bridge_channel.c | 4 ++-- main/channel.c | 14 +++++++++++++- main/framehook.c | 4 ++++ main/pbx.c | 6 ++++++ 5 files changed, 30 insertions(+), 3 deletions(-) (limited to 'main') diff --git a/main/bridge_after.c b/main/bridge_after.c index 3d1d2f362..fbe4e605a 100644 --- a/main/bridge_after.c +++ b/main/bridge_after.c @@ -451,6 +451,11 @@ int ast_bridge_setup_after_goto(struct ast_channel *chan) struct after_bridge_goto_ds *after_bridge; int goto_failed = -1; + /* We are going to be leaving the bridging system now; + * clear any pending UNBRIDGE flags + */ + ast_channel_clear_softhangup(chan, AST_SOFTHANGUP_UNBRIDGE); + /* Determine if we are going to setup a dialplan location and where. */ if (ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_ASYNCGOTO) { /* An async goto has already setup a location. */ diff --git a/main/bridge_channel.c b/main/bridge_channel.c index 2b37f25b5..9a1e40bba 100644 --- a/main/bridge_channel.c +++ b/main/bridge_channel.c @@ -1757,8 +1757,8 @@ void bridge_channel_internal_pull(struct ast_bridge_channel *bridge_channel) * outgoing channel, clear the outgoing flag. */ if (ast_test_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_OUTGOING) - && (ast_channel_softhangup_internal_flag(bridge_channel->chan) & (AST_SOFTHANGUP_ASYNCGOTO | AST_SOFTHANGUP_UNBRIDGE) - || bridge_channel->state == BRIDGE_CHANNEL_STATE_WAIT)) { + && (ast_channel_is_leaving_bridge(bridge_channel->chan) + || bridge_channel->state == BRIDGE_CHANNEL_STATE_WAIT)) { ast_debug(2, "Channel %s will survive this bridge; clearing outgoing (dialed) flag\n", ast_channel_name(bridge_channel->chan)); ast_clear_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_OUTGOING); } diff --git a/main/channel.c b/main/channel.c index 2d84c771d..27e07b800 100644 --- a/main/channel.c +++ b/main/channel.c @@ -2596,7 +2596,7 @@ void ast_channel_clear_softhangup(struct ast_channel *chan, int flag) /*! \brief Softly hangup a channel, don't lock */ int ast_softhangup_nolock(struct ast_channel *chan, int cause) { - ast_debug(1, "Soft-Hanging up channel '%s'\n", ast_channel_name(chan)); + ast_debug(1, "Soft-Hanging (%#04x) up channel '%s'\n", cause, ast_channel_name(chan)); /* Inform channel driver that we need to be hung up, if it cares */ ast_channel_softhangup_internal_flag_add(chan, cause); ast_queue_frame(chan, &ast_null_frame); @@ -10146,6 +10146,18 @@ int ast_channel_is_bridged(const struct ast_channel *chan) return ast_channel_internal_bridge(chan) != NULL; } +int ast_channel_is_leaving_bridge(struct ast_channel *chan) +{ + int hangup_flags = ast_channel_softhangup_internal_flag(chan); + int hangup_test = hangup_flags & (AST_SOFTHANGUP_ASYNCGOTO | AST_SOFTHANGUP_UNBRIDGE); + + /* This function should only return true if either ASYNCGOTO + * or UNBRIDGE is set, or both flags are set. It should return + * false if any other flag is set. + */ + return (hangup_test && (hangup_test == hangup_flags)); +} + struct ast_channel *ast_channel_bridge_peer(struct ast_channel *chan) { struct ast_channel *peer; diff --git a/main/framehook.c b/main/framehook.c index de8c612aa..84719ef49 100644 --- a/main/framehook.c +++ b/main/framehook.c @@ -189,6 +189,10 @@ int ast_framehook_detach(struct ast_channel *chan, int id) } AST_LIST_TRAVERSE_SAFE_END; + if (ast_channel_is_bridged(chan)) { + ast_softhangup_nolock(chan, AST_SOFTHANGUP_UNBRIDGE); + } + return res; } diff --git a/main/pbx.c b/main/pbx.c index 2d9e15b08..ba985199f 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -6323,6 +6323,12 @@ static enum ast_pbx_result __ast_pbx_run(struct ast_channel *c, while (!(res = ast_spawn_extension(c, ast_channel_context(c), ast_channel_exten(c), ast_channel_priority(c), S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, NULL), &found, 1))) { + + /* Defensively clear the UNBRIDGE flag in case it leaked + * out of the bridging framework. UNBRIDE never implies + * that a channel is hung up. + */ + ast_channel_clear_softhangup(c, AST_SOFTHANGUP_UNBRIDGE); if (!ast_check_hangup(c)) { ast_channel_priority_set(c, ast_channel_priority(c) + 1); continue; -- cgit v1.2.3