res_rtp_asterisk: ICE server-reflexive candidates (srflx) with Dual-Stack.

Previously, Asterisk sent srflx only when configured exclusively for IPv4. Now,
srflx is gathered and sent via SDP, even when Asterisk is enabled for
Dual Stack (IPv4+IPv6) and an IPv4 interface is available/used.

ASTERISK-27437

Change-Id: Ie07d8e2bfa7b6fe06fcdc73d390a7a9a4d8c0bc1
This commit is contained in:
Alexander Traud
2017-11-21 13:39:34 +01:00
parent d2fb0ffb5b
commit 6ebe03d4b3

View File

@@ -2910,8 +2910,8 @@ static void rtp_add_candidates_to_ice(struct ast_rtp_instance *instance, struct
}
/* If configured to use a STUN server to get our external mapped address do so */
if (stunaddr.sin_addr.s_addr && count && ast_sockaddr_is_ipv4(addr)
&& !stun_address_is_blacklisted(addr)) {
if (count && stunaddr.sin_addr.s_addr && !stun_address_is_blacklisted(addr) &&
(ast_sockaddr_is_ipv4(addr) || ast_sockaddr_is_any(addr))) {
struct sockaddr_in answer;
int rsp;
@@ -2925,18 +2925,30 @@ static void rtp_add_candidates_to_ice(struct ast_rtp_instance *instance, struct
ao2_lock(instance);
if (!rsp) {
pj_sockaddr base;
/* Use the first local IPv4 host candidate as the base */
for (pos = basepos; pos < count; pos++) {
if (address[pos].addr.sa_family == PJ_AF_INET &&
!rtp_address_is_ice_blacklisted(&address[pos])) {
pj_sockaddr_cp(&base, &address[pos]);
break;
}
}
if (pos < count) {
pj_sockaddr ext;
pj_str_t mapped = pj_str(ast_strdupa(ast_inet_ntoa(answer.sin_addr)));
int srflx = 1;
/* Use the first local host candidate as the base */
pj_sockaddr_cp(&base, &address[basepos]);
pj_sockaddr_init(pj_AF_INET(), &ext, &mapped, ntohs(answer.sin_port));
/* If the returned address is the same as one of our host candidates, don't send the srflx */
/*
* If the returned address is the same as one of our host
* candidates, don't send the srflx
*/
for (pos = 0; pos < count; pos++) {
if ((pj_sockaddr_cmp(&address[pos], &ext) == 0) && !rtp_address_is_ice_blacklisted(&address[pos])) {
if (pj_sockaddr_cmp(&address[pos], &ext) == 0 &&
!rtp_address_is_ice_blacklisted(&address[pos])) {
srflx = 0;
break;
}
@@ -2949,6 +2961,7 @@ static void rtp_add_candidates_to_ice(struct ast_rtp_instance *instance, struct
}
}
}
}
/* If configured to use a TURN relay create a session and allocate */
if (pj_strlen(&turnaddr)) {