summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/wsrep_mysqld.cc22
-rw-r--r--sql/wsrep_sst.cc37
-rw-r--r--sql/wsrep_utils.cc15
-rw-r--r--sql/wsrep_utils.h3
4 files changed, 33 insertions, 44 deletions
diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc
index cf8ac25aa6a..ad6b8eedf3e 100644
--- a/sql/wsrep_mysqld.cc
+++ b/sql/wsrep_mysqld.cc
@@ -571,27 +571,17 @@ int wsrep_init()
size_t const node_addr_len= strlen(node_addr);
if (node_addr_len > 0)
{
- const char* const colon= strrchr(node_addr, ':');
- if (strchr(node_addr, ':') == colon) // 1 or 0 ':'
+ size_t const ip_len= wsrep_host_len(node_addr, node_addr_len);
+ if (ip_len + 7 /* :55555\0 */ < inc_addr_max)
{
- size_t const ip_len= colon ? colon - node_addr : node_addr_len;
- if (ip_len + 7 /* :55555\0 */ < inc_addr_max)
- {
- memcpy (inc_addr, node_addr, ip_len);
- snprintf(inc_addr + ip_len, inc_addr_max - ip_len, ":%u",
- (int)mysqld_port);
- }
- else
- {
- WSREP_WARN("Guessing address for incoming client connections: "
- "address too long.");
- inc_addr[0]= '\0';
- }
+ memcpy (inc_addr, node_addr, ip_len);
+ snprintf(inc_addr + ip_len, inc_addr_max - ip_len, ":%u",
+ (int)mysqld_port);
}
else
{
WSREP_WARN("Guessing address for incoming client connections: "
- "too many colons :) .");
+ "address too long.");
inc_addr[0]= '\0';
}
}
diff --git a/sql/wsrep_sst.cc b/sql/wsrep_sst.cc
index 11698089582..331185e2cf3 100644
--- a/sql/wsrep_sst.cc
+++ b/sql/wsrep_sst.cc
@@ -634,18 +634,19 @@ ssize_t wsrep_sst_prepare (void** msg)
// Figure out SST address. Common for all SST methods
if (wsrep_sst_receive_address &&
- strcmp (wsrep_sst_receive_address, WSREP_SST_ADDRESS_AUTO))
+ strcmp (wsrep_sst_receive_address, WSREP_SST_ADDRESS_AUTO))
{
addr_in= wsrep_sst_receive_address;
}
else if (wsrep_node_address && strlen(wsrep_node_address))
{
- const char* const colon= strchr (wsrep_node_address, ':');
- if (colon)
+ size_t const addr_len= strlen(wsrep_node_address);
+ size_t const host_len= wsrep_host_len(wsrep_node_address, addr_len);
+
+ if (host_len < addr_len)
{
- ptrdiff_t const len= colon - wsrep_node_address;
- strncpy (ip_buf, wsrep_node_address, len);
- ip_buf[len]= '\0';
+ strncpy (ip_buf, wsrep_node_address, host_len);
+ ip_buf[host_len]= '\0';
addr_in= ip_buf;
}
else
@@ -772,25 +773,6 @@ static int sst_donate_mysqldump (const char* addr,
bool bypass,
char** env) // carries auth info
{
- size_t host_len;
- const char* port = strchr (addr, ':');
-
- if (port)
- {
- port += 1;
- host_len = port - addr;
- }
- else
- {
- port = "";
- host_len = strlen (addr) + 1;
- }
-
- char *host= (char *) alloca(host_len);
-
- strncpy (host, addr, host_len - 1);
- host[host_len - 1] = '\0';
-
int const cmd_len= 4096;
wsp::string cmd_str(cmd_len);
@@ -805,14 +787,13 @@ static int sst_donate_mysqldump (const char* addr,
int ret= snprintf (cmd_str(), cmd_len,
"wsrep_sst_mysqldump "
- WSREP_SST_OPT_HOST" '%s' "
- WSREP_SST_OPT_PORT" '%s' "
+ WSREP_SST_OPT_ADDR" '%s' "
WSREP_SST_OPT_LPORT" '%u' "
WSREP_SST_OPT_SOCKET" '%s' "
WSREP_SST_OPT_CONF" '%s' "
WSREP_SST_OPT_GTID" '%s:%lld'"
"%s",
- host, port, mysqld_port, mysqld_unix_port,
+ addr, mysqld_port, mysqld_unix_port,
wsrep_defaults_file, uuid_str,
(long long)seqno, bypass ? " " WSREP_SST_OPT_BYPASS : "");
diff --git a/sql/wsrep_utils.cc b/sql/wsrep_utils.cc
index 719e8e6b473..9c5cef6a997 100644
--- a/sql/wsrep_utils.cc
+++ b/sql/wsrep_utils.cc
@@ -554,3 +554,18 @@ size_t wsrep_guess_ip (char* buf, size_t buf_len)
return 0;
}
+
+/* returns the length of the host part of the address string */
+size_t wsrep_host_len(const char* const addr, size_t const addr_len)
+{
+ // check for IPv6 notation first
+ const char* const bracket= ('[' == addr[0] ? strchr(addr, ']') : NULL);
+
+ if (bracket) { // IPv6
+ return (bracket - addr + 1);
+ }
+ else { // host part ends at ':' or end of string
+ const char* const colon= strchr(addr, ':');
+ return (colon ? colon - addr : addr_len);
+ }
+}
diff --git a/sql/wsrep_utils.h b/sql/wsrep_utils.h
index 7d864603c7f..0ae5c68df21 100644
--- a/sql/wsrep_utils.h
+++ b/sql/wsrep_utils.h
@@ -21,6 +21,9 @@
unsigned int wsrep_check_ip (const char* addr);
size_t wsrep_guess_ip (char* buf, size_t buf_len);
+/* returns the length of the host part of the address string */
+size_t wsrep_host_len(const char* addr, size_t addr_len);
+
namespace wsp {
class node_status
{