From: Mike Bradeen Date: Thu, 8 May 2025 18:12:33 +0000 (-0600) Subject: res_pjsip_nat.c: Do not overwrite transfer host X-Git-Tag: 21.10.0-rc1~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a6ba4937dea3d25426e31a6c9af4b339f42111d;p=thirdparty%2Fasterisk.git res_pjsip_nat.c: Do not overwrite transfer host 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 (cherry picked from commit 0a249440015af0725849af5b2fd82b951e007ee4) --- diff --git a/res/res_pjsip_nat.c b/res/res_pjsip_nat.c index b8d4ac4cd4..699e5fb08b 100644 --- a/res/res_pjsip_nat.c +++ b/res/res_pjsip_nat.c @@ -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));