diff options
author | Seppo Jaakola <seppo.jaakola@codership.com> | 2013-11-26 16:48:30 +0200 |
---|---|---|
committer | Seppo Jaakola <seppo.jaakola@codership.com> | 2013-11-26 16:48:30 +0200 |
commit | a2594e96f7c7fe762a8165916551ae96bcbb869f (patch) | |
tree | fa1e4eb2a6d6ef1ca8a039a2afe48a65bca6ab33 /sql/wsrep_utils.cc | |
parent | 2b4183f10b54a5b3f8c848d897b3107859c23fa4 (diff) | |
download | mariadb-git-a2594e96f7c7fe762a8165916551ae96bcbb869f.tar.gz |
Merges from lp:codership-mysql/5.5 up to rev #3893, this changes to wsrep API #24
Diffstat (limited to 'sql/wsrep_utils.cc')
-rw-r--r-- | sql/wsrep_utils.cc | 85 |
1 files changed, 66 insertions, 19 deletions
diff --git a/sql/wsrep_utils.cc b/sql/wsrep_utils.cc index 37e537c62e4..b01bdaaa15e 100644 --- a/sql/wsrep_utils.cc +++ b/sql/wsrep_utils.cc @@ -22,16 +22,17 @@ #include "wsrep_utils.h" #include "wsrep_mysqld.h" -//#include "wsrep_api.h" -//#include "wsrep_priv.h" + +#include <sql_class.h> + #include <spawn.h> // posix_spawn() #include <unistd.h> // pipe() #include <errno.h> // errno #include <string.h> // strerror() #include <sys/wait.h> // waitpid() - -#include <sql_class.h> -#include "wsrep_priv.h" +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> // getaddrinfo() extern char** environ; // environment variables @@ -317,23 +318,69 @@ thd::~thd () } // namespace wsp -extern ulong my_bind_addr; -extern uint mysqld_port; +/* Returns INADDR_NONE, INADDR_ANY, INADDR_LOOPBACK or something else */ +unsigned int wsrep_check_ip (const char* const addr) +{ + unsigned int ret = INADDR_NONE; + struct addrinfo *res, hints; + + memset (&hints, 0, sizeof(hints)); + hints.ai_flags= AI_PASSIVE/*|AI_ADDRCONFIG*/; + hints.ai_socktype= SOCK_STREAM; + hints.ai_family= AF_UNSPEC; -size_t guess_ip (char* buf, size_t buf_len) + int gai_ret = getaddrinfo(addr, NULL, &hints, &res); + if (0 == gai_ret) + { + if (AF_INET == res->ai_family) /* IPv4 */ + { + struct sockaddr_in* a= (struct sockaddr_in*)res->ai_addr; + ret= htonl(a->sin_addr.s_addr); + } + else /* IPv6 */ + { + struct sockaddr_in6* a= (struct sockaddr_in6*)res->ai_addr; + if (IN6_IS_ADDR_UNSPECIFIED(&a->sin6_addr)) + ret= INADDR_ANY; + else if (IN6_IS_ADDR_LOOPBACK(&a->sin6_addr)) + ret= INADDR_LOOPBACK; + else + ret= 0xdeadbeef; + } + freeaddrinfo (res); + } + else { + WSREP_ERROR ("getaddrinfo() failed on '%s': %d (%s)", + addr, gai_ret, gai_strerror(gai_ret)); + } + + // uint8_t* b= (uint8_t*)&ret; + // fprintf (stderr, "########## wsrep_check_ip returning: %hhu.%hhu.%hhu.%hhu\n", + // b[0], b[1], b[2], b[3]); + + return ret; +} + +extern const char* my_bind_addr_str; +extern uint mysqld_port; + +size_t wsrep_guess_ip (char* buf, size_t buf_len) { size_t ip_len = 0; - if (htonl(INADDR_NONE) == my_bind_addr) { - WSREP_ERROR("Networking not configured, cannot receive state transfer."); - return 0; - } + if (my_bind_addr_str && strlen(my_bind_addr_str)) + { + unsigned int const ip_type= wsrep_check_ip(my_bind_addr_str); - if (htonl(INADDR_ANY) != my_bind_addr) { - uint8_t* b = (uint8_t*)&my_bind_addr; - ip_len = snprintf (buf, buf_len, - "%hhu.%hhu.%hhu.%hhu", b[0],b[1],b[2],b[3]); - return ip_len; + if (INADDR_NONE == ip_type) { + WSREP_ERROR("Networking not configured, cannot receive state transfer."); + return 0; + } + + if (INADDR_ANY != ip_type) {; + strncpy (buf, my_bind_addr_str, buf_len); + return strlen(buf); + } } // mysqld binds to all interfaces - try IP from wsrep_node_address @@ -404,9 +451,9 @@ size_t guess_ip (char* buf, size_t buf_len) return ip_len; } -size_t guess_address(char* buf, size_t buf_len) +size_t wsrep_guess_address(char* buf, size_t buf_len) { - size_t addr_len = guess_ip (buf, buf_len); + size_t addr_len = wsrep_guess_ip (buf, buf_len); if (addr_len && addr_len < buf_len) { addr_len += snprintf (buf + addr_len, buf_len - addr_len, |