Skip to content
Snippets Groups Projects
Commit 11f650c6 authored by Joshua Colp's avatar Joshua Colp
Browse files

stasis: Fix dial masquerade datastore lifetime

A recent change went into Asterisk which added reference counts to the
channels stored in a dial masquerade datastore. Unfortunately this
included a reference to the caller in a dialing operation. While all
of the dialed targets have the datastore removed from them upon dialing
completion this did not occur for the caller, causing it to have a
reference to itself that could go never go away (as it depended on
the destruction of the datastore which only happened when the channel
was destroyed). This resulted in the caller channel remaining on the
system despite it having hung up.

This change does the following to fix this issue:

1. The dial masquerade datastore is now removed from the caller upon
dialing completion, just like the dialed targets.
2. Upon destruction of the caller all the dialed targets are also
removed from the dial masquerade datastore (just in case).
3. The reference to the caller has been removed as it should not be
possible for the datastore to now be valid/useful after the lifetime
of the caller has ended.

ASTERISK-25025 #close

Change-Id: I1ef4ca5ca04980028604cc2af5d2992ac3431b3f
parent ce21776a
No related branches found
No related tags found
No related merge requests found
...@@ -364,6 +364,7 @@ static void ast_channel_publish_dial_internal(struct ast_channel *caller, ...@@ -364,6 +364,7 @@ static void ast_channel_publish_dial_internal(struct ast_channel *caller,
} }
static void remove_dial_masquerade(struct ast_channel *peer); static void remove_dial_masquerade(struct ast_channel *peer);
static void remove_dial_masquerade_caller(struct ast_channel *caller);
static int set_dial_masquerade(struct ast_channel *caller, static int set_dial_masquerade(struct ast_channel *caller,
struct ast_channel *peer, const char *dialstring); struct ast_channel *peer, const char *dialstring);
...@@ -373,6 +374,11 @@ void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_cha ...@@ -373,6 +374,11 @@ void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_cha
{ {
ast_assert(peer != NULL); ast_assert(peer != NULL);
/* XXX With an early bridge the below dial masquerade datastore code could, theoretically,
* go away as the act of changing the channel during dialing would be done using the bridge
* API itself and not a masquerade.
*/
if (caller) { if (caller) {
/* /*
* Lock two or three channels. * Lock two or three channels.
...@@ -407,6 +413,7 @@ void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_cha ...@@ -407,6 +413,7 @@ void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_cha
ast_channel_unlock(forwarded); ast_channel_unlock(forwarded);
} }
ast_channel_unlock(peer); ast_channel_unlock(peer);
remove_dial_masquerade_caller(caller);
ast_channel_unlock(caller); ast_channel_unlock(caller);
} }
} }
...@@ -1349,7 +1356,6 @@ static void dial_masquerade_datastore_cleanup(struct dial_masquerade_datastore * ...@@ -1349,7 +1356,6 @@ static void dial_masquerade_datastore_cleanup(struct dial_masquerade_datastore *
while ((cur = AST_LIST_REMOVE_HEAD(&masq_data->dialed_peers, list))) { while ((cur = AST_LIST_REMOVE_HEAD(&masq_data->dialed_peers, list))) {
dial_target_free(cur); dial_target_free(cur);
} }
masq_data->caller = ast_channel_cleanup(masq_data->caller);
} }
static void dial_masquerade_datastore_remove_chan(struct dial_masquerade_datastore *masq_data, struct ast_channel *chan) static void dial_masquerade_datastore_remove_chan(struct dial_masquerade_datastore *masq_data, struct ast_channel *chan)
...@@ -1399,6 +1405,16 @@ static void dial_masquerade_datastore_destroy(void *data) ...@@ -1399,6 +1405,16 @@ static void dial_masquerade_datastore_destroy(void *data)
ao2_ref(data, -1); ao2_ref(data, -1);
} }
/*!
* \internal
* \brief Datastore destructor for dial_masquerade_datastore
*/
static void dial_masquerade_caller_datastore_destroy(void *data)
{
dial_masquerade_datastore_cleanup(data);
ao2_ref(data, -1);
}
static struct ast_datastore *dial_masquerade_datastore_find(struct ast_channel *chan); static struct ast_datastore *dial_masquerade_datastore_find(struct ast_channel *chan);
static void dial_masquerade_fixup(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan) static void dial_masquerade_fixup(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
...@@ -1517,6 +1533,13 @@ static const struct ast_datastore_info dial_masquerade_info = { ...@@ -1517,6 +1533,13 @@ static const struct ast_datastore_info dial_masquerade_info = {
.chan_breakdown = dial_masquerade_breakdown, .chan_breakdown = dial_masquerade_breakdown,
}; };
static const struct ast_datastore_info dial_masquerade_caller_info = {
.type = "stasis-chan-dial-masq",
.destroy = dial_masquerade_caller_datastore_destroy,
.chan_fixup = dial_masquerade_fixup,
.chan_breakdown = dial_masquerade_breakdown,
};
/*! /*!
* \internal * \internal
* \brief Find the dial masquerade datastore on the given channel. * \brief Find the dial masquerade datastore on the given channel.
...@@ -1527,7 +1550,14 @@ static const struct ast_datastore_info dial_masquerade_info = { ...@@ -1527,7 +1550,14 @@ static const struct ast_datastore_info dial_masquerade_info = {
*/ */
static struct ast_datastore *dial_masquerade_datastore_find(struct ast_channel *chan) static struct ast_datastore *dial_masquerade_datastore_find(struct ast_channel *chan)
{ {
return ast_channel_datastore_find(chan, &dial_masquerade_info, NULL); struct ast_datastore *datastore;
datastore = ast_channel_datastore_find(chan, &dial_masquerade_info, NULL);
if (!datastore) {
datastore = ast_channel_datastore_find(chan, &dial_masquerade_caller_info, NULL);
}
return datastore;
} }
/*! /*!
...@@ -1546,7 +1576,7 @@ static struct dial_masquerade_datastore *dial_masquerade_datastore_add( ...@@ -1546,7 +1576,7 @@ static struct dial_masquerade_datastore *dial_masquerade_datastore_add(
{ {
struct ast_datastore *datastore; struct ast_datastore *datastore;
datastore = ast_datastore_alloc(&dial_masquerade_info, NULL); datastore = ast_datastore_alloc(!masq_data ? &dial_masquerade_caller_info : &dial_masquerade_info, NULL);
if (!datastore) { if (!datastore) {
return NULL; return NULL;
} }
...@@ -1557,7 +1587,7 @@ static struct dial_masquerade_datastore *dial_masquerade_datastore_add( ...@@ -1557,7 +1587,7 @@ static struct dial_masquerade_datastore *dial_masquerade_datastore_add(
ast_datastore_free(datastore); ast_datastore_free(datastore);
return NULL; return NULL;
} }
masq_data->caller = ast_channel_ref(chan); masq_data->caller = chan;
} }
datastore->data = masq_data; datastore->data = masq_data;
...@@ -1663,3 +1693,24 @@ static void remove_dial_masquerade(struct ast_channel *peer) ...@@ -1663,3 +1693,24 @@ static void remove_dial_masquerade(struct ast_channel *peer)
ast_channel_datastore_remove(peer, datastore); ast_channel_datastore_remove(peer, datastore);
ast_datastore_free(datastore); ast_datastore_free(datastore);
} }
static void remove_dial_masquerade_caller(struct ast_channel *caller)
{
struct ast_datastore *datastore;
struct dial_masquerade_datastore *masq_data;
datastore = dial_masquerade_datastore_find(caller);
if (!datastore) {
return;
}
masq_data = datastore->data;
if (!masq_data || !AST_LIST_EMPTY(&masq_data->dialed_peers)) {
return;
}
dial_masquerade_datastore_remove_chan(masq_data, caller);
ast_channel_datastore_remove(caller, datastore);
ast_datastore_free(datastore);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment