提交 7510bccd authored 作者: Anthony Minessale's avatar Anthony Minessale

MILESTONE: working inbound calls

上级 cb076e6b
......@@ -220,9 +220,10 @@ SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp_t **rtp_session);
\return SWITCH_STATUS_SUCCESS
*/
SWITCH_DECLARE(switch_status_t) switch_rtp_activate_ice(switch_rtp_t *rtp_session, char *login, char *rlogin,
const char *password, switch_core_media_ice_type_t type, uint32_t priority);
const char *password, const char *rpassword, switch_core_media_ice_type_t type, uint32_t priority);
SWITCH_DECLARE(switch_status_t) switch_rtp_activate_rtcp_ice(switch_rtp_t *rtp_session, char *login, char *rlogin,
const char *password, switch_core_media_ice_type_t type, uint32_t priority);
const char *password, const char *rpassword,
switch_core_media_ice_type_t type, uint32_t priority);
/*!
\brief Activate sending RTCP Sender Reports (SR's)
......
......@@ -262,6 +262,7 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip,
\param end pointer to the end of the buffer
\return true or false depending on if there are any more attributes
*/
#define switch_stun_packet_next_attribute(attribute, end) (attribute && (attribute = (switch_stun_packet_attribute_t *) (attribute->value + switch_stun_attribute_padded_length(attribute))) && ((void *)attribute < end) && attribute->type && ((void *)(attribute + switch_stun_attribute_padded_length(attribute)) < end))
#define switch_stun_packet_next_attribute_hbo(attribute, end) (attribute && (attribute = (switch_stun_packet_attribute_t *) (attribute->value + switch_stun_attribute_padded_length_hbo(attribute))) && ((void *)attribute < end) && attribute->type && ((void *)(attribute + switch_stun_attribute_padded_length_hbo(attribute)) < end))
......
......@@ -817,13 +817,14 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
if (sofia_media_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
if (tech_pvt->nh) {
if (tech_pvt->mparams.local_sdp_str) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", switch_channel_get_name(channel),
tech_pvt->mparams.local_sdp_str);
}
}
}
if (sofia_test_flag(tech_pvt, TFLAG_NAT) ||
......
......@@ -1228,6 +1228,7 @@ SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload)
switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_FALSE);
switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_FALSE);
switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_FALSE);
switch_network_list_add_cidr(rfc_list, "169.254.0.0/16", SWITCH_FALSE);
switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
tmp_name = "nat.auto";
......
差异被折叠。
......@@ -55,7 +55,7 @@
#define WRITE_DEC(rtp_session) switch_mutex_unlock(rtp_session->write_mutex); rtp_session->writing--
#define RTP_DEFAULT_STUNCOUNT 100;
#define rtp_header_len 12
#define RTP_START_PORT 16384
#define RTP_END_PORT 32768
......@@ -164,6 +164,7 @@ typedef struct {
char *ice_user;
char *user_ice;
char *pass;
char *rpass;
uint32_t stuncount;
uint32_t funny_stun;
uint32_t default_stuncount;
......@@ -677,7 +678,7 @@ static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice)
switch_stun_packet_attribute_add_controlling(packet);
}
switch_stun_packet_attribute_add_integrity(packet, ice->pass);
switch_stun_packet_attribute_add_integrity(packet, ice->rpass);
switch_stun_packet_attribute_add_fingerprint(packet);
......@@ -715,6 +716,8 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
char username[33] = { 0 };
unsigned char buf[512] = { 0 };
switch_size_t cpylen = len;
int xlen = 0;
int ok = 1;
if (!switch_rtp_ready(rtp_session) || zstr(ice->user_ice) || zstr(ice->ice_user)) {
return;
......@@ -727,23 +730,19 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
goto end;
}
if (cpylen > 512) {
cpylen = 512;
if (cpylen > sizeof(buf)) {
cpylen = sizeof(buf);
}
memcpy(buf, data, cpylen);
packet = switch_stun_packet_parse(buf, sizeof(buf));
packet = switch_stun_packet_parse(buf, cpylen);
if (!packet) {
switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session");
//int sbytes = (int) cpylen;
//int stat;
//if ((stat = srtp_unprotect(rtp_session->recv_ctx, buf, &sbytes)) || !(packet = switch_stun_packet_parse(buf, sizeof(buf)))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid STUN/ICE packet received\n");
goto end;
//}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid STUN/ICE packet received\n");
goto end;
}
#if 0
......@@ -762,8 +761,6 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
switch_stun_packet_first_attribute(packet, attr);
do {
switch (attr->type) {
case SWITCH_STUN_ATTR_MAPPED_ADDRESS:
......@@ -778,27 +775,41 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
switch_stun_packet_attribute_get_username(attr, username, 32);
}
break;
case SWITCH_STUN_ATTR_PRIORITY:
{
uint32_t *val = (uint32_t *) attr->value;
ok = *val == ice->priority;
}
break;
}
if (!switch_stun_packet_next_attribute(attr, end_buf)) {
break;
}
} while (switch_stun_packet_next_attribute(attr, end_buf));
xlen += 4 + switch_stun_attribute_padded_length(attr);
} while (xlen <= packet->header.length);
if (ice->type == ICE_GOOGLE_JINGLE && ok) {
ok = !strcmp(ice->user_ice, username);
}
if ((packet->header.type == SWITCH_STUN_BINDING_REQUEST)) {
//if ((packet->header.type == SWITCH_STUN_BINDING_REQUEST) && !strcmp(ice->user_ice, username)) {
if ((packet->header.type == SWITCH_STUN_BINDING_REQUEST) && ok) {
uint8_t stunbuf[512];
switch_stun_packet_t *rpacket;
const char *remote_ip;
switch_size_t bytes;
char ipbuf[25];
//int rtcp = 0;
switch_sockaddr_t *from_addr = rtp_session->from_addr;
switch_socket_t *sock_output = rtp_session->sock_output;
if (ice == &rtp_session->rtcp_ice) {
//rtcp = 1;
from_addr = rtp_session->rtcp_from_addr;
sock_output = rtp_session->rtcp_sock_output;
}
printf("STUN REQ\n");
rtp_session->ice.ready = 1;
memset(stunbuf, 0, sizeof(stunbuf));
rpacket = switch_stun_packet_build_header(SWITCH_STUN_BINDING_RESPONSE, packet->header.id, stunbuf);
......@@ -811,11 +822,18 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
switch_stun_packet_attribute_add_binded_address(rpacket, (char *) remote_ip, switch_sockaddr_get_port(from_addr));
if ((ice->type & ICE_VANILLA)) {
//if (!(ice->type && ICE_CONTROLLED)) {
// switch_stun_packet_attribute_add_use_candidate(rpacket);
// switch_stun_packet_attribute_add_priority(rpacket, ice->priority);
//}
switch_stun_packet_attribute_add_integrity(rpacket, ice->pass);
switch_stun_packet_attribute_add_fingerprint(rpacket);
}
rtp_session->ice.ready = 1;
bytes = switch_stun_packet_length(rpacket);
switch_socket_sendto(sock_output, from_addr, 0, (void *) rpacket, &bytes);
......@@ -1074,7 +1092,7 @@ static uint8_t get_next_write_ts(switch_rtp_t *rtp_session, uint32_t timestamp)
static int check_srtp_and_ice(switch_rtp_t *rtp_session)
{
int ret = 0;
int rtcp_ok = 1;
if (rtp_session->flags[SWITCH_RTP_FLAG_AUTO_CNG] && rtp_session->send_msg.header.ts &&
......@@ -1094,7 +1112,11 @@ static int check_srtp_and_ice(switch_rtp_t *rtp_session)
}
}
if (rtp_session->rtcp_sock_output &&
if (rtp_session->rtcp_ice.ice_user && !rtp_session->rtcp_ice.ready) {
rtcp_ok = 0;
}
if (rtp_session->rtcp_sock_output && rtcp_ok &&
rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP] && !rtp_session->flags[SWITCH_RTP_FLAG_RTCP_PASSTHRU] &&
rtp_session->rtcp_interval && (rtp_session->stats.read_count % rtp_session->rtcp_interval) == 0) {
struct switch_rtcp_senderinfo *sr = (struct switch_rtcp_senderinfo*) rtp_session->rtcp_send_msg.body;
......@@ -2422,7 +2444,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_rtcp(switch_rtp_t *rtp_sessi
}
SWITCH_DECLARE(switch_status_t) switch_rtp_activate_ice(switch_rtp_t *rtp_session, char *login, char *rlogin,
const char *password, switch_core_media_ice_type_t type, uint32_t priority)
const char *password, const char *rpassword, switch_core_media_ice_type_t type, uint32_t priority)
{
char ice_user[80];
char user_ice[80];
......@@ -2439,12 +2461,18 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_ice(switch_rtp_t *rtp_sessio
rtp_session->ice.user_ice = switch_core_strdup(rtp_session->pool, user_ice);
rtp_session->ice.type = type;
rtp_session->ice.priority = priority;
rtp_session->ice.pass = "";
rtp_session->ice.rpass = "";
if (password) {
rtp_session->ice.pass = switch_core_strdup(rtp_session->pool, password);
}
if (rpassword) {
rtp_session->ice.rpass = switch_core_strdup(rtp_session->pool, rpassword);
}
rtp_session->ice.default_stuncount = 25;
rtp_session->ice.default_stuncount = RTP_DEFAULT_STUNCOUNT;
rtp_session->ice.stuncount = 0;
if (rtp_session->ice.ice_user) {
......@@ -2458,7 +2486,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_ice(switch_rtp_t *rtp_sessio
SWITCH_DECLARE(switch_status_t) switch_rtp_activate_rtcp_ice(switch_rtp_t *rtp_session, char *login, char *rlogin,
const char *password, switch_core_media_ice_type_t type, uint32_t priority)
const char *password, const char *rpassword, switch_core_media_ice_type_t type, uint32_t priority)
{
char ice_user[80];
char user_ice[80];
......@@ -2475,11 +2503,18 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_rtcp_ice(switch_rtp_t *rtp_s
rtp_session->rtcp_ice.user_ice = switch_core_strdup(rtp_session->pool, user_ice);
rtp_session->rtcp_ice.type = type;
rtp_session->rtcp_ice.priority = priority;
rtp_session->rtcp_ice.pass = "";
rtp_session->rtcp_ice.rpass = "";
if (password) {
rtp_session->rtcp_ice.pass = switch_core_strdup(rtp_session->pool, password);
}
rtp_session->rtcp_ice.default_stuncount = 25;
if (rpassword) {
rtp_session->rtcp_ice.rpass = switch_core_strdup(rtp_session->pool, rpassword);
}
rtp_session->rtcp_ice.default_stuncount = RTP_DEFAULT_STUNCOUNT;
rtp_session->rtcp_ice.stuncount = 0;
if (rtp_session->rtcp_ice.ice_user) {
......
......@@ -120,6 +120,7 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, ui
switch_stun_packet_attribute_t *attr;
uint32_t bytes_left = len;
void *end_buf = buf + len;
int xlen = 0;
if (len < SWITCH_STUN_PACKET_MIN_LEN) {
return NULL;
......@@ -128,7 +129,8 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, ui
packet = (switch_stun_packet_t *) buf;
packet->header.type = ntohs(packet->header.type);
packet->header.length = ntohs(packet->header.length);
bytes_left -= packet->header.length + 20;
bytes_left -= 20;
/*
* Check packet type (RFC3489(bis?) values)
......@@ -182,12 +184,13 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, ui
attr->type = ntohs(attr->type);
bytes_left -= 4; /* attribute header consumed */
if (!attr->length || switch_stun_attribute_padded_length(attr) > bytes_left) {
if (switch_stun_attribute_padded_length(attr) > bytes_left) {
/*
* Note we simply don't "break" here out of the loop anymore because
* we don't want the upper layers to have to deal with attributes without a value
* (or worse: invalid length)
*/
return NULL;
}
/*
......@@ -202,6 +205,12 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, ui
case SWITCH_STUN_ATTR_REFLECTED_FROM:
case SWITCH_STUN_ATTR_ALTERNATE_SERVER:
case SWITCH_STUN_ATTR_DESTINATION_ADDRESS:
case SWITCH_STUN_ATTR_PRIORITY:
{
uint32_t *u = (uint32_t *)attr->value;
*u = ntohl(*u);
}
break;
case SWITCH_STUN_ATTR_SOURCE_ADDRESS2:
{
switch_stun_ip_t *ip;
......@@ -279,16 +288,18 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, ui
break;
default:
/* Mandatory attribute range? => invalid */
//if (attr->type <= 0x7FFF) {
// return NULL;
//}
break;
}
bytes_left -= switch_stun_attribute_padded_length(attr); /* attribute value consumed, substract padded length */
} while (bytes_left >= SWITCH_STUN_ATTRIBUTE_MIN_LEN && switch_stun_packet_next_attribute(attr, end_buf));
bytes_left -= switch_stun_attribute_padded_length(attr); /* attribute value consumed, substract padded length */
xlen += 4 + switch_stun_attribute_padded_length(attr);
attr = (switch_stun_packet_attribute_t *) (attr->value + switch_stun_attribute_padded_length(attr));
if ((void *)attr > end_buf) {
break;
}
} while (xlen < packet->header.length);
if ((uint32_t) (packet->header.length + 20) > (uint32_t) (len - bytes_left)) {
/*
* the packet length is longer than the length of all attributes?
......@@ -296,10 +307,11 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, ui
*/
packet->header.length = (uint16_t) ((len - bytes_left) - 20);
}
return packet;
}
SWITCH_DECLARE(const char *) switch_stun_value_to_name(int32_t type, uint32_t value)
{
uint32_t x = 0;
......@@ -460,16 +472,13 @@ SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_xor_binded_address(swit
SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_priority(switch_stun_packet_t *packet, uint32_t priority)
{
switch_stun_packet_attribute_t *attribute;
uint32_t *lame;
priority = htonl(priority);
attribute = (switch_stun_packet_attribute_t *) ((uint8_t *) & packet->first_attribute + ntohs(packet->header.length));
attribute->type = htons(SWITCH_STUN_ATTR_PRIORITY);
attribute->length = htons(4);
memcpy(attribute->value, &priority, 4);
lame = (uint32_t *) attribute->value;
printf("FUCKER2 %u %u\n", *lame, priority);
packet->header.length += htons(sizeof(switch_stun_packet_attribute_t)) + attribute->length;
return 1;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论