<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/6608">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
  Jenkins2: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pjsip_message_filter: Fix regression causing bad contact address<br><br>The "res_pjsip:  Filter out non SIP(S) requests" commit moved the<br>filtering of messages to pjproject's PJSIP_MOD_PRIORITY_TRANSPORT_LAYER<br>in order to filter out incoming bad uri schemes as early as possible.<br>Since the change affected outgoing messages as well and the TRANSPORT<br>layer is the last to be run on outgoing messages, we were overwriting<br>the setting of external_signaling_address (which is set earlier by<br>res_pjsip_nat) with an internal address.<br><br>* pjsip_message_filter now registers itself as a pjproject module<br>twice.  Once in the TSX layer for the outgoing messages (as it was<br>originally), then a second time in the TRANSPORT layer for the<br>incoming messages to catch the invalid uri schemes.<br><br>ASTERISK-27295<br>Reported by: Sean Bright<br><br>Change-Id: I2c90190c43370f8a9d1c4693a19fd65840689c8c<br>---<br>M res/res_pjsip/pjsip_message_filter.c<br>1 file changed, 23 insertions(+), 9 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip/pjsip_message_filter.c b/res/res_pjsip/pjsip_message_filter.c<br>index 63b8bd5..d2f9b95 100644<br>--- a/res/res_pjsip/pjsip_message_filter.c<br>+++ b/res/res_pjsip/pjsip_message_filter.c<br>@@ -36,13 +36,19 @@<br>  unsigned int disallow_from_domain_modification;<br> };<br> <br>-static pjsip_module filter_module = {<br>-      .name = { "Message Filtering", 17 },<br>+static pjsip_module filter_module_transport = {<br>+     .name = { "Message Filtering Transport", 27 },<br>      .id = -1,<br>     .priority = PJSIP_MOD_PRIORITY_TRANSPORT_LAYER,<br>+      .on_rx_request = filter_on_rx_message,<br>+};<br>+<br>+static pjsip_module filter_module_tsx = {<br>+   .name = { "Message Filtering TSX", 21 },<br>+   .id = -1,<br>+    .priority = PJSIP_MOD_PRIORITY_TSX_LAYER - 1,<br>         .on_tx_request = filter_on_tx_message,<br>        .on_tx_response = filter_on_tx_message,<br>-      .on_rx_request = filter_on_rx_message,<br> };<br> <br> /*! \brief Helper function to get (or allocate if not already present) restrictions on a message */<br>@@ -50,13 +56,13 @@<br> {<br>         struct filter_message_restrictions *restrictions;<br> <br>- restrictions = ast_sip_mod_data_get(tdata->mod_data, filter_module.id, MOD_DATA_RESTRICTIONS);<br>+    restrictions = ast_sip_mod_data_get(tdata->mod_data, filter_module_tsx.id, MOD_DATA_RESTRICTIONS);<br>         if (restrictions) {<br>           return restrictions;<br>  }<br> <br>  restrictions = PJ_POOL_ALLOC_T(tdata->pool, struct filter_message_restrictions);<br>-  ast_sip_mod_data_set(tdata->pool, tdata->mod_data, filter_module.id, MOD_DATA_RESTRICTIONS, restrictions);<br>+     ast_sip_mod_data_set(tdata->pool, tdata->mod_data, filter_module_tsx.id, MOD_DATA_RESTRICTIONS, restrictions);<br> <br>       return restrictions;<br> }<br>@@ -217,7 +223,8 @@<br> <br> static pj_status_t filter_on_tx_message(pjsip_tx_data *tdata)<br> {<br>- struct filter_message_restrictions *restrictions = ast_sip_mod_data_get(tdata->mod_data, filter_module.id, MOD_DATA_RESTRICTIONS);<br>+        struct filter_message_restrictions *restrictions =<br>+           ast_sip_mod_data_get(tdata->mod_data, filter_module_transport.id, MOD_DATA_RESTRICTIONS);<br>  pjsip_tpmgr_fla2_param prm;<br>   pjsip_cseq_hdr *cseq;<br>         pjsip_via_hdr *via;<br>@@ -277,7 +284,7 @@<br>                      /* prm.ret_addr is allocated from the tdata pool OR the transport so it is perfectly fine to just do an assignment like this */<br>                       pj_strassign(&uri->host, &prm.ret_addr);<br>                   uri->port = prm.ret_port;<br>-                 ast_debug(4, "Re-wrote Contact URI host/port to %.*s:%d\n",<br>+                        ast_debug(5, "Re-wrote Contact URI host/port to %.*s:%d (this may be re-written again later)\n",<br>                            (int)pj_strlen(&uri->host), pj_strbuf(&uri->host), uri->port);<br> <br>                    if (tdata->tp_info.transport->key.type == PJSIP_TRANSPORT_UDP ||<br>@@ -498,7 +505,8 @@<br> <br> void ast_res_pjsip_cleanup_message_filter(void)<br> {<br>- ast_sip_unregister_service(&filter_module);<br>+      ast_sip_unregister_service(&filter_module_tsx);<br>+  ast_sip_unregister_service(&filter_module_transport);<br>     ast_sip_unregister_supplement(&filter_supplement);<br>        ast_sip_session_unregister_supplement(&filter_session_supplement);<br> }<br>@@ -516,7 +524,13 @@<br>              return -1;<br>    }<br> <br>- if (ast_sip_register_service(&filter_module)) {<br>+  if (ast_sip_register_service(&filter_module_transport)) {<br>+                ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n");<br>+               ast_res_pjsip_cleanup_message_filter();<br>+              return -1;<br>+   }<br>+<br>+ if (ast_sip_register_service(&filter_module_tsx)) {<br>               ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n");<br>                ast_res_pjsip_cleanup_message_filter();<br>               return -1;<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/6608">change 6608</a>. To unsubscribe, 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/6608"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 14 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I2c90190c43370f8a9d1c4693a19fd65840689c8c </div>
<div style="display:none"> Gerrit-Change-Number: 6608 </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: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>