[Asterisk-code-review] res_pjsip_nat: Don't rewrite Contact on REGISTER responses. (asterisk[18])

Joshua Colp asteriskteam at digium.com
Wed Feb 24 07:04:28 CST 2021


Joshua Colp has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15515 )


Change subject: res_pjsip_nat: Don't rewrite Contact on REGISTER responses.
......................................................................

res_pjsip_nat: Don't rewrite Contact on REGISTER responses.

When sending a SIP response to an incoming REGISTER request
we don't want to change the Contact header as it will
contain the Contacts registered to the AOR and not our own
Contact URI.

ASTERISK-29235

Change-Id: I35a0723545281dd01fcd5cae497baab58720478c
---
M res/res_pjsip_nat.c
1 file changed, 10 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/15/15515/1

diff --git a/res/res_pjsip_nat.c b/res/res_pjsip_nat.c
index 3d6f25d..ce0a84b 100644
--- a/res/res_pjsip_nat.c
+++ b/res/res_pjsip_nat.c
@@ -432,8 +432,16 @@
 	}
 
 	if (!ast_sockaddr_isnull(&transport_state->external_signaling_address)) {
-		/* Update the contact header with the external address */
-		if (uri || (uri = nat_get_contact_sip_uri(tdata))) {
+		pjsip_cseq_hdr *cseq = PJSIP_MSG_CSEQ_HDR(tdata->msg);
+
+		/* Update the contact header with the external address, however if this is
+		 * a response to a REGISTER request we don't want to as the Contact headers
+		 * in the response are the registered Contacts and not our own.
+		 */
+
+		if ((!cseq || tdata->msg->type == PJSIP_REQUEST_MSG ||
+			pjsip_method_cmp(&cseq->method, &pjsip_register_method)) &&
+			(uri || (uri = nat_get_contact_sip_uri(tdata)))) {
 			pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport_state->external_signaling_address));
 			if (transport->external_signaling_port) {
 				uri->port = transport->external_signaling_port;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15515
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I35a0723545281dd01fcd5cae497baab58720478c
Gerrit-Change-Number: 15515
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210224/81551aeb/attachment.html>


More information about the asterisk-code-review mailing list