forked from Mirrors/freeswitch
make switch_cmp_addr ipv6 friendly and cleanup/refactor autoadjust code in rtp
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15289 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
a7a909df2a
commit
10f10c5db0
@ -1935,6 +1935,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
|
||||
}
|
||||
}
|
||||
|
||||
/* ignore packets not meant for us unless the auto-adjust window is open */
|
||||
if (bytes && !switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) &&
|
||||
(!switch_cmp_addr(rtp_session->from_addr, rtp_session->remote_addr) ||
|
||||
((rtp_session->cng_pt && rtp_session->recv_msg.header.pt == rtp_session->cng_pt) || rtp_session->recv_msg.header.pt == 13))) {
|
||||
@ -1943,19 +1944,18 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
|
||||
|
||||
}
|
||||
|
||||
if (bytes &&
|
||||
switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) {
|
||||
const char *tx_host;
|
||||
const char *old_host;
|
||||
char bufa[30], bufb[30];
|
||||
|
||||
tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr);
|
||||
old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
|
||||
if ((switch_sockaddr_get_port(rtp_session->from_addr) != rtp_session->remote_port) || strcmp(tx_host, old_host)) {
|
||||
const char *err;
|
||||
uint32_t old = rtp_session->remote_port;
|
||||
|
||||
if (++rtp_session->autoadj_tally >= 10 && !zstr(tx_host) && switch_sockaddr_get_port(rtp_session->from_addr) > 0) {
|
||||
if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) {
|
||||
if (!switch_cmp_addr(rtp_session->from_addr, rtp_session->remote_addr)) {
|
||||
if (++rtp_session->autoadj_tally >= 10) {
|
||||
const char *err;
|
||||
uint32_t old = rtp_session->remote_port;
|
||||
const char *tx_host;
|
||||
const char *old_host;
|
||||
char bufa[30], bufb[30];
|
||||
|
||||
tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr);
|
||||
old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
|
||||
"Auto Changing port from %s:%u to %s:%u\n", old_host, old, tx_host,
|
||||
switch_sockaddr_get_port(rtp_session->from_addr));
|
||||
|
@ -1348,10 +1348,36 @@ SWITCH_DECLARE(int) get_addr_int(switch_sockaddr_t *sa)
|
||||
|
||||
SWITCH_DECLARE(int) switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2)
|
||||
{
|
||||
struct sockaddr_in *s1 = (struct sockaddr_in *)&sa1->sa;
|
||||
struct sockaddr_in *s2 = (struct sockaddr_in *)&sa2->sa;
|
||||
struct sockaddr_in *s1;
|
||||
struct sockaddr_in *s2;
|
||||
|
||||
return (ntohs((unsigned short)s1->sin_addr.s_addr) == ntohs((unsigned short)s2->sin_addr.s_addr) && ntohs(s1->sin_port) == ntohs(s2->sin_port));
|
||||
struct sockaddr_in6 *s16;
|
||||
struct sockaddr_in6 *s26;
|
||||
|
||||
struct sockaddr *ss1;
|
||||
struct sockaddr *ss2;
|
||||
|
||||
if (!(sa1 && sa2)) return 0;
|
||||
|
||||
s1 = (struct sockaddr_in *)&sa1->sa;
|
||||
s2 = (struct sockaddr_in *)&sa2->sa;
|
||||
|
||||
s16 = (struct sockaddr_in6 *)&sa1->sa;
|
||||
s26 = (struct sockaddr_in6 *)&sa2->sa;
|
||||
|
||||
ss1 = (struct sockaddr *)&sa1->sa;
|
||||
ss2 = (struct sockaddr *)&sa2->sa;
|
||||
|
||||
if (ss1->sa_family != ss2->sa_family) return 0;
|
||||
|
||||
switch (ss1->sa_family) {
|
||||
case AF_INET:
|
||||
return (s1->sin_addr.s_addr == s2->sin_addr.s_addr && s1->sin_port == s2->sin_port);
|
||||
case AF_INET6:
|
||||
return (s16->sin6_addr.s6_addr == s26->sin6_addr.s6_addr && s16->sin6_port == s26->sin6_port);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user