<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14898">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
George Joseph: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_session: Fix issue with COLP and 491<br><br>The recent 491 changes introduced a check to determine if the active<br>and pending topologies were equal and to suppress the re-invite if they<br>were. When a re-invite is sent for a COLP-only change, the pending<br>topology is NULL so that check doesn't happen and the re-invite is<br>correctly sent. Of course, sending the re-invite sets the pending<br>topology. If a 491 is received, when we resend the re-invite, the<br>pending topology is set and since we didn't request a change to the<br>topology in the first place, pending and active topologies are equal so<br>the topologies-equal check causes the re-invite to be erroneously<br>suppressed.<br><br>This change checks if the topologies are equal before we run the media<br>state resolver (which recreates the pending topology) so that when we<br>do the final topologies-equal check we know if this was a topology<br>change request. If it wasn't a change request, we don't suppress<br>the re-invite even though the topologies are equal.<br><br>ASTERISK-29014<br><br>Change-Id: Iffd7dd0500301156a566119ebde528d1a9573314<br>---<br>M res/res_pjsip_session.c<br>1 file changed, 29 insertions(+), 17 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index b93fa4e..7b66430 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -1596,11 +1596,12 @@</span><br><span> struct ast_sip_session_delayed_request *delay = delayed_request_alloc(method,</span><br><span> on_request, on_sdp_creation, on_response, generate_new_sdp, pending_media_state,</span><br><span> active_media_state);</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_ENTER(3, "%s\n", ast_sip_session_get_name(session));</span><br><span> </span><br><span> if (!delay) {</span><br><span> ast_sip_session_media_state_free(pending_media_state);</span><br><span> ast_sip_session_media_state_free(active_media_state);</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_EXIT_LOG_RTN_VALUE(-1, LOG_ERROR, "Unable to allocate delay request\n");</span><br><span> }</span><br><span> </span><br><span> if (method == DELAYED_METHOD_BYE || queue_head) {</span><br><span>@@ -1609,14 +1610,14 @@</span><br><span> } else {</span><br><span> AST_LIST_INSERT_TAIL(&session->delayed_requests, delay, next);</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_EXIT_RTN_VALUE(0);</span><br><span> }</span><br><span> </span><br><span> static pjmedia_sdp_session *generate_session_refresh_sdp(struct ast_sip_session *session)</span><br><span> {</span><br><span> pjsip_inv_session *inv_session = session->inv_session;</span><br><span> const pjmedia_sdp_session *previous_sdp = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- SCOPE_ENTER(1, "%s\n", ast_sip_session_get_name(session));</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_ENTER(3, "%s\n", ast_sip_session_get_name(session));</span><br><span> </span><br><span> if (inv_session->neg) {</span><br><span> if (pjmedia_sdp_neg_was_answer_remote(inv_session->neg)) {</span><br><span>@@ -2258,6 +2259,7 @@</span><br><span> if (pending_media_state) {</span><br><span> int index;</span><br><span> int type_streams[AST_MEDIA_TYPE_END] = {0};</span><br><span style="color: hsl(120, 100%, 40%);">+ int topology_change_request = 0;</span><br><span> </span><br><span> ast_trace(-1, "%s: Pending media state exists\n", ast_sip_session_get_name(session));</span><br><span> </span><br><span>@@ -2278,8 +2280,16 @@</span><br><span> </span><br><span> if (active_media_state) {</span><br><span> struct ast_sip_session_media_state *new_pending_state;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * We need to check if the passed in active and pending states are equal</span><br><span style="color: hsl(120, 100%, 40%);">+ * before we run the media states resolver. We'll use the flag later</span><br><span style="color: hsl(120, 100%, 40%);">+ * to signal whether this was topology change or some other change such</span><br><span style="color: hsl(120, 100%, 40%);">+ * as a connected line change.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ topology_change_request = !ast_stream_topology_equal(active_media_state->topology, pending_media_state->topology);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_trace(-1, "%s: Active media state exists\n", ast_sip_session_get_name(session));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_trace(-1, "%s: Active media state exists and is%s equal to pending\n", ast_sip_session_get_name(session),</span><br><span style="color: hsl(120, 100%, 40%);">+ topology_change_request ? " not" : "");</span><br><span> ast_trace(-1, "%s: DP: %s\n", ast_sip_session_get_name(session), ast_str_tmp(256, ast_stream_topology_to_str(pending_media_state->topology, &STR_TMP)));</span><br><span> ast_trace(-1, "%s: DA: %s\n", ast_sip_session_get_name(session), ast_str_tmp(256, ast_stream_topology_to_str(active_media_state->topology, &STR_TMP)));</span><br><span> ast_trace(-1, "%s: CP: %s\n", ast_sip_session_get_name(session), ast_str_tmp(256, ast_stream_topology_to_str(session->pending_media_state->topology, &STR_TMP)));</span><br><span>@@ -2437,8 +2447,13 @@</span><br><span> ast_sip_session_get_name(session), position);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /* If the resulting media state matches the existing active state don't bother doing a session refresh */</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_stream_topology_equal(session->active_media_state->topology, pending_media_state->topology)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * We can suppress this re-invite if the pending topology is equal to the currently</span><br><span style="color: hsl(120, 100%, 40%);">+ * active topology but only if this re-invite was the result of a requested topology</span><br><span style="color: hsl(120, 100%, 40%);">+ * change. If it was the result of some other change, like connected line, then</span><br><span style="color: hsl(120, 100%, 40%);">+ * we don't want to suppress it even though the topologies are equal.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (topology_change_request && ast_stream_topology_equal(session->active_media_state->topology, pending_media_state->topology)) {</span><br><span> ast_trace(-1, "%s: CA: %s\n", ast_sip_session_get_name(session), ast_str_tmp(256, ast_stream_topology_to_str(session->active_media_state->topology, &STR_TMP)));</span><br><span> ast_trace(-1, "%s: NP: %s\n", ast_sip_session_get_name(session), ast_str_tmp(256, ast_stream_topology_to_str(pending_media_state->topology, &STR_TMP)));</span><br><span> ast_sip_session_media_state_free(pending_media_state);</span><br><span>@@ -4185,34 +4200,29 @@</span><br><span> struct ast_sip_session_media_state *pending_media_state;</span><br><span> struct ast_sip_session_media_state *active_media_state;</span><br><span> const char *session_name = ast_sip_session_get_name(session);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(3, "%s re-INVITE collision.\n", session_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_ENTER(3, "%s\n", session_name);</span><br><span> </span><br><span> pending_media_state = ast_sip_session_media_state_clone(session->pending_media_state);</span><br><span> if (!pending_media_state) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "%s: Failed to clone pending media state\n", session_name);</span><br><span style="color: hsl(0, 100%, 40%);">- return;</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_EXIT_LOG_RTN(LOG_ERROR, "%s: Failed to clone pending media state\n", session_name);</span><br><span> }</span><br><span> </span><br><span> active_media_state = ast_sip_session_media_state_clone(session->active_media_state);</span><br><span> if (!active_media_state) {</span><br><span> ast_sip_session_media_state_free(pending_media_state);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "%s: Failed to clone active media state\n", session_name);</span><br><span style="color: hsl(0, 100%, 40%);">- return;</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_EXIT_LOG_RTN(LOG_ERROR, "%s: Failed to clone active media state\n", session_name);</span><br><span> }</span><br><span> </span><br><span> if (delay_request(session, NULL, NULL, on_response, 1, DELAYED_METHOD_INVITE, pending_media_state,</span><br><span> active_media_state, 1)) {</span><br><span> ast_sip_session_media_state_free(pending_media_state);</span><br><span> ast_sip_session_media_state_free(active_media_state);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "%s: Failed to add delayed request\n", session_name);</span><br><span style="color: hsl(0, 100%, 40%);">- return;</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_EXIT_LOG_RTN(LOG_ERROR, "%s: Failed to add delayed request\n", session_name);</span><br><span> }</span><br><span> </span><br><span> if (pj_timer_entry_running(&session->rescheduled_reinvite)) {</span><br><span> /* Timer already running. Something weird is going on. */</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "%s: re-INVITE collision while timer running!!!\n", session_name);</span><br><span style="color: hsl(0, 100%, 40%);">- return;</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_EXIT_LOG_RTN(LOG_ERROR, "%s: re-INVITE collision while timer running!!!\n", session_name);</span><br><span> }</span><br><span> </span><br><span> tv.sec = 0;</span><br><span>@@ -4227,8 +4237,10 @@</span><br><span> if (pjsip_endpt_schedule_timer(ast_sip_get_pjsip_endpoint(),</span><br><span> &session->rescheduled_reinvite, &tv) != PJ_SUCCESS) {</span><br><span> ao2_ref(session, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "%s: Couldn't schedule timer\n", session_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_EXIT_LOG_RTN(LOG_ERROR, "%s: Couldn't schedule timer\n", session_name);</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_EXIT_RTN();</span><br><span> }</span><br><span> </span><br><span> static void __print_debug_details(const char *function, pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_event *e)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14898">change 14898</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/14898"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Iffd7dd0500301156a566119ebde528d1a9573314 </div>
<div style="display:none"> Gerrit-Change-Number: 14898 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>