[svn-commits] mjordan: branch 12 r415443 - in /branches/12: bridges/ include/asterisk/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Jun 8 13:12:00 CDT 2014


Author: mjordan
Date: Sun Jun  8 13:11:54 2014
New Revision: 415443

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=415443
Log:
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/


Modified:
    branches/12/bridges/bridge_native_rtp.c
    branches/12/include/asterisk/channel.h
    branches/12/main/bridge_after.c
    branches/12/main/bridge_channel.c
    branches/12/main/channel.c
    branches/12/main/framehook.c
    branches/12/main/pbx.c

Modified: branches/12/bridges/bridge_native_rtp.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/bridges/bridge_native_rtp.c?view=diff&rev=415443&r1=415442&r2=415443
==============================================================================
--- branches/12/bridges/bridge_native_rtp.c (original)
+++ branches/12/bridges/bridge_native_rtp.c Sun Jun  8 13:11:54 2014
@@ -234,8 +234,10 @@
 		break;
 	case AST_RTP_GLUE_RESULT_REMOTE:
 		if (!target) {
-			glue0->update_peer(c0->chan, NULL, NULL, NULL, NULL, 0);
-			if (glue1) {
+			if (ast_channel_is_leaving_bridge(c0->chan)) {
+				glue0->update_peer(c0->chan, NULL, NULL, NULL, NULL, 0);
+			}
+			if (glue1 && ast_channel_is_leaving_bridge(c1->chan)) {
 				glue1->update_peer(c1->chan, NULL, NULL, NULL, NULL, 0);
 			}
 		} else {
@@ -488,8 +490,10 @@
 		ast_rtp_instance_set_bridged(tinstance, NULL);
 	}
 
-	/* Direct RTP may have occurred, tear it down */
-	glue->update_peer(bridge_channel->chan, NULL, NULL, NULL, NULL, 0);
+	if (ast_channel_is_leaving_bridge(bridge_channel->chan)) {
+		/* Direct RTP may have occurred, tear it down */
+		glue->update_peer(bridge_channel->chan, NULL, NULL, NULL, NULL, 0);
+	}
 
 	native_rtp_bridge_stop(bridge, NULL);
 }

Modified: branches/12/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/channel.h?view=diff&rev=415443&r1=415442&r2=415443
==============================================================================
--- branches/12/include/asterisk/channel.h (original)
+++ branches/12/include/asterisk/channel.h Sun Jun  8 13:11:54 2014
@@ -4284,6 +4284,22 @@
 int ast_channel_is_bridged(const struct ast_channel *chan);
 
 /*!
+ * \brief Determine if a channel is leaving a bridge, but \em not hung up
+ * \since 12.4.0
+ *
+ * \param chan The channel to test
+ *
+ * \note If a channel is hung up, it is implicitly leaving any bridge it
+ * may be in. This function is used to test if a channel is leaving a bridge
+ * but may survive the experience, if it has a place to go to (dialplan or
+ * otherwise)
+ *
+ * \retval 0 The channel is not leaving the bridge or is hung up
+ * \retval non-zero The channel is leaving the bridge
+ */
+int ast_channel_is_leaving_bridge(struct ast_channel *chan);
+
+/*!
  * \brief Get the channel's bridge peer only if the bridge is two-party.
  * \since 12.0.0
  *

Modified: branches/12/main/bridge_after.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/bridge_after.c?view=diff&rev=415443&r1=415442&r2=415443
==============================================================================
--- branches/12/main/bridge_after.c (original)
+++ branches/12/main/bridge_after.c Sun Jun  8 13:11:54 2014
@@ -451,6 +451,11 @@
 	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. */

Modified: branches/12/main/bridge_channel.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/bridge_channel.c?view=diff&rev=415443&r1=415442&r2=415443
==============================================================================
--- branches/12/main/bridge_channel.c (original)
+++ branches/12/main/bridge_channel.c Sun Jun  8 13:11:54 2014
@@ -1757,8 +1757,8 @@
 	 * 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);
 	}

Modified: branches/12/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/channel.c?view=diff&rev=415443&r1=415442&r2=415443
==============================================================================
--- branches/12/main/channel.c (original)
+++ branches/12/main/channel.c Sun Jun  8 13:11:54 2014
@@ -2596,7 +2596,7 @@
 /*! \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);
@@ -10151,6 +10151,18 @@
 	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;

Modified: branches/12/main/framehook.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/framehook.c?view=diff&rev=415443&r1=415442&r2=415443
==============================================================================
--- branches/12/main/framehook.c (original)
+++ branches/12/main/framehook.c Sun Jun  8 13:11:54 2014
@@ -189,6 +189,10 @@
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
 
+	if (ast_channel_is_bridged(chan)) {
+		ast_softhangup_nolock(chan, AST_SOFTHANGUP_UNBRIDGE);
+	}
+
 	return res;
 }
 

Modified: branches/12/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/pbx.c?view=diff&rev=415443&r1=415442&r2=415443
==============================================================================
--- branches/12/main/pbx.c (original)
+++ branches/12/main/pbx.c Sun Jun  8 13:11:54 2014
@@ -6310,6 +6310,12 @@
 		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;




More information about the svn-commits mailing list