]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_nat: Don't rewrite Contact on REGISTER responses.
authorJoshua C. Colp <jcolp@sangoma.com>
Wed, 24 Feb 2021 13:04:09 +0000 (09:04 -0400)
committerJoshua Colp <jcolp@sangoma.com>
Wed, 3 Mar 2021 18:27:32 +0000 (12:27 -0600)
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

res/res_pjsip_nat.c

index 3d6f25d5f682c469ed571875a2a5c47d7cb65f2c..1b5fdd12603b6b17309514efd2720e86306129a6 100644 (file)
@@ -432,12 +432,24 @@ static pj_status_t process_nat(pjsip_tx_data *tdata)
        }
 
        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))) {
-                       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;
-                               ast_debug(4, "Re-wrote Contact URI port to %d\n", uri->port);
+               pjsip_cseq_hdr *cseq = PJSIP_MSG_CSEQ_HDR(tdata->msg);
+
+               /* Update the Contact header with the external address. We only do this if
+                * a CSeq is not present (which should not happen - but we are extra safe),
+                * if a request is being sent, or if a response is sent that is not a response
+                * to a REGISTER. We specifically don't do this for a response to a REGISTER
+                * as the Contact headers would contain the registered Contacts, and not our
+                * own Contact.
+                */
+               if (!cseq || tdata->msg->type == PJSIP_REQUEST_MSG ||
+                       pjsip_method_cmp(&cseq->method, &pjsip_register_method)) {
+                       /* We can only rewrite the URI when one is present */
+                       if (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;
+                                       ast_debug(4, "Re-wrote Contact URI port to %d\n", uri->port);
+                               }
                        }
                }