mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-23 20:51:58 +00:00
make crash protection a configure option --enable-crash-protection and make mini-rtp have 4 byte headers
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1368 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
+7
-1
@@ -176,7 +176,13 @@ int main(int argc, char *argv[])
|
||||
switch_event_fire(&event);
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "freeswitch Version %s Started\n\n", SWITCH_VERSION_FULL);
|
||||
#ifdef CRASH_PROT
|
||||
#define __CP "ENABLED"
|
||||
#else
|
||||
#define __CP "DISABLED"
|
||||
#endif
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "freeswitch Version %s Started. Crash Protection [%s]\n\n", SWITCH_VERSION_FULL, __CP);
|
||||
snprintf(path, sizeof(path), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, pfile);
|
||||
|
||||
if (bg) {
|
||||
|
||||
+11
-9
@@ -36,7 +36,6 @@
|
||||
|
||||
#define SWITCH_EVENT_QUEUE_LEN 256
|
||||
#define SWITCH_SQL_QUEUE_LEN 2000
|
||||
#define SWITCH_THREAD_JMP_KEY "JMP_KEY"
|
||||
|
||||
struct switch_core_session {
|
||||
uint32_t id;
|
||||
@@ -86,7 +85,9 @@ struct switch_core_runtime {
|
||||
uint32_t session_id;
|
||||
apr_pool_t *memory_pool;
|
||||
switch_hash_t *session_table;
|
||||
#ifdef CRASH_PROT
|
||||
switch_hash_t *stack_table;
|
||||
#endif
|
||||
switch_core_db_t *db;
|
||||
switch_core_db_t *event_db;
|
||||
const switch_state_handler_table_t *state_handlers[SWITCH_MAX_STATE_HANDLERS];
|
||||
@@ -1099,8 +1100,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
||||
break;
|
||||
default:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s decoder error!\n",
|
||||
|
||||
session->read_codec->codec_interface->interface_name);
|
||||
session->read_codec->codec_interface->interface_name);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@@ -1862,7 +1862,7 @@ SWITCH_DECLARE(unsigned int) switch_core_session_runing(switch_core_session_t *s
|
||||
{
|
||||
return session->thread_running;
|
||||
}
|
||||
|
||||
#ifdef CRASH_PROT
|
||||
#if defined (__GNUC__) && defined (LINUX)
|
||||
#include <execinfo.h>
|
||||
#include <stdio.h>
|
||||
@@ -1911,7 +1911,7 @@ static int handle_fatality(int sig)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
|
||||
{
|
||||
@@ -1919,6 +1919,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
|
||||
const switch_endpoint_interface_t *endpoint_interface;
|
||||
const switch_state_handler_table_t *driver_state_handler = NULL;
|
||||
const switch_state_handler_table_t *application_state_handler = NULL;
|
||||
#ifdef CRASH_PROT
|
||||
switch_thread_id_t thread_id = switch_thread_self();
|
||||
jmp_buf env;
|
||||
int sig;
|
||||
@@ -1941,7 +1942,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
|
||||
} else {
|
||||
apr_hash_set(runtime.stack_table, &thread_id, sizeof(thread_id), &env);
|
||||
}
|
||||
|
||||
#endif
|
||||
/*
|
||||
Life of the channel. you have channel and pool in your session
|
||||
everywhere you go you use the session to malloc with
|
||||
@@ -2250,9 +2251,9 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
|
||||
switch_thread_cond_wait(session->cond, session->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CRASH_PROT
|
||||
apr_hash_set(runtime.stack_table, &thread_id, sizeof(thread_id), NULL);
|
||||
|
||||
#endif
|
||||
session->thread_running = 0;
|
||||
}
|
||||
|
||||
@@ -2825,8 +2826,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(char *console)
|
||||
runtime.session_id = 1;
|
||||
|
||||
switch_core_hash_init(&runtime.session_table, runtime.memory_pool);
|
||||
#ifdef CRASH_PROT
|
||||
switch_core_hash_init(&runtime.stack_table, runtime.memory_pool);
|
||||
|
||||
#endif
|
||||
time(&runtime.initiated);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
+44
-36
@@ -46,6 +46,7 @@
|
||||
#define SWITCH_RTP_CNG_PAYLOAD 13
|
||||
#define MAX_KEY_LEN 64
|
||||
#define MASTER_KEY_LEN 30
|
||||
#define RTP_MAGIC_NUMBER 42
|
||||
|
||||
static switch_port_t NEXT_PORT = RTP_START_PORT;
|
||||
static switch_mutex_t *port_lock = NULL;
|
||||
@@ -53,26 +54,18 @@ static switch_mutex_t *port_lock = NULL;
|
||||
typedef srtp_hdr_t rtp_hdr_t;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(1)
|
||||
#pragma pack(4)
|
||||
#endif
|
||||
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
|
||||
typedef struct {
|
||||
unsigned version:2; /* protocol version */
|
||||
unsigned p:1; /* padding flag */
|
||||
unsigned x:1; /* header extension flag */
|
||||
unsigned cc:4; /* CSRC count */
|
||||
uint32_t ts; /* timestamp */
|
||||
uint32_t ts; /* timestamp */
|
||||
} PACKED srtp_mini_hdr_t;
|
||||
|
||||
#else
|
||||
typedef struct {
|
||||
uint8_t cc:4; /* CSRC count */
|
||||
uint8_t x:1; /* header extension flag */
|
||||
uint8_t p:1; /* padding flag */
|
||||
uint8_t version:2; /* protocol version */
|
||||
uint32_t ts; /* timestamp */
|
||||
uint32_t ts; /* timestamp */
|
||||
} PACKED srtp_mini_hdr_t;
|
||||
|
||||
#endif
|
||||
@@ -166,6 +159,7 @@ struct switch_rtp {
|
||||
char *user_ice;
|
||||
switch_time_t last_stun;
|
||||
uint32_t packet_size;
|
||||
uint32_t rpacket_size;
|
||||
switch_time_t last_read;
|
||||
switch_time_t next_read;
|
||||
uint32_t ms_per_packet;
|
||||
@@ -181,19 +175,28 @@ static int global_init = 0;
|
||||
|
||||
static void switch_rtp_miniframe_probe(switch_rtp_t *rtp_session)
|
||||
{
|
||||
rtp_mini_msg_t mini = {{0}};
|
||||
int x;
|
||||
const char *str = "!";
|
||||
rtp_msg_t msg = {{0}};
|
||||
int x;
|
||||
|
||||
msg.header.ssrc = htonl(RTP_MAGIC_NUMBER);
|
||||
msg.header.ts = htonl(rtp_session->packet_size);
|
||||
msg.header.seq = htons(RTP_MAGIC_NUMBER);
|
||||
msg.header.m = 1;
|
||||
msg.header.pt = RTP_MAGIC_NUMBER;
|
||||
msg.header.version = 2;
|
||||
msg.header.p = 0;
|
||||
msg.header.x = 0;
|
||||
msg.header.cc = 0;
|
||||
|
||||
mini.header.version = 1;
|
||||
mini.header.ts = 42;
|
||||
snprintf(mini.body, sizeof(mini.body), str);
|
||||
snprintf(msg.body, sizeof(msg.body), str);
|
||||
for(x = 0; x < 3 ; x++) {
|
||||
switch_size_t bytes = strlen(str) + sizeof(mini.header);
|
||||
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)&mini, &bytes);
|
||||
switch_size_t bytes = strlen(str) + sizeof(msg.header);
|
||||
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)&msg, &bytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static switch_status_t ice_out(switch_rtp_t *rtp_session)
|
||||
{
|
||||
|
||||
@@ -706,37 +709,42 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
|
||||
return -1;
|
||||
}
|
||||
bytes = sbytes;
|
||||
}
|
||||
}
|
||||
|
||||
if (bytes > 0 && rtp_session->recv_msg.header.version == 1) {
|
||||
uint32_t ts;
|
||||
rtp_mini_msg_t *mini = (rtp_mini_msg_t *) &rtp_session->recv_msg;
|
||||
|
||||
if (mini->header.ts == 42) {
|
||||
if (bytes > 0) {
|
||||
int effective_size = bytes - sizeof(srtp_mini_hdr_t);
|
||||
|
||||
if (rtp_session->recv_msg.header.pt == RTP_MAGIC_NUMBER) {
|
||||
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_MINI)) {
|
||||
switch_set_flag(rtp_session, SWITCH_RTP_FLAG_MINI);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "YAY MINI-RTP!\n");
|
||||
rtp_session->rpacket_size = ntohl(rtp_session->recv_msg.header.ts);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "YAY MINI-RTP! %d\n", rtp_session->rpacket_size);
|
||||
switch_rtp_miniframe_probe(rtp_session);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
ts = mini->header.ts;
|
||||
bytes -= sizeof(srtp_mini_hdr_t);
|
||||
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_MINI) && rtp_session->rpacket_size && effective_size > 0) {
|
||||
uint32_t mfactor = (effective_size % rtp_session->rpacket_size);
|
||||
|
||||
memmove(rtp_session->recv_msg.body, mini->body, bytes);
|
||||
if (!mfactor) {
|
||||
uint32_t ts;
|
||||
rtp_mini_msg_t *mini = (rtp_mini_msg_t *) &rtp_session->recv_msg;
|
||||
ts = mini->header.ts;
|
||||
bytes -= sizeof(srtp_mini_hdr_t);
|
||||
|
||||
rtp_session->recv_msg.header.ts = ts;
|
||||
rtp_session->recv_msg.header.seq = htons(rtp_session->rseq++);
|
||||
rtp_session->recv_msg.header.pt = rtp_session->rpayload;
|
||||
bytes += rtp_header_len;
|
||||
rtp_session->recv_msg.header.version = 2;
|
||||
memmove(rtp_session->recv_msg.body, mini->body, bytes);
|
||||
|
||||
rtp_session->recv_msg.header.ts = ts;
|
||||
rtp_session->recv_msg.header.seq = htons(rtp_session->rseq++);
|
||||
rtp_session->recv_msg.header.pt = rtp_session->rpayload;
|
||||
bytes += rtp_header_len;
|
||||
rtp_session->recv_msg.header.version = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) {
|
||||
if ((switch_time_now() - rtp_session->next_read) > 1000) {
|
||||
/* We're late! We're Late!*/
|
||||
@@ -846,6 +854,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
|
||||
if (bytes > 0) {
|
||||
do_2833(rtp_session);
|
||||
}
|
||||
|
||||
return (int) bytes;
|
||||
}
|
||||
|
||||
@@ -1171,7 +1180,6 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
|
||||
rtp_mini_msg_t mini = {{0}};
|
||||
bytes -= rtp_header_len;
|
||||
mini.header.ts = send_msg->header.ts;
|
||||
mini.header.version = 1;
|
||||
memcpy(mini.body, send_msg->body, bytes);
|
||||
bytes += sizeof(srtp_mini_hdr_t);
|
||||
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)&mini, &bytes);
|
||||
|
||||
Reference in New Issue
Block a user