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

George Joseph asteriskteam at digium.com
Fri Nov 19 08:42:47 CST 2021


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/17542 )

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 halves 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(-)

Approvals:
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/main/bridge_channel.c b/main/bridge_channel.c
index 71739b7..aefb764 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.
@@ -2862,6 +2863,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",
@@ -2876,6 +2878,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/+/17542
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: I29928b6de87cd9be996a77daccefd7c360fef651
Gerrit-Change-Number: 17542
Gerrit-PatchSet: 2
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211119/70f7f6d8/attachment.html>


More information about the asterisk-code-review mailing list