From: Kinsey Moore Date: Tue, 25 Sep 2012 19:34:01 +0000 (+0000) Subject: Fix an issue where media would not flow for situations where the legacy STUN code... X-Git-Tag: 10.10.0-rc1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbed3175d8be0ebcd199e5241f8d5de46239c384;p=thirdparty%2Fasterisk.git Fix an issue where media would not flow for situations where the legacy STUN code is in use. The STUN packets should *not* be blocked by strict RTP. (closes issue ASTERISK-20415) Reported by: Michele Cicciotti patches: uploaded by Joshua Colp (trunk r369817) ........ Merged revisions 373702 from http://svn.asterisk.org/svn/asterisk/branches/1.8 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10@373703 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c index 5bafae292a..7773fbcc34 100644 --- a/res/res_rtp_asterisk.c +++ b/res/res_rtp_asterisk.c @@ -2160,6 +2160,33 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc return &ast_null_frame; } + /* Get fields and verify this is an RTP packet */ + seqno = ntohl(rtpheader[0]); + + ast_rtp_instance_get_remote_address(instance, &remote_address); + + if (!(version = (seqno & 0xC0000000) >> 30)) { + struct sockaddr_in addr_tmp; + struct ast_sockaddr addr_v4; + if (ast_sockaddr_is_ipv4(&addr)) { + ast_sockaddr_to_sin(&addr, &addr_tmp); + } else if (ast_sockaddr_ipv4_mapped(&addr, &addr_v4)) { + ast_debug(1, "Using IPv6 mapped address %s for STUN\n", + ast_sockaddr_stringify(&addr)); + ast_sockaddr_to_sin(&addr_v4, &addr_tmp); + } else { + ast_debug(1, "Cannot do STUN for non IPv4 address %s\n", + ast_sockaddr_stringify(&addr)); + return &ast_null_frame; + } + if ((ast_stun_handle_packet(rtp->s, &addr_tmp, rtp->rawdata + AST_FRIENDLY_OFFSET, res, NULL, NULL) == AST_STUN_ACCEPT) && + ast_sockaddr_isnull(&remote_address)) { + ast_sockaddr_from_sin(&addr, &addr_tmp); + ast_rtp_instance_set_remote_address(instance, &addr); + } + return &ast_null_frame; + } + /* If strict RTP protection is enabled see if we need to learn the remote address or if we need to drop the packet */ if (rtp->strict_rtp_state == STRICT_RTP_LEARN) { ast_debug(1, "%p -- start learning mode pass with addr = %s\n", rtp, ast_sockaddr_stringify(&addr)); @@ -2193,33 +2220,6 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc } } - /* Get fields and verify this is an RTP packet */ - seqno = ntohl(rtpheader[0]); - - ast_rtp_instance_get_remote_address(instance, &remote_address); - - if (!(version = (seqno & 0xC0000000) >> 30)) { - struct sockaddr_in addr_tmp; - struct ast_sockaddr addr_v4; - if (ast_sockaddr_is_ipv4(&addr)) { - ast_sockaddr_to_sin(&addr, &addr_tmp); - } else if (ast_sockaddr_ipv4_mapped(&addr, &addr_v4)) { - ast_debug(1, "Using IPv6 mapped address %s for STUN\n", - ast_sockaddr_stringify(&addr)); - ast_sockaddr_to_sin(&addr_v4, &addr_tmp); - } else { - ast_debug(1, "Cannot do STUN for non IPv4 address %s\n", - ast_sockaddr_stringify(&addr)); - return &ast_null_frame; - } - if ((ast_stun_handle_packet(rtp->s, &addr_tmp, rtp->rawdata + AST_FRIENDLY_OFFSET, res, NULL, NULL) == AST_STUN_ACCEPT) && - ast_sockaddr_isnull(&remote_address)) { - ast_sockaddr_from_sin(&addr, &addr_tmp); - ast_rtp_instance_set_remote_address(instance, &addr); - } - return &ast_null_frame; - } - /* If symmetric RTP is enabled see if the remote side is not what we expected and change where we are sending audio */ if (ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT)) { if (ast_sockaddr_cmp(&remote_address, &addr)) {