]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
bridge: Deny full Local channel pair in bridge.
authorJoshua C. Colp <jcolp@sangoma.com>
Tue, 16 Nov 2021 10:06:26 +0000 (06:06 -0400)
committerGeorge Joseph <gjoseph@digium.com>
Fri, 19 Nov 2021 14:42:46 +0000 (08:42 -0600)
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

main/bridge_channel.c

index 71739b7b0fee25cd0c4ec5f2ce524ec2ce2e85c2..aefb76405ab9c010e781a478bef2315ec89f8cf3 100644 (file)
@@ -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 bridge_channel_internal_join(struct ast_bridge_channel *bridge_channel)
        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 @@ int bridge_channel_internal_join(struct ast_bridge_channel *bridge_channel)
 
        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));