<p>nappsoft has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14406">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_nat.c: remove x-ast-orig-host from request URI and To header<br><br>While asterisk is filtering out the x-ast-orig-host parameter from the<br>contact on response messages, it is not filtering it out from the<br>request URI and the to header on SIP requests (for example INVITE).<br><br>ASTERISK-28884 #close<br><br>Change-Id: Id032b33098a1befea9b243ca994184baecccc59e<br>---<br>M res/res_pjsip_nat.c<br>1 file changed, 27 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/06/14406/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip_nat.c b/res/res_pjsip_nat.c</span><br><span>index 01ce139..9dab32a 100644</span><br><span>--- a/res/res_pjsip_nat.c</span><br><span>+++ b/res/res_pjsip_nat.c</span><br><span>@@ -37,6 +37,9 @@</span><br><span> #define AST_SIP_X_AST_ORIG_HOST "x-ast-orig-host"</span><br><span> #define AST_SIP_X_AST_ORIG_HOST_LEN 15</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define is_sip_uri(uri) \</span><br><span style="color: hsl(120, 100%, 40%);">+ (PJSIP_URI_SCHEME_IS_SIP(uri) || PJSIP_URI_SCHEME_IS_SIPS(uri))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void save_orig_contact_host(pjsip_rx_data *rdata, pjsip_sip_uri *uri)</span><br><span> {</span><br><span> pjsip_param *x_orig_host;</span><br><span>@@ -303,6 +306,29 @@</span><br><span> static void restore_orig_contact_host(pjsip_tx_data *tdata)</span><br><span> {</span><br><span> pjsip_contact_hdr *contact;</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_str_t x_name = { AST_SIP_X_AST_ORIG_HOST, AST_SIP_X_AST_ORIG_HOST_LEN };</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_param *x_orig_host;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_sip_uri *uri;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_hdr *hdr;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (tdata->msg->type == PJSIP_REQUEST_MSG) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (is_sip_uri(tdata->msg->line.req.uri)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ uri = pjsip_uri_get_uri(tdata->msg->line.req.uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((x_orig_host = pjsip_param_find(&uri->other_param, &x_name))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_list_erase(x_orig_host);</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%);">+ for (hdr = tdata->msg->hdr.next; hdr != &tdata->msg->hdr; hdr = hdr->next) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (hdr->type == PJSIP_H_TO) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (is_sip_uri(((pjsip_fromto_hdr *) hdr)->uri)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ uri = pjsip_uri_get_uri(((pjsip_fromto_hdr *) hdr)->uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((x_orig_host = pjsip_param_find(&uri->other_param, &x_name))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_list_erase(x_orig_host);</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 style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> if (tdata->msg->type != PJSIP_RESPONSE_MSG) {</span><br><span> return;</span><br><span>@@ -311,8 +337,7 @@</span><br><span> contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);</span><br><span> while (contact) {</span><br><span> pjsip_sip_uri *contact_uri = pjsip_uri_get_uri(contact->uri);</span><br><span style="color: hsl(0, 100%, 40%);">- pj_str_t x_name = { AST_SIP_X_AST_ORIG_HOST, AST_SIP_X_AST_ORIG_HOST_LEN };</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_param *x_orig_host = pjsip_param_find(&contact_uri->other_param, &x_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ x_orig_host = pjsip_param_find(&contact_uri->other_param, &x_name);</span><br><span> </span><br><span> if (x_orig_host) {</span><br><span> char host_port[x_orig_host->value.slen + 1];</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14406">change 14406</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/+/14406"/><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: Id032b33098a1befea9b243ca994184baecccc59e </div>
<div style="display:none"> Gerrit-Change-Number: 14406 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: nappsoft <infos@nappsoft.ch> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>