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
This commit is contained in:
Joshua C. Colp 2021-11-16 06:06:26 -04:00 committed by George Joseph
parent ca2e13e18f
commit 7d4e37a180
1 changed files with 25 additions and 0 deletions

View 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));