FS-526: improve nat handling when using stun or host as ext-rtp-ip

This commit is contained in:
Brian West 2010-09-30 10:08:20 -05:00
parent 23f71563fb
commit 03e74c51f9

View File

@ -872,32 +872,30 @@ switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt, int forc
sdp_port = tech_pvt->local_sdp_audio_port; sdp_port = tech_pvt->local_sdp_audio_port;
if (!(use_ip = switch_channel_get_variable(tech_pvt->channel, "rtp_adv_audio_ip")) /* Check if NAT is detected */
&& !zstr(tech_pvt->profile->extrtpip)) { if (!zstr(tech_pvt->remote_ip) && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
use_ip = tech_pvt->profile->extrtpip; /* Yes, map the port through switch_nat */
} switch_nat_add_mapping(tech_pvt->local_sdp_audio_port, SWITCH_NAT_UDP, &sdp_port, SWITCH_FALSE);
switch_nat_add_mapping(tech_pvt->local_sdp_audio_port + 1, SWITCH_NAT_UDP, &rtcp_port, SWITCH_FALSE);
if (use_ip) { /* Find an IP address to use */
if (sofia_glue_ext_address_lookup(tech_pvt->profile, tech_pvt, &lookup_rtpip, &sdp_port, if (!(use_ip = switch_channel_get_variable(tech_pvt->channel, "rtp_adv_audio_ip"))
use_ip, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { && !zstr(tech_pvt->profile->extrtpip)) {
/* Address lookup was required and fail (external ip was "host:..." or "stun:...") */ use_ip = tech_pvt->profile->extrtpip;
return SWITCH_STATUS_FALSE; }
} else {
if (lookup_rtpip == use_ip) { if (use_ip) {
/* sofia_glue_ext_address_lookup didn't return any error, but the return IP is the same as the original one, if (sofia_glue_ext_address_lookup(tech_pvt->profile, tech_pvt, &lookup_rtpip, &sdp_port,
which means no lookup was necessary. Check if NAT is detected */ use_ip, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
if (!zstr(tech_pvt->remote_ip) && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { /* Address lookup was required and fail (external ip was "host:..." or "stun:...") */
/* Yes, map the port through switch_nat */ return SWITCH_STATUS_FALSE;
switch_nat_add_mapping(tech_pvt->local_sdp_audio_port, SWITCH_NAT_UDP, &sdp_port, SWITCH_FALSE);
switch_nat_add_mapping(tech_pvt->local_sdp_audio_port + 1, SWITCH_NAT_UDP, &rtcp_port, SWITCH_FALSE);
} else {
/* No NAT detected */
use_ip = tech_pvt->rtpip;
}
} else { } else {
/* Address properly resolved, use it as external ip */ /* Address properly resolved, use it as external ip */
use_ip = lookup_rtpip; use_ip = lookup_rtpip;
} }
} else {
/* No external ip found, use the profile's rtp ip */
use_ip = tech_pvt->rtpip;
} }
} else { } else {
/* No NAT traversal required, use the profile's rtp ip */ /* No NAT traversal required, use the profile's rtp ip */
@ -941,31 +939,29 @@ switch_status_t sofia_glue_tech_choose_video_port(private_object_t *tech_pvt, in
sdp_port = tech_pvt->local_sdp_video_port; sdp_port = tech_pvt->local_sdp_video_port;
if (!(use_ip = switch_channel_get_variable(tech_pvt->channel, "rtp_adv_video_ip")) /* Check if NAT is detected */
&& !zstr(tech_pvt->profile->extrtpip)) { if (!zstr(tech_pvt->remote_ip) && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
use_ip = tech_pvt->profile->extrtpip; /* Yes, map the port through switch_nat */
} switch_nat_add_mapping(tech_pvt->local_sdp_video_port, SWITCH_NAT_UDP, &sdp_port, SWITCH_FALSE);
if (use_ip) { /* Find an IP address to use */
if (sofia_glue_ext_address_lookup(tech_pvt->profile, tech_pvt, &lookup_rtpip, &sdp_port, if (!(use_ip = switch_channel_get_variable(tech_pvt->channel, "rtp_adv_video_ip"))
use_ip, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { && !zstr(tech_pvt->profile->extrtpip)) {
/* Address lookup was required and fail (external ip was "host:..." or "stun:...") */ use_ip = tech_pvt->profile->extrtpip;
return SWITCH_STATUS_FALSE; }
} else {
if (lookup_rtpip == use_ip) { if (use_ip) {
/* sofia_glue_ext_address_lookup didn't return any error, but the return IP is the same as the original one, if (sofia_glue_ext_address_lookup(tech_pvt->profile, tech_pvt, &lookup_rtpip, &sdp_port,
which means no lookup was necessary. Check if NAT is detected */ use_ip, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
if (!zstr(tech_pvt->remote_ip) && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { /* Address lookup was required and fail (external ip was "host:..." or "stun:...") */
/* Yes, map the port through switch_nat */ return SWITCH_STATUS_FALSE;
switch_nat_add_mapping(tech_pvt->local_sdp_video_port, SWITCH_NAT_UDP, &sdp_port, SWITCH_FALSE);
} else {
/* No NAT detected */
use_ip = tech_pvt->rtpip;
}
} else { } else {
/* Address properly resolved, use it as external ip */ /* Address properly resolved, use it as external ip */
use_ip = lookup_rtpip; use_ip = lookup_rtpip;
} }
} else {
/* No external ip found, use the profile's rtp ip */
use_ip = tech_pvt->rtpip;
} }
} else { } else {
/* No NAT traversal required, use the profile's rtp ip */ /* No NAT traversal required, use the profile's rtp ip */