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 0a24944001)
This commit is contained in:
Mike Bradeen
2025-05-08 12:12:33 -06:00
committed by George Joseph
parent 99402536cb
commit 2a6ba4937d

View 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 * 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 * 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 * 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 || if ((!cseq || tdata->msg->type == PJSIP_REQUEST_MSG ||
pjsip_method_cmp(&cseq->method, &pjsip_register_method)) { 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 */ /* We can only rewrite the URI when one is present */
if (uri || (uri = ast_sip_get_contact_sip_uri(tdata))) { 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)); pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport_state->external_signaling_address));