[Asterisk-code-review] bridge: Deny full Local channel pair in bridge. (asterisk[master])

Joshua Colp asteriskteam at digium.com
Tue Nov 16 04:14:09 CST 2021


Joshua Colp has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17474 )


Change subject: bridge: Deny full Local channel pair in bridge.
......................................................................

bridge: Deny full Local channel pair in bridge.

Local channels are made up of two pairs - the 1 and 2
sides. When a frame goes in one side, it comes out the
other. Back and forth. When both halvess are in a
bridge this creates an infinite loop of frames.

This change makes it so that bridging no longer
allows both of these sides to exist in the same
bridge.

ASTERISK-29748

Change-Id: I29928b6de87cd9be996a77daccefd7c360fef651
---
M main/bridge_channel.c
1 file changed, 25 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/74/17474/1

diff --git a/main/bridge_channel.c b/main/bridge_channel.c
index 608db61..fa757e4 100644
--- a/main/bridge_channel.c
+++ b/main/bridge_channel.c
@@ -57,6 +57,7 @@
 #include "asterisk/sem.h"
 #include "asterisk/stream.h"
 #include "asterisk/message.h"
+#include "asterisk/core_local.h"
 
 /*!
  * \brief Used to queue an action frame onto a bridge channel and write an action frame into a bridge.
@@ -2904,6 +2905,7 @@
 	int res = 0;
 	uint8_t indicate_src_change = 0;
 	struct ast_bridge_features *channel_features;
+	struct ast_channel *peer;
 	struct ast_channel *swap;
 
 	ast_debug(1, "Bridge %s: %p(%s) is joining\n",
@@ -2918,6 +2920,29 @@
 
 	ast_channel_lock(bridge_channel->chan);
 
+	peer = ast_local_get_peer(bridge_channel->chan);
+	if (peer) {
+		struct ast_bridge *peer_bridge;
+
+		ast_channel_lock(peer);
+		peer_bridge = ast_channel_internal_bridge(peer);
+		ast_channel_unlock(peer);
+		ast_channel_unref(peer);
+
+		/* As we are only doing a pointer comparison we don't need the peer_bridge
+		 * to be reference counted or locked.
+		 */
+		if (peer_bridge == bridge_channel->bridge) {
+			ast_channel_unlock(bridge_channel->chan);
+			ast_bridge_unlock(bridge_channel->bridge);
+			ast_debug(1, "Bridge %s: %p(%s) denying Bridge join to prevent Local channel loop\n",
+				bridge_channel->bridge->uniqueid,
+				bridge_channel,
+				ast_channel_name(bridge_channel->chan));
+			return -1;
+		}
+	}
+
 	bridge_channel->read_format = ao2_bump(ast_channel_readformat(bridge_channel->chan));
 	bridge_channel->write_format = ao2_bump(ast_channel_writeformat(bridge_channel->chan));
 

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17474
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I29928b6de87cd9be996a77daccefd7c360fef651
Gerrit-Change-Number: 17474
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211116/4a8a2bab/attachment.html>


More information about the asterisk-code-review mailing list