]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_nat.c: Do not overwrite transfer host
authorMike Bradeen <mbradeen@sangoma.com>
Thu, 8 May 2025 18:12:33 +0000 (12:12 -0600)
committerMike Bradeen <mbradeen@sangoma.com>
Tue, 13 May 2025 16:48:00 +0000 (16:48 +0000)
When a call is transfered via dialplan behind a NAT, the
host portion of the Contact header in the 302 will no longer
be over-written with the external NAT IP and will retain the
hostname.

Fixes: #1141
res/res_pjsip_nat.c

index b8d4ac4cd47cafe4e96fcc98128573fa9f5ff22e..699e5fb08be764092b1cdb437ec9d0c13ec31a77 100644 (file)
@@ -359,10 +359,13 @@ static pj_status_t process_nat(pjsip_tx_data *tdata)
                 * 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.
+                * own Contact. Nor do we do it for a 302 response to an INVITE request.
                 */
-               if (!cseq || tdata->msg->type == PJSIP_REQUEST_MSG ||
-                       pjsip_method_cmp(&cseq->method, &pjsip_register_method)) {
+               if ((!cseq || tdata->msg->type == PJSIP_REQUEST_MSG ||
+                       pjsip_method_cmp(&cseq->method, &pjsip_register_method)) &&
+                       (tdata->msg->type != PJSIP_RESPONSE_MSG ||
+                       pjsip_method_cmp(&cseq->method, &pjsip_invite_method) ||
+                       tdata->msg->line.status.code != PJSIP_SC_MOVED_TEMPORARILY )) {
                        /* We can only rewrite the URI when one is present */
                        if (uri || (uri = ast_sip_get_contact_sip_uri(tdata))) {
                                pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport_state->external_signaling_address));