FS-7602 add some of 3b2d00f3e6 from verto to sip and refactor some code to keep sip working like verto

This commit is contained in:
Anthony Minessale 2015-06-02 21:20:03 -05:00
parent 51c6a6f7b5
commit c9065a85b6
10 changed files with 66 additions and 25 deletions

View File

@ -332,6 +332,7 @@ SWITCH_DECLARE(switch_media_flow_t) switch_core_session_media_flow(switch_core_s
SWITCH_DECLARE(switch_status_t) switch_core_media_get_vid_params(switch_core_session_t *session, switch_vid_params_t *vid_params);
SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_session_t *session, switch_file_handle_t *fh, switch_rw_t rw);
SWITCH_DECLARE(switch_bool_t) switch_core_session_in_video_thread(switch_core_session_t *session);
SWITCH_DECLARE(switch_bool_t) switch_core_media_check_dtls(switch_core_session_t *session);
SWITCH_END_EXTERN_C
#endif

View File

@ -197,6 +197,8 @@ SWITCH_DECLARE(char *) switch_stun_host_lookup(const char *host, switch_memory_p
\return true or false
*/
SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, uint16_t *port);
SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_xor_mapped_address(switch_stun_packet_attribute_t *attribute, uint32_t cookie, char *ipstr, uint16_t *port);
/*!
\brief Extract a username from a packet attribute

View File

@ -2676,9 +2676,15 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t
stream->write_function(stream, "Dialplan \t%s\n", switch_str_nil(profile->dialplan));
stream->write_function(stream, "Context \t%s\n", switch_str_nil(profile->context));
stream->write_function(stream, "Challenge Realm \t%s\n", zstr(profile->challenge_realm) ? "auto_to" : profile->challenge_realm);
for (x = 0; x < profile->rtpip_index; x++) {
stream->write_function(stream, "RTP-IP \t%s\n", switch_str_nil(profile->rtpip[x]));
}
for (x = 0; x < profile->rtpip_index6; x++) {
stream->write_function(stream, "RTP-IP \t%s\n", switch_str_nil(profile->rtpip6[x]));
}
if (profile->extrtpip) {
stream->write_function(stream, "Ext-RTP-IP \t%s\n", profile->extrtpip);
}
@ -2980,6 +2986,9 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl
for (x = 0; x < profile->rtpip_index; x++) {
stream->write_function(stream, " <rtp-ip>%s</rtp-ip>\n", switch_str_nil(profile->rtpip[x]));
}
for (x = 0; x < profile->rtpip_index6; x++) {
stream->write_function(stream, " <rtp-ip>%s</rtp-ip>\n", switch_str_nil(profile->rtpip6[x]));
}
if (profile->extrtpip) {
stream->write_function(stream, " <ext-rtp-ip>%s</ext-rtp-ip>\n", profile->extrtpip);
}
@ -5467,7 +5476,7 @@ static void general_event_handler(switch_event_t *event)
}
if (!strcmp(profile->rtpip[x], old_ip6)) {
profile->rtpip[x] = switch_core_strdup(profile->pool, new_ip6);
profile->rtpip6[x] = switch_core_strdup(profile->pool, new_ip6);
rb++;
}
}

View File

@ -575,11 +575,14 @@ struct sofia_profile {
char *shutdown_type;
char *extrtpip;
char *rtpip[MAX_RTPIP];
char *rtpip6[MAX_RTPIP];
char *jb_msec;
switch_payload_t te;
switch_payload_t recv_te;
uint32_t rtpip_index;
uint32_t rtpip_next;
uint32_t rtpip_index6;
uint32_t rtpip_next6;
char *rtcp_audio_interval_msec;
char *rtcp_video_interval_msec;

View File

@ -4219,6 +4219,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
profile->ob_failed_calls = 0;
profile->shutdown_type = "false";
profile->rtpip_index = 0;
profile->rtpip_index6 = 0;
if (xprofiledomain) {
profile->domain_name = switch_core_strdup(profile->pool, xprofiledomain);
@ -4717,10 +4718,19 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
} else {
ip = strcasecmp(val, "auto") ? val : mod_sofia_globals.guess_ip;
}
if (profile->rtpip_index < MAX_RTPIP) {
profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, ip);
if (strchr(ip, ':')) {
if (profile->rtpip_index < MAX_RTPIP) {
profile->rtpip6[profile->rtpip_index6++] = switch_core_strdup(profile->pool, ip);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Max IPs configured for profile %s.\n", profile->name);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Max IPs configured for profile %s.\n", profile->name);
if (profile->rtpip_index6 < MAX_RTPIP) {
profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, ip);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Max IPs configured for profile %s.\n", profile->name);
}
}
} else if (!strcasecmp(var, "sip-ip")) {
char *ip = mod_sofia_globals.guess_ip;
@ -5455,7 +5465,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
profile->sipip = switch_core_strdup(profile->pool, mod_sofia_globals.guess_ip);
}
if (!profile->rtpip[0]) {
if (!profile->rtpip[0] && !profile->rtpip6[0]) {
profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, mod_sofia_globals.guess_ip);
}
@ -5488,7 +5498,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
profile->sdp_username = switch_core_strdup(profile->pool, "FreeSWITCH");
}
if (!profile->rtpip[0]) {
if (!profile->rtpip[0] && !profile->rtpip6[0]) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Setting ip to '127.0.0.1'\n");
profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, "127.0.0.1");
}

View File

@ -92,9 +92,25 @@ void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t *
tech_pvt->profile = profile;
tech_pvt->mparams.rtpip = switch_core_session_strdup(session, profile->rtpip[profile->rtpip_next++]);
if (profile->rtpip_next >= profile->rtpip_index) {
profile->rtpip_next = 0;
if (!zstr(profile->rtpip[profile->rtpip_next])) {
tech_pvt->mparams.rtpip4 = switch_core_session_strdup(session, profile->rtpip[profile->rtpip_next++]);
tech_pvt->mparams.rtpip = tech_pvt->mparams.rtpip4;
if (profile->rtpip_next >= profile->rtpip_index) {
profile->rtpip_next = 0;
}
}
if (!zstr(profile->rtpip[profile->rtpip_next6])) {
tech_pvt->mparams.rtpip6 = switch_core_session_strdup(session, profile->rtpip[profile->rtpip_next6++]);
if (zstr(tech_pvt->mparams.rtpip)) {
tech_pvt->mparams.rtpip = tech_pvt->mparams.rtpip6;
}
if (profile->rtpip_next6 >= profile->rtpip_index6) {
profile->rtpip_next6 = 0;
}
}
profile->inuse++;

View File

@ -216,8 +216,6 @@ struct switch_media_handle_s {
};
static switch_bool_t check_dtls(switch_core_session_t *session);
static switch_srtp_crypto_suite_t SUITES[CRYPTO_INVALID] = {
{ "AEAD_AES_256_GCM_8", AEAD_AES_256_GCM_8, 44},
{ "AEAD_AES_128_GCM_8", AEAD_AES_128_GCM_8, 28},
@ -6589,13 +6587,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi
end:
switch_channel_clear_flag(session->channel, CF_REINVITE);
switch_core_recovery_track(session);
return status;
}
@ -8649,7 +8644,7 @@ static int check_engine(switch_rtp_engine_t *engine)
return 1;
}
static switch_bool_t check_dtls(switch_core_session_t *session)
SWITCH_DECLARE(switch_bool_t) switch_core_media_check_dtls(switch_core_session_t *session)
{
switch_media_handle_t *smh;
switch_rtp_engine_t *a_engine, *v_engine;
@ -8661,7 +8656,7 @@ static switch_bool_t check_dtls(switch_core_session_t *session)
return SWITCH_FALSE;
}
if (switch_channel_down(session->channel)) {
if (!switch_channel_media_up(session->channel)) {
return SWITCH_FALSE;
}
@ -8715,14 +8710,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_receive_message(switch_core_se
}
break;
case SWITCH_MESSAGE_INDICATE_ANSWER:
case SWITCH_MESSAGE_INDICATE_PROGRESS:
case SWITCH_MESSAGE_ANSWER_EVENT:
case SWITCH_MESSAGE_PROGRESS_EVENT:
{
check_dtls(session);
}
break;
case SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ:
{
if (v_engine->rtp_session) {

View File

@ -486,6 +486,10 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
}
}
}
if (state > CS_INIT && switch_channel_media_up(session->channel)) {
switch_core_media_check_dtls(session);
}
switch (state) {
case CS_NEW: /* Just created, Waiting for first instructions */

