<p>Maximilian Fridrich has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19256">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Add 100rel option "peer_supported".<br><br>This patch adds a new option to the 100rel parameter for pjsip<br>endpoints called "peer_supported". When an endpoint with this option<br>receives an incoming request and the request indicated support for the<br>100rel extension, then Asterisk will send 1xx responses reliably. If<br>the request did not indicate 100rel support, Asterisk sends 1xx<br>responses normally.<br><br>ASTERISK-30158<br><br>Change-Id: Id6d95ffa8f00dab118e0b386146e99f254f287ad<br>---<br>A contrib/ast-db-manage/config/versions/539f68bede2c_add_peer_supported_to_100rel.py<br>A doc/CHANGES-staging/res_pjsip_100rel_option.txt<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip/pjsip_config.xml<br>M res/res_pjsip/pjsip_configuration.c<br>M res/res_pjsip_session.c<br>6 files changed, 152 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/56/19256/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/contrib/ast-db-manage/config/versions/539f68bede2c_add_peer_supported_to_100rel.py b/contrib/ast-db-manage/config/versions/539f68bede2c_add_peer_supported_to_100rel.py</span><br><span>new file mode 100644</span><br><span>index 0000000..1a3572c</span><br><span>--- /dev/null</span><br><span>+++ b/contrib/ast-db-manage/config/versions/539f68bede2c_add_peer_supported_to_100rel.py</span><br><span>@@ -0,0 +1,57 @@</span><br><span style="color: hsl(120, 100%, 40%);">+"""Add peer_supported to 100rel</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Revision ID: 539f68bede2c</span><br><span style="color: hsl(120, 100%, 40%);">+Revises: 7197536bb68d</span><br><span style="color: hsl(120, 100%, 40%);">+Create Date: 2022-08-10 09:36:16.576049</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 style="color: hsl(120, 100%, 40%);">+# revision identifiers, used by Alembic.</span><br><span style="color: hsl(120, 100%, 40%);">+revision = '539f68bede2c'</span><br><span style="color: hsl(120, 100%, 40%);">+down_revision = '7197536bb68d'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+from alembic import op</span><br><span style="color: hsl(120, 100%, 40%);">+from sqlalchemy.dialects.postgresql import ENUM</span><br><span style="color: hsl(120, 100%, 40%);">+import sqlalchemy as sa</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%);">+OLD_ENUM = ['no', 'required', 'yes']</span><br><span style="color: hsl(120, 100%, 40%);">+NEW_ENUM = ['no', 'required', 'peer_supported', 'yes']</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+old_type = sa.Enum(*OLD_ENUM, name='pjsip_100rel_values')</span><br><span style="color: hsl(120, 100%, 40%);">+new_type = sa.Enum(*NEW_ENUM, name='pjsip_100rel_values_v2')</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def upgrade():</span><br><span style="color: hsl(120, 100%, 40%);">+    context = op.get_context()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # Upgrading to this revision WILL clear your directmedia values.</span><br><span style="color: hsl(120, 100%, 40%);">+    if context.bind.dialect.name != 'postgresql':</span><br><span style="color: hsl(120, 100%, 40%);">+        op.alter_column('ps_endpoints', '100rel',</span><br><span style="color: hsl(120, 100%, 40%);">+                        type_=new_type,</span><br><span style="color: hsl(120, 100%, 40%);">+                        existing_type=old_type)</span><br><span style="color: hsl(120, 100%, 40%);">+    else:</span><br><span style="color: hsl(120, 100%, 40%);">+        enum = ENUM(*NEW_ENUM, name='pjsip_100rel_values_v2')</span><br><span style="color: hsl(120, 100%, 40%);">+        enum.create(op.get_bind(), checkfirst=False)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        op.execute('ALTER TABLE ps_endpoints ALTER COLUMN 100rel TYPE'</span><br><span style="color: hsl(120, 100%, 40%);">+                   ' pjsip_100rel_values_v2 USING'</span><br><span style="color: hsl(120, 100%, 40%);">+                   ' 100rel::text::pjsip_100rel_values_v2')</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        ENUM(name="pjsip_100rel_values").drop(op.get_bind(), checkfirst=False)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def downgrade():</span><br><span style="color: hsl(120, 100%, 40%);">+    context = op.get_context()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if context.bind.dialect.name != 'postgresql':</span><br><span style="color: hsl(120, 100%, 40%);">+        op.alter_column('ps_endpoints', '100rel',</span><br><span style="color: hsl(120, 100%, 40%);">+                        type_=old_type,</span><br><span style="color: hsl(120, 100%, 40%);">+                        existing_type=new_type)</span><br><span style="color: hsl(120, 100%, 40%);">+    else:</span><br><span style="color: hsl(120, 100%, 40%);">+        enum = ENUM(*OLD_ENUM, name='pjsip_100rel_values')</span><br><span style="color: hsl(120, 100%, 40%);">+        enum.create(op.get_bind(), checkfirst=False)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        op.execute('ALTER TABLE ps_endpoints ALTER COLUMN 100rel TYPE'</span><br><span style="color: hsl(120, 100%, 40%);">+                   ' pjsip_100rel_values USING'</span><br><span style="color: hsl(120, 100%, 40%);">+                   ' 100rel::text::pjsip_100rel_values')</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        ENUM(name="pjsip_100rel_values_v2").drop(op.get_bind(), checkfirst=False)</span><br><span>diff --git a/doc/CHANGES-staging/res_pjsip_100rel_option.txt b/doc/CHANGES-staging/res_pjsip_100rel_option.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..81af80a</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/res_pjsip_100rel_option.txt</span><br><span>@@ -0,0 +1,6 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_pjsip</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+A new option named "peer_supported" has been added to the endpoint option</span><br><span style="color: hsl(120, 100%, 40%);">+100rel. When set to this option, Asterisk sends provisional responses</span><br><span style="color: hsl(120, 100%, 40%);">+reliably if the peer supports it. If the peer does not support reliable</span><br><span style="color: hsl(120, 100%, 40%);">+provisional responses, Asterisk sends them normally.</span><br><span>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h</span><br><span>index dcdf2b3..3cba04a 100644</span><br><span>--- a/include/asterisk/res_pjsip.h</span><br><span>+++ b/include/asterisk/res_pjsip.h</span><br><span>@@ -450,6 +450,20 @@</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief 100rel modes for SIP endpoints</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+enum ast_sip_100rel_mode {</span><br><span style="color: hsl(120, 100%, 40%);">+   /*! Do not support 100rel. (no) */</span><br><span style="color: hsl(120, 100%, 40%);">+    AST_SIP_100REL_UNSUPPORTED = 0,</span><br><span style="color: hsl(120, 100%, 40%);">+       /*! As UAC, indicate 100rel support in Supported header. (yes) */</span><br><span style="color: hsl(120, 100%, 40%);">+     AST_SIP_100REL_SUPPORTED,</span><br><span style="color: hsl(120, 100%, 40%);">+     /*! As UAS, send 1xx responses reliably, if the UAC indicated its support. Otherwise same as AST_SIP_100REL_SUPPORTED. (peer_supported) */</span><br><span style="color: hsl(120, 100%, 40%);">+    AST_SIP_100REL_PEER_SUPPORTED,</span><br><span style="color: hsl(120, 100%, 40%);">+        /*! Require the use of 100rel. (required) */</span><br><span style="color: hsl(120, 100%, 40%);">+  AST_SIP_100REL_REQUIRED,</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>  * \brief DTMF modes for SIP endpoints</span><br><span>  */</span><br><span> enum ast_sip_dtmf_mode {</span><br><span>@@ -981,6 +995,8 @@</span><br><span>       AST_STRING_FIELD_EXTENDED(geoloc_incoming_call_profile);</span><br><span>     /*! The name of the geoloc profile to apply when Asterisk sends a call to this endpoint */</span><br><span>   AST_STRING_FIELD_EXTENDED(geoloc_outgoing_call_profile);</span><br><span style="color: hsl(120, 100%, 40%);">+      /*! 100rel mode to use with this endpoint */</span><br><span style="color: hsl(120, 100%, 40%);">+  enum ast_sip_100rel_mode rel100;</span><br><span> };</span><br><span> </span><br><span> /*! URI parameter for symmetric transport */</span><br><span>diff --git a/res/res_pjsip/pjsip_config.xml b/res/res_pjsip/pjsip_config.xml</span><br><span>index d78efe32..3cec9a4 100644</span><br><span>--- a/res/res_pjsip/pjsip_config.xml</span><br><span>+++ b/res/res_pjsip/pjsip_config.xml</span><br><span>@@ -32,9 +32,33 @@</span><br><span>                                        <synopsis>Allow support for RFC3262 provisional ACK tags</synopsis></span><br><span>                                      <description></span><br><span>                                          <enumlist></span><br><span style="color: hsl(0, 100%, 40%);">-                                                        <enum name="no" /></span><br><span style="color: hsl(0, 100%, 40%);">-                                                      <enum name="required" /></span><br><span style="color: hsl(0, 100%, 40%);">-                                                        <enum name="yes" /></span><br><span style="color: hsl(120, 100%, 40%);">+                                                   <enum name="no"></span><br><span style="color: hsl(120, 100%, 40%);">+                                                      <para>If set to <literal>no</literal>, do not support transmission of</span><br><span style="color: hsl(120, 100%, 40%);">+                                                       reliable provisional responses. As UAS, if an incoming request contains 100rel</span><br><span style="color: hsl(120, 100%, 40%);">+                                                        in the Required header, it is rejected with 420 Bad Extension.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                                   </enum></span><br><span style="color: hsl(120, 100%, 40%);">+                                                 <enum name="required"></span><br><span style="color: hsl(120, 100%, 40%);">+                                                        <para>If set to <literal>required</literal>, require provisional responses to</span><br><span style="color: hsl(120, 100%, 40%);">+                                                       be sent and received reliably. As UAS, incoming requests without 100rel</span><br><span style="color: hsl(120, 100%, 40%);">+                                                       in the Supported header are rejected with 421 Extension Required. As UAC,</span><br><span style="color: hsl(120, 100%, 40%);">+                                                     outgoing requests will have 100rel in the Required header.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                                       </enum></span><br><span style="color: hsl(120, 100%, 40%);">+                                                 <enum name="peer_supported"></span><br><span style="color: hsl(120, 100%, 40%);">+                                                  <para>If set to <literal>peer_supported</literal>, send provisional responses</span><br><span style="color: hsl(120, 100%, 40%);">+                                                       reliably if the request by the peer contained 100rel in the Supported or</span><br><span style="color: hsl(120, 100%, 40%);">+                                                      Require header. As UAS, if an incoming request contains 100rel in the Supported</span><br><span style="color: hsl(120, 100%, 40%);">+                                                       header, send 1xx responses reliably. If the request by the peer does not contain 100rel</span><br><span style="color: hsl(120, 100%, 40%);">+                                                       in the Supported and Require header, send responses normally. As UAC, outgoing requests</span><br><span style="color: hsl(120, 100%, 40%);">+                                                       will contain 100rel in the Supported header.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                                     </enum></span><br><span style="color: hsl(120, 100%, 40%);">+                                                 <enum name="yes"></span><br><span style="color: hsl(120, 100%, 40%);">+                                                     <para>If set to <literal>yes</literal>, indicate the support of reliable provisional</span><br><span style="color: hsl(120, 100%, 40%);">+                                                        responses and PRACK them if required by the peer. As UAS, if the incoming request</span><br><span style="color: hsl(120, 100%, 40%);">+                                                     contains 100rel in the Supported header but not in the Required header, send 1xx</span><br><span style="color: hsl(120, 100%, 40%);">+                                                      responses normally. If the incoming request contains 100rel in the Required header,</span><br><span style="color: hsl(120, 100%, 40%);">+                                                   send 1xx responses reliably. As UAC add 100rel to the Supported header and PRACK 1xx</span><br><span style="color: hsl(120, 100%, 40%);">+                                                  responses if required.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                                   </enum></span><br><span>                                                </enumlist></span><br><span>                                    </description></span><br><span>                                 </configOption></span><br><span>diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c</span><br><span>index 6bc978d..cf42f88 100644</span><br><span>--- a/res/res_pjsip/pjsip_configuration.c</span><br><span>+++ b/res/res_pjsip/pjsip_configuration.c</span><br><span>@@ -182,9 +182,16 @@</span><br><span> </span><br><span>    if (ast_true(var->value)) {</span><br><span>               endpoint->extensions.flags |= PJSIP_INV_SUPPORT_100REL;</span><br><span style="color: hsl(120, 100%, 40%);">+            endpoint->rel100 = AST_SIP_100REL_SUPPORTED;</span><br><span style="color: hsl(120, 100%, 40%);">+       } else if (!strcasecmp(var->value, "peer_supported")) {</span><br><span style="color: hsl(120, 100%, 40%);">+          endpoint->extensions.flags |= PJSIP_INV_SUPPORT_100REL;</span><br><span style="color: hsl(120, 100%, 40%);">+            endpoint->rel100 = AST_SIP_100REL_PEER_SUPPORTED;</span><br><span>         } else if (!strcasecmp(var->value, "required")) {</span><br><span>               endpoint->extensions.flags |= PJSIP_INV_REQUIRE_100REL;</span><br><span style="color: hsl(0, 100%, 40%);">-      } else if (!ast_false(var->value)){</span><br><span style="color: hsl(120, 100%, 40%);">+                endpoint->rel100 = AST_SIP_100REL_REQUIRED;</span><br><span style="color: hsl(120, 100%, 40%);">+        } else if (ast_false(var->value)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                endpoint->rel100 = AST_SIP_100REL_UNSUPPORTED;</span><br><span style="color: hsl(120, 100%, 40%);">+     } else {</span><br><span>             return -1;</span><br><span>   }</span><br><span> </span><br><span>@@ -195,10 +202,12 @@</span><br><span> {</span><br><span>   const struct ast_sip_endpoint *endpoint = obj;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-      if (endpoint->extensions.flags & PJSIP_INV_REQUIRE_100REL) {</span><br><span style="color: hsl(0, 100%, 40%);">-             *buf = "required";</span><br><span style="color: hsl(0, 100%, 40%);">-    } else if (endpoint->extensions.flags & PJSIP_INV_SUPPORT_100REL) {</span><br><span style="color: hsl(120, 100%, 40%);">+    if (endpoint->rel100 == AST_SIP_100REL_SUPPORTED) {</span><br><span>               *buf = "yes";</span><br><span style="color: hsl(120, 100%, 40%);">+       } else if (endpoint->rel100 == AST_SIP_100REL_PEER_SUPPORTED) {</span><br><span style="color: hsl(120, 100%, 40%);">+            *buf = "peer_supported";</span><br><span style="color: hsl(120, 100%, 40%);">+    } else if (endpoint->rel100 == AST_SIP_100REL_REQUIRED) {</span><br><span style="color: hsl(120, 100%, 40%);">+          *buf = "required";</span><br><span>         } else {</span><br><span>             *buf = "no";</span><br><span>       }</span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index 858faf3..2b2d92e 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -3789,8 +3789,23 @@</span><br><span>  pjsip_dialog *dlg;</span><br><span>   pjsip_inv_session *inv_session;</span><br><span>      unsigned int options = endpoint->extensions.flags;</span><br><span style="color: hsl(120, 100%, 40%);">+ const pj_str_t STR_100REL = { "100rel", 6};</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int i;</span><br><span>      pj_status_t dlg_status = PJ_EUNKNOWN;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+     /*</span><br><span style="color: hsl(120, 100%, 40%);">+     * If 100rel is set to "peer_supported" on the endpoint and the peer indicated support for 100rel</span><br><span style="color: hsl(120, 100%, 40%);">+    * in the Supported header, send 1xx responses reliably by adding PJSIP_INV_REQUIRE_100REL to pjsip_inv_options flags.</span><br><span style="color: hsl(120, 100%, 40%);">+         */</span><br><span style="color: hsl(120, 100%, 40%);">+   if (endpoint->rel100 == AST_SIP_100REL_PEER_SUPPORTED && rdata->msg_info.supported != NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+           for (i = 0; i < rdata->msg_info.supported->count; ++i) {</span><br><span style="color: hsl(120, 100%, 40%);">+                     if (pj_stricmp(&rdata->msg_info.supported->values[i], &STR_100REL) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                              options |= PJSIP_INV_REQUIRE_100REL;</span><br><span style="color: hsl(120, 100%, 40%);">+                          break;</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 style="color: hsl(120, 100%, 40%);">+</span><br><span>  if (pjsip_inv_verify_request(rdata, &options, NULL, NULL, ast_sip_get_pjsip_endpoint(), &tdata) != PJ_SUCCESS) {</span><br><span>             if (tdata) {</span><br><span>                         if (pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL) != PJ_SUCCESS) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19256">change 19256</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/+/19256"/><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: Id6d95ffa8f00dab118e0b386146e99f254f287ad </div>
<div style="display:none"> Gerrit-Change-Number: 19256 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Maximilian Fridrich <m.fridrich@commend.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>