<p>Henning Westerholt has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18990">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: return all codecs on a re-INVITE without SDP<br><br>Currently chan_pjsip on receiving a re-INVITE without SDP will only return<br>the codecs that are previously negotiated and not offering all enabled<br>codecs.<br><br>This causes interoperability issues with different equipment (e.g. from Cisco)<br>for some of our customers and probably also in other scenarios involving 3PCC<br>infrastructure.<br><br>According to RFC 3261, section 14.2 it SHOULD return all codecs on a re-INVITE<br>without SDP<br><br>The PR proposes a new parameter to configure this behaviour:<br>all_codecs_on_empty_reinvite. It includes the code, documentation and<br>example configuration additions.<br><br>ASTERISK-30193 #close<br><br>Change-Id: I69763708d5039d512f391e296ee8a4d43a1e2148<br>---<br>M configs/samples/pjsip.conf.sample<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip/config_global.c<br>M res/res_pjsip/pjsip_config.xml<br>M res/res_pjsip_session.c<br>5 files changed, 79 insertions(+), 10 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/90/18990/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample</span><br><span>index 4436951..328e526 100644</span><br><span>--- a/configs/samples/pjsip.conf.sample</span><br><span>+++ b/configs/samples/pjsip.conf.sample</span><br><span>@@ -1277,6 +1277,9 @@</span><br><span> ; that the User Agent is capable of accepting a REFER request with</span><br><span> ; creating an implicit subscription (see RFC 4488).</span><br><span> ; (default: "yes")</span><br><span style="color: hsl(120, 100%, 40%);">+;all_codecs_on_empty_reinvite=yes</span><br><span style="color: hsl(120, 100%, 40%);">+ ; If we should return all codecs on empty re-INVITE.</span><br><span style="color: hsl(120, 100%, 40%);">+ ; RFC 3261 specify it SHOULD be done like this.</span><br><span> </span><br><span> ;allow_sending_180_after_183=yes ; Allow Asterisk to send 180 Ringing to an endpoint</span><br><span> ; after 183 Session Progress has been send.</span><br><span>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h</span><br><span>index 1714cff..3c20fbf 100644</span><br><span>--- a/include/asterisk/res_pjsip.h</span><br><span>+++ b/include/asterisk/res_pjsip.h</span><br><span>@@ -3500,4 +3500,12 @@</span><br><span> */</span><br><span> void ast_sip_transport_state_unregister(struct ast_sip_tpmgr_state_callback *element);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Retrieve the system setting 'all_codecs_on_empty_reinvite'.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since unreleased</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non zero if we should return all codecs on empty re-INVITE</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+unsigned int ast_sip_get_all_codecs_on_empty_reinvite(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #endif /* _RES_PJSIP_H */</span><br><span>diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c</span><br><span>index 4620c3f..1056e53 100644</span><br><span>--- a/res/res_pjsip/config_global.c</span><br><span>+++ b/res/res_pjsip/config_global.c</span><br><span>@@ -54,6 +54,7 @@</span><br><span> #define DEFAULT_SEND_CONTACT_STATUS_ON_UPDATE_REGISTRATION 0</span><br><span> #define DEFAULT_TASKPROCESSOR_OVERLOAD_TRIGGER TASKPROCESSOR_OVERLOAD_TRIGGER_GLOBAL</span><br><span> #define DEFAULT_NOREFERSUB 1</span><br><span style="color: hsl(120, 100%, 40%);">+#define DEFAULT_ALL_CODECS_ON_EMPTY_REINVITE 1</span><br><span> </span><br><span> /*!</span><br><span> * \brief Cached global config object</span><br><span>@@ -119,6 +120,8 @@</span><br><span> enum ast_sip_taskprocessor_overload_trigger overload_trigger;</span><br><span> /*! Nonzero if norefersub is to be sent in Supported header */</span><br><span> unsigned int norefersub;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Nonzero if we should return all codecs on empty re-INVITE */</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int all_codecs_on_empty_reinvite;</span><br><span> };</span><br><span> </span><br><span> static void global_destructor(void *obj)</span><br><span>@@ -537,6 +540,21 @@</span><br><span> return norefersub;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+unsigned int ast_sip_get_all_codecs_on_empty_reinvite(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int all_codecs_on_empty_reinvite;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct global_config *cfg;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ cfg = get_global_cfg();</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!cfg) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return DEFAULT_ALL_CODECS_ON_EMPTY_REINVITE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ all_codecs_on_empty_reinvite = cfg->all_codecs_on_empty_reinvite;</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(cfg, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return all_codecs_on_empty_reinvite;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int overload_trigger_handler(const struct aco_option *opt,</span><br><span> struct ast_variable *var, void *obj)</span><br><span> {</span><br><span>@@ -744,6 +762,9 @@</span><br><span> ast_sorcery_object_field_register(sorcery, "global", "norefersub",</span><br><span> DEFAULT_NOREFERSUB ? "yes" : "no",</span><br><span> OPT_YESNO_T, 1, FLDSET(struct global_config, norefersub));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_object_field_register(sorcery, "global", "all_codecs_on_empty_reinvite",</span><br><span style="color: hsl(120, 100%, 40%);">+ DEFAULT_ALL_CODECS_ON_EMPTY_REINVITE ? "yes" : "no",</span><br><span style="color: hsl(120, 100%, 40%);">+ OPT_BOOL_T, 1, FLDSET(struct global_config, all_codecs_on_empty_reinvite));</span><br><span> </span><br><span> if (ast_sorcery_instance_observer_add(sorcery, &observer_callbacks_global)) {</span><br><span> return -1;</span><br><span>diff --git a/res/res_pjsip/pjsip_config.xml b/res/res_pjsip/pjsip_config.xml</span><br><span>index e9abc86..7d87097 100644</span><br><span>--- a/res/res_pjsip/pjsip_config.xml</span><br><span>+++ b/res/res_pjsip/pjsip_config.xml</span><br><span>@@ -2071,6 +2071,13 @@</span><br><span> </para></span><br><span> </description></span><br><span> </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="all_codecs_on_empty_reinvite" default="yes"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>If we should return all codecs on empty re-INVITE</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <description><para></span><br><span style="color: hsl(120, 100%, 40%);">+ If we should return all codecs on empty re-INVITE. RFC 3261</span><br><span style="color: hsl(120, 100%, 40%);">+ specify this as a SHOULD requirement.</span><br><span style="color: hsl(120, 100%, 40%);">+ </para></description></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span> </configObject></span><br><span> </configFile></span><br><span> </configInfo></span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index 3c55af7..de32bae 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -101,7 +101,7 @@</span><br><span> char stream_type[1];</span><br><span> };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv, struct ast_sip_session *session, const pjmedia_sdp_session *offer);</span><br><span style="color: hsl(120, 100%, 40%);">+static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv, struct ast_sip_session *session, const pjmedia_sdp_session *offer, const unsigned int answer_all_codecs);</span><br><span> </span><br><span> static int sdp_handler_list_hash(const void *obj, int flags)</span><br><span> {</span><br><span>@@ -1619,7 +1619,7 @@</span><br><span> pjmedia_sdp_neg_get_active_local(inv_session->neg, &previous_sdp);</span><br><span> }</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- SCOPE_EXIT_RTN_VALUE(create_local_sdp(inv_session, session, previous_sdp));</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_EXIT_RTN_VALUE(create_local_sdp(inv_session, session, previous_sdp, 0));</span><br><span> }</span><br><span> </span><br><span> static void set_from_header(struct ast_sip_session *session)</span><br><span>@@ -2543,7 +2543,7 @@</span><br><span> pjmedia_sdp_neg_set_remote_offer(inv_session->pool, inv_session->neg, previous_offer);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- new_answer = create_local_sdp(inv_session, session, previous_offer);</span><br><span style="color: hsl(120, 100%, 40%);">+ new_answer = create_local_sdp(inv_session, session, previous_offer, 0);</span><br><span> if (!new_answer) {</span><br><span> ast_log(LOG_WARNING, "Could not create a new local SDP answer for channel '%s'\n",</span><br><span> ast_channel_name(session->channel));</span><br><span>@@ -2832,7 +2832,7 @@</span><br><span> {</span><br><span> pjmedia_sdp_session *offer;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!(offer = create_local_sdp(session->inv_session, session, NULL))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(offer = create_local_sdp(session->inv_session, session, NULL, 0))) {</span><br><span> pjsip_inv_terminate(session->inv_session, 500, PJ_FALSE);</span><br><span> return -1;</span><br><span> }</span><br><span>@@ -4021,10 +4021,10 @@</span><br><span> goto end;</span><br><span> }</span><br><span> /* We are creating a local SDP which is an answer to their offer */</span><br><span style="color: hsl(0, 100%, 40%);">- local = create_local_sdp(invite->session->inv_session, invite->session, sdp_info->sdp);</span><br><span style="color: hsl(120, 100%, 40%);">+ local = create_local_sdp(invite->session->inv_session, invite->session, sdp_info->sdp, 0);</span><br><span> } else {</span><br><span> /* We are creating a local SDP which is an offer */</span><br><span style="color: hsl(0, 100%, 40%);">- local = create_local_sdp(invite->session->inv_session, invite->session, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ local = create_local_sdp(invite->session->inv_session, invite->session, NULL, 0);</span><br><span> }</span><br><span> </span><br><span> /* If we were unable to create a local SDP terminate the session early, it won't go anywhere */</span><br><span>@@ -5027,7 +5027,7 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv, struct ast_sip_session *session, const pjmedia_sdp_session *offer)</span><br><span style="color: hsl(120, 100%, 40%);">+static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv, struct ast_sip_session *session, const pjmedia_sdp_session *offer, const unsigned int answer_all_codecs)</span><br><span> {</span><br><span> static const pj_str_t STR_IN = { "IN", 2 };</span><br><span> static const pj_str_t STR_IP4 = { "IP4", 3 };</span><br><span>@@ -5060,11 +5060,19 @@</span><br><span> /* We've encountered a situation where we have been told to create a local SDP but noone has given us any indication</span><br><span> * of what kind of stream topology they would like. We try to not alter the current state of the SDP negotiation</span><br><span> * by using what is currently negotiated. If this is unavailable we fall back to what is configured on the endpoint.</span><br><span style="color: hsl(120, 100%, 40%);">+ * We will also do this if wanted by the answer_all_codecs flag.</span><br><span> */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_trace(1, "no information about stream topology received\n");</span><br><span> ast_stream_topology_free(session->pending_media_state->topology);</span><br><span style="color: hsl(0, 100%, 40%);">- if (session->active_media_state->topology) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (session->active_media_state->topology && !answer_all_codecs) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_trace(1, "using existing topology\n");</span><br><span> session->pending_media_state->topology = ast_stream_topology_clone(session->active_media_state->topology);</span><br><span> } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (answer_all_codecs) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_trace(1, "fall back to endpoint configuration - answer all codecs\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_trace(1, "fall back to endpoint configuration\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> session->pending_media_state->topology = ast_stream_topology_clone(session->endpoint->media.topology);</span><br><span> }</span><br><span> if (!session->pending_media_state->topology) {</span><br><span>@@ -5198,7 +5206,7 @@</span><br><span> SCOPE_EXIT_RTN("%s: handle_incoming_sdp failed\n", ast_sip_session_get_name(session));</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if ((answer = create_local_sdp(inv, session, offer))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((answer = create_local_sdp(inv, session, offer, 0))) {</span><br><span> pjsip_inv_set_sdp_answer(inv, answer);</span><br><span> SCOPE_EXIT_RTN("%s: Set SDP answer\n", ast_sip_session_get_name(session));</span><br><span> }</span><br><span>@@ -5211,6 +5219,7 @@</span><br><span> const pjmedia_sdp_session *previous_sdp = NULL;</span><br><span> pjmedia_sdp_session *offer;</span><br><span> int i;</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int answer_all_codecs = 0;</span><br><span> </span><br><span> /* We allow PJSIP to produce an SDP if no channel is present. This may result</span><br><span> * in an incorrect SDP occurring, but if no channel is present then we are in</span><br><span>@@ -5218,10 +5227,27 @@</span><br><span> * produce an SDP doesn't need to worry about a channel being present or not,</span><br><span> * just in case.</span><br><span> */</span><br><span style="color: hsl(120, 100%, 40%);">+ SCOPE_ENTER(3, "%s\n", ast_sip_session_get_name(session));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_trace(1, "session_inv_on_create_offer\n");</span><br><span> if (!session->channel) {</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Some devices send a re-INVITE offer with empty SDP. Asterisk by default return</span><br><span style="color: hsl(120, 100%, 40%);">+ * an answer with the current used codecs, which is not strictly compliant to RFC</span><br><span style="color: hsl(120, 100%, 40%);">+ * 3261 (SHOULD requirement). So we detect this condition and include all</span><br><span style="color: hsl(120, 100%, 40%);">+ * configured codecs in the answer if the workaround is activated.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (inv->invite_tsx && inv->state == PJSIP_INV_STATE_CONFIRMED</span><br><span style="color: hsl(120, 100%, 40%);">+ && inv->invite_tsx->method.id == PJSIP_INVITE_METHOD) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_trace(1, "re-INVITE\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (inv->invite_tsx->role == PJSIP_ROLE_UAS && !pjmedia_sdp_neg_was_answer_remote(inv->neg)</span><br><span style="color: hsl(120, 100%, 40%);">+ && ast_sip_get_all_codecs_on_empty_reinvite()) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_trace(1, "no codecs in re-INIVTE, include all codecs in the answer\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ answer_all_codecs = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (inv->neg) {</span><br><span> if (pjmedia_sdp_neg_was_answer_remote(inv->neg)) {</span><br><span> pjmedia_sdp_neg_get_active_remote(inv->neg, &previous_sdp);</span><br><span>@@ -5230,7 +5256,11 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- offer = create_local_sdp(inv, session, previous_sdp);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (answer_all_codecs) {</span><br><span style="color: hsl(120, 100%, 40%);">+ offer = create_local_sdp(inv, session, NULL, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ offer = create_local_sdp(inv, session, previous_sdp, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> if (!offer) {</span><br><span> return;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18990">change 18990</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/+/18990"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I69763708d5039d512f391e296ee8a4d43a1e2148 </div>
<div style="display:none"> Gerrit-Change-Number: 18990 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Henning Westerholt <hw@gilawa.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>