View File

@ -887,7 +887,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "STUN PACKET TYPE: %s\n",
switch_stun_value_to_name(SWITCH_STUN_TYPE_PACKET_TYPE, packet->header.type));
do {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|---: STUN ATTR %s\n",
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|---: STUN ATTR %d %x %s\n", attr->type, attr->type,
switch_stun_value_to_name(SWITCH_STUN_TYPE_ATTRIBUTE, attr->type));
switch (attr->type) {
@ -928,6 +928,14 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|------: %s:%d\n", ip, port);
}
break;
case SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS:
if (attr->type) {
char ip[16];
uint16_t port;
switch_stun_packet_attribute_get_xor_mapped_address(attr, packet->header.cookie, ip, &port);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|------: %s:%d\n", ip, port);
}
break;
case SWITCH_STUN_ATTR_USERNAME:
if (attr->type) {
switch_stun_packet_attribute_get_username(attr, username, sizeof(username));

View File

@ -60,6 +60,7 @@ static const struct value_mapping PACKET_TYPES[] = {
static const struct value_mapping ATTR_TYPES[] = {
{SWITCH_STUN_ATTR_MAPPED_ADDRESS, "MAPPED_ADDRESS"},
{SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS, "XOR_MAPPED_ADDRESS"},
{SWITCH_STUN_ATTR_RESPONSE_ADDRESS, "RESPONSE_ADDRESS"},
{SWITCH_STUN_ATTR_CHANGE_REQUEST, "CHANGE_REQUEST"},
{SWITCH_STUN_ATTR_SOURCE_ADDRESS, "SOURCE_ADDRESS"},