From 808978ec76f9457ef6ef49a6fef42dac069d8507 Mon Sep 17 00:00:00 2001 From: Sergey Safarov Date: Fri, 7 Oct 2016 02:15:41 -0400 Subject: [PATCH 1/2] FS-9594: Has been adjusted string vars size to fit IPv6 address --- src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c | 2 +- src/mod/event_handlers/mod_kazoo/mod_kazoo.c | 6 +++--- src/mod/event_handlers/mod_kazoo/mod_kazoo.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c b/src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c index cf43ce1f45..06874cd48d 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c @@ -154,7 +154,7 @@ static void *SWITCH_THREAD_FUNC event_stream_loop(switch_thread_t *thread, void ei_event_binding_t *event_binding; switch_sockaddr_t *sa; uint16_t port; - char ipbuf[25]; + char ipbuf[48]; const char *ip_addr; void *pop; short event_stream_framing = globals.event_stream_framing; diff --git a/src/mod/event_handlers/mod_kazoo/mod_kazoo.c b/src/mod/event_handlers/mod_kazoo/mod_kazoo.c index dd305fe911..174559405e 100644 --- a/src/mod/event_handlers/mod_kazoo/mod_kazoo.c +++ b/src/mod/event_handlers/mod_kazoo/mod_kazoo.c @@ -50,7 +50,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_kazoo_var_prefix, globals.kazoo_var_p static switch_status_t api_erlang_status(switch_stream_handle_t *stream) { switch_sockaddr_t *sa; uint16_t port; - char ipbuf[25]; + char ipbuf[48]; const char *ip_addr; ei_node_t *ei_node; @@ -177,7 +177,7 @@ static switch_status_t handle_node_api_event_stream(ei_event_stream_t *event_str if (event_stream->connected == SWITCH_FALSE) { switch_sockaddr_t *sa; uint16_t port; - char ipbuf[25] = {0}; + char ipbuf[48] = {0}; const char *ip_addr; switch_socket_addr_get(&sa, SWITCH_TRUE, event_stream->acceptor); @@ -511,7 +511,7 @@ static switch_status_t config(void) { static switch_status_t create_acceptor() { switch_sockaddr_t *sa; uint16_t port; - char ipbuf[25]; + char ipbuf[48]; const char *ip_addr; /* if the config has specified an erlang release compatibility then pass that along to the erlang interface */ diff --git a/src/mod/event_handlers/mod_kazoo/mod_kazoo.h b/src/mod/event_handlers/mod_kazoo/mod_kazoo.h index 5200255bbd..a1e105ccc9 100644 --- a/src/mod/event_handlers/mod_kazoo/mod_kazoo.h +++ b/src/mod/event_handlers/mod_kazoo/mod_kazoo.h @@ -75,9 +75,9 @@ struct ei_node_s { char *peer_nodename; switch_time_t created_time; switch_socket_t *socket; - char remote_ip[25]; + char remote_ip[48]; uint16_t remote_port; - char local_ip[25]; + char local_ip[48]; uint16_t local_port; uint32_t flags; struct ei_node_s *next; From adb8c8000f616b3b16d83e71c224be022a6defc3 Mon Sep 17 00:00:00 2001 From: Sergey Safarov Date: Fri, 7 Oct 2016 05:38:35 -0400 Subject: [PATCH 2/2] FS-9594: Fixed hostname resolving for IPv6 addreses. aa --- src/mod/event_handlers/mod_kazoo/kazoo_utils.c | 13 ++++++------- src/mod/event_handlers/mod_kazoo/mod_kazoo.h | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_utils.c b/src/mod/event_handlers/mod_kazoo/kazoo_utils.c index 962e87f6f1..5f6e4bf78c 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_utils.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_utils.c @@ -157,6 +157,8 @@ switch_socket_t *create_socket_with_port(switch_memory_pool_t *pool, switch_port return NULL; } + switch_getnameinfo(&globals.hostname, sa, 0); + // if (globals.nat_map && switch_nat_get_type()) { // switch_nat_add_mapping(port, SWITCH_NAT_TCP, NULL, SWITCH_FALSE); // } @@ -170,7 +172,6 @@ switch_socket_t *create_socket(switch_memory_pool_t *pool) { } switch_status_t create_ei_cnode(const char *ip_addr, const char *name, struct ei_cnode_s *ei_cnode) { - struct hostent *nodehost; char hostname[EI_MAXHOSTNAMELEN + 1] = ""; char nodename[MAXNODELEN + 1]; char cnodename[EI_MAXALIVELEN + 1]; @@ -186,12 +187,10 @@ switch_status_t create_ei_cnode(const char *ip_addr, const char *name, struct ei /* truncate the alivename at the @ */ *atsign = '\0'; } else { - if ((nodehost = gethostbyaddr(ip_addr, sizeof (ip_addr), AF_INET))) { - memcpy(hostname, nodehost->h_name, EI_MAXHOSTNAMELEN); - } - - if (zstr_buf(hostname) || !strncasecmp(globals.ip, "0.0.0.0", 7)) { - gethostname(hostname, EI_MAXHOSTNAMELEN); + if (zstr(globals.hostname) || !strncasecmp(globals.ip, "0.0.0.0", 7) || !strncasecmp(globals.ip, "::", 2)) { + memcpy(hostname, switch_core_get_hostname(), EI_MAXHOSTNAMELEN); + } else { + memcpy(hostname, globals.hostname, EI_MAXHOSTNAMELEN); } snprintf(nodename, MAXNODELEN + 1, "%s@%s", globals.ei_nodename, hostname); diff --git a/src/mod/event_handlers/mod_kazoo/mod_kazoo.h b/src/mod/event_handlers/mod_kazoo/mod_kazoo.h index a1e105ccc9..e2a23134ba 100644 --- a/src/mod/event_handlers/mod_kazoo/mod_kazoo.h +++ b/src/mod/event_handlers/mod_kazoo/mod_kazoo.h @@ -103,6 +103,7 @@ struct globals_s { switch_bool_t ei_shortname; int ei_compat_rel; char *ip; + char *hostname; char *ei_cookie; char *ei_nodename; char *kazoo_var_prefix;