Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 230380) +++ channels/chan_sip.c (working copy) @@ -9055,6 +9055,16 @@ } } +static void adjust_nat_flags(struct sip_pvt *p) +{ + if ((ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_RFC3581) + && ast_test_flag(&p->flags[1], SIP_PAGE2_RPORT_PRESENT) + && !ast_test_flag(&p->flags[0], SIP_NAT_ROUTE)) { + + ast_set_flag(&p->flags[0], SIP_NAT_ROUTE); + } +} + /*! \brief Verify registration of user - Registration is done in several steps, first a REGISTER without auth to get a challenge (nonce) then a second one with auth @@ -9126,6 +9136,8 @@ res = AUTH_PEER_NOT_DYNAMIC; } else { ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_NAT); + adjust_nat_flags(p); + transmit_response(p, "100 Trying", req); if (!(res = check_auth(p, req, peer->name, peer->secret, peer->md5secret, SIP_REGISTER, uri, XMIT_UNRELIABLE, ast_test_flag(req, SIP_PKT_IGNORE)))) { if (sip_cancel_destroy(p)) @@ -9887,6 +9899,7 @@ if (user && ast_apply_ha(user->ha, sin)) { ast_copy_flags(&p->flags[0], &user->flags[0], SIP_FLAGS_TO_COPY); ast_copy_flags(&p->flags[1], &user->flags[1], SIP_PAGE2_FLAGS_TO_COPY); + adjust_nat_flags(p); if (sipmethod == SIP_INVITE) { /* copy channel vars */ for (v = user->chanvars ; v ; v = v->next) { @@ -9920,6 +9933,7 @@ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); ast_copy_flags(&p->flags[0], &user->flags[0], SIP_FLAGS_TO_COPY); ast_copy_flags(&p->flags[1], &user->flags[1], SIP_PAGE2_FLAGS_TO_COPY); + adjust_nat_flags(p); /* Copy SIP extensions profile from INVITE */ if (p->sipoptions) user->sipoptions = p->sipoptions; @@ -10008,6 +10022,7 @@ /* Take the peer */ ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); + adjust_nat_flags(p); /* Copy SIP extensions profile to peer */ if (p->sipoptions) @@ -10041,6 +10056,7 @@ if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri2, reliable, ast_test_flag(req, SIP_PKT_IGNORE)))) { ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); + adjust_nat_flags(p); /* If we have a call limit, set flag */ if (peer->call_limit) ast_set_flag(&p->flags[0], SIP_CALL_LIMIT); @@ -16851,6 +16867,7 @@ p->recv = peer->addr; ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); + adjust_nat_flags(p); /* Send OPTIONs to peer's fullcontact */ if (!ast_strlen_zero(peer->fullcontact))