<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14897">View Change</a></p><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 they were originally<br>equal and it's OK if they are equal now. In this case, we continue and<br>send the re-invite.<br><br>ASTERISK-29014<br><br>Change-Id: Iffd7dd0500301156a566119ebde528d1a9573314<br>---<br>M res/res_pjsip_session.c<br>1 file changed, 17 insertions(+), 16 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/97/14897/1</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..a99b625 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 original_states_equal = 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,10 @@</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%);">+ original_states_equal = 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%);">+ original_states_equal ? "" : " 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>@@ -2438,7 +2442,7 @@</span><br><span> }</span><br><span> </span><br><span> /* 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%);">+ if (!original_states_equal && 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 +4189,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 +4226,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/+/14897">change 14897</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/+/14897"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: Iffd7dd0500301156a566119ebde528d1a9573314 </div>
<div style="display:none"> Gerrit-Change-Number: 14897 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>