1
0
mirror of https://github.com/signalwire/freeswitch.git synced 2025-04-23 03:33:48 +00:00

add apr func to disable loopback on multicast to simplify mod_multicast_event

This commit is contained in:
Anthony Minessale 2010-04-02 16:40:24 -05:00
parent ec99de7e8b
commit 6314075859
3 changed files with 22 additions and 21 deletions
src
include
mod/event_handlers/mod_event_multicast
switch_apr.c

@ -1213,6 +1213,7 @@ SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t *sock, switch_
*/ */
SWITCH_DECLARE(switch_status_t) switch_mcast_hops(switch_socket_t *sock, uint8_t ttl); SWITCH_DECLARE(switch_status_t) switch_mcast_hops(switch_socket_t *sock, uint8_t ttl);
SWITCH_DECLARE(switch_status_t) switch_mcast_loopback(switch_socket_t *sock, uint8_t opt);
/** @} */ /** @} */

@ -52,7 +52,6 @@ static struct {
char *bindings; char *bindings;
uint32_t key_count; uint32_t key_count;
char hostname[80]; char hostname[80];
uint64_t host_hash;
switch_port_t port; switch_port_t port;
switch_sockaddr_t *addr; switch_sockaddr_t *addr;
switch_socket_t *udp_socket; switch_socket_t *udp_socket;
@ -295,36 +294,35 @@ static void event_handler(switch_event_t *event)
switch_uuid_get(&uuid); switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid); switch_uuid_format(uuid_str, &uuid);
len = strlen(packet) + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH + EVP_MAX_IV_LENGTH + strlen((char *) MAGIC); len = strlen(packet) + SWITCH_UUID_FORMATTED_LENGTH + EVP_MAX_IV_LENGTH + strlen((char *) MAGIC);
#else #else
len = strlen(packet) + sizeof(globals.host_hash) + strlen((char *) MAGIC); len = strlen(packet) + strlen((char *) MAGIC);
#endif #endif
buf = malloc(len + 1); buf = malloc(len + 1);
memset(buf, 0, len + 1); memset(buf, 0, len + 1);
switch_assert(buf); switch_assert(buf);
memcpy(buf, &globals.host_hash, sizeof(globals.host_hash));
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
if (globals.psk) { if (globals.psk) {
switch_copy_string(buf + sizeof(globals.host_hash), uuid_str, SWITCH_UUID_FORMATTED_LENGTH); switch_copy_string(buf, uuid_str, SWITCH_UUID_FORMATTED_LENGTH);
EVP_CIPHER_CTX_init(&ctx); EVP_CIPHER_CTX_init(&ctx);
EVP_EncryptInit(&ctx, EVP_bf_cbc(), NULL, NULL); EVP_EncryptInit(&ctx, EVP_bf_cbc(), NULL, NULL);
EVP_CIPHER_CTX_set_key_length(&ctx, strlen(globals.psk)); EVP_CIPHER_CTX_set_key_length(&ctx, strlen(globals.psk));
EVP_EncryptInit(&ctx, NULL, (unsigned char *) globals.psk, (unsigned char *) uuid_str); EVP_EncryptInit(&ctx, NULL, (unsigned char *) globals.psk, (unsigned char *) uuid_str);
EVP_EncryptUpdate(&ctx, (unsigned char *) buf + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH, EVP_EncryptUpdate(&ctx, (unsigned char *) buf + SWITCH_UUID_FORMATTED_LENGTH,
&outlen, (unsigned char *) packet, (int) strlen(packet)); &outlen, (unsigned char *) packet, (int) strlen(packet));
EVP_EncryptUpdate(&ctx, (unsigned char *) buf + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH + outlen, EVP_EncryptUpdate(&ctx, (unsigned char *) buf + SWITCH_UUID_FORMATTED_LENGTH + outlen,
&tmplen, (unsigned char *) MAGIC, (int) strlen((char *) MAGIC)); &tmplen, (unsigned char *) MAGIC, (int) strlen((char *) MAGIC));
outlen += tmplen; outlen += tmplen;
EVP_EncryptFinal(&ctx, (unsigned char *) buf + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH + outlen, &tmplen); EVP_EncryptFinal(&ctx, (unsigned char *) buf + SWITCH_UUID_FORMATTED_LENGTH + outlen, &tmplen);
outlen += tmplen; outlen += tmplen;
len = (size_t) outlen + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH; len = (size_t) outlen + SWITCH_UUID_FORMATTED_LENGTH;
*(buf + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH + outlen) = '\0'; *(buf + SWITCH_UUID_FORMATTED_LENGTH + outlen) = '\0';
} else { } else {
#endif #endif
switch_copy_string(buf + sizeof(globals.host_hash), packet, len - sizeof(globals.host_hash)); switch_copy_string(buf, packet, len);
switch_copy_string(buf + sizeof(globals.host_hash) + strlen(packet), (char *) MAGIC, strlen((char *) MAGIC) + 1); switch_copy_string(buf + strlen(packet), (char *) MAGIC, strlen((char *) MAGIC) + 1);
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
} }
#endif #endif
@ -369,7 +367,6 @@ SWITCH_STANDARD_API(multicast_peers)
SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load) SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load)
{ {
switch_api_interface_t *api_interface; switch_api_interface_t *api_interface;
switch_ssize_t hlen = -1;
switch_status_t status = SWITCH_STATUS_GENERR; switch_status_t status = SWITCH_STATUS_GENERR;
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
@ -381,7 +378,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load)
switch_core_hash_init(&globals.peer_hash, module_pool); switch_core_hash_init(&globals.peer_hash, module_pool);
gethostname(globals.hostname, sizeof(globals.hostname)); gethostname(globals.hostname, sizeof(globals.hostname));
globals.host_hash = switch_hashfunc_default(globals.hostname, &hlen);
globals.key_count = 0; globals.key_count = 0;
if (load_config() != SWITCH_STATUS_SUCCESS) { if (load_config() != SWITCH_STATUS_SUCCESS) {
@ -414,6 +410,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load)
switch_goto_status(SWITCH_STATUS_TERM, fail); switch_goto_status(SWITCH_STATUS_TERM, fail);
} }
if (switch_mcast_loopback(globals.udp_socket, 0) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to disable loopback\n");
switch_goto_status(SWITCH_STATUS_TERM, fail);
}
if (switch_socket_bind(globals.udp_socket, globals.addr) != SWITCH_STATUS_SUCCESS) { if (switch_socket_bind(globals.udp_socket, globals.addr) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bind Error\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bind Error\n");
switch_goto_status(SWITCH_STATUS_TERM, fail); switch_goto_status(SWITCH_STATUS_TERM, fail);
@ -501,7 +502,6 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime)
char *myaddr; char *myaddr;
size_t len = MULTICAST_BUFFSIZE; size_t len = MULTICAST_BUFFSIZE;
char *packet; char *packet;
uint64_t host_hash = 0;
switch_status_t status; switch_status_t status;
memset(buf, 0, len); memset(buf, 0, len);
@ -520,12 +520,8 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime)
} }
#endif #endif
memcpy(&host_hash, buf, sizeof(host_hash)); packet = buf;
packet = buf + sizeof(host_hash);
if (host_hash == globals.host_hash) {
continue;
}
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
if (globals.psk) { if (globals.psk) {
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
@ -533,7 +529,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime)
int outl, tmplen; int outl, tmplen;
EVP_CIPHER_CTX ctx; EVP_CIPHER_CTX ctx;
len -= sizeof(host_hash) + SWITCH_UUID_FORMATTED_LENGTH; len -= SWITCH_UUID_FORMATTED_LENGTH;
tmp = malloc(len); tmp = malloc(len);

@ -768,6 +768,10 @@ SWITCH_DECLARE(switch_status_t) switch_mcast_hops(switch_socket_t *sock, uint8_t
return apr_mcast_hops(sock, ttl); return apr_mcast_hops(sock, ttl);
} }
SWITCH_DECLARE(switch_status_t) switch_mcast_loopback(switch_socket_t *sock, uint8_t opt)
{
return apr_mcast_loopback(sock, opt);
}
/* socket functions */ /* socket functions */