Skip to content

Commit

Permalink
Changes in wsrep_guess_ip()
Browse files Browse the repository at this point in the history
* Changed loopback detection to be done via ifa->ifa_flags
* Removed unused function wsrep_guess_address()
  • Loading branch information
Nirbhay Choubey committed Feb 27, 2015
1 parent af651c8 commit 8ee5668
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
2 changes: 0 additions & 2 deletions mysql-test/suite/galera/suite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ return "No my_print_defaults" unless $epath;

push @::global_suppressions,
(
qr(WSREP: Failed to guess base node address),
qr(WSREP: Guessing address for incoming client connections failed),
qr(WSREP: wsrep_sst_receive_address is set to '127.0.0.1),
qr(WSREP: Could not open saved state file for reading: ),
qr(WSREP: Gap in state sequence. Need state transfer.),
Expand Down
2 changes: 0 additions & 2 deletions mysql-test/suite/wsrep/suite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ return "No my_print_defaults" unless $epath;

push @::global_suppressions,
(
qr(WSREP: Failed to guess base node address),
qr(WSREP: Guessing address for incoming client connections failed),
qr(WSREP: Could not open saved state file for reading: ),
qr(WSREP: option --wsrep-casual-reads is deprecated),
qr(WSREP: --wsrep-casual-reads=ON takes precedence over --wsrep-sync-wait=0),
Expand Down
29 changes: 13 additions & 16 deletions sql/wsrep_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
#include <netdb.h> // getaddrinfo()

#ifdef HAVE_GETIFADDRS
#include <net/if.h>
#include <ifaddrs.h>
#endif
#endif /* HAVE_GETIFADDRS */

extern char** environ; // environment variables

Expand Down Expand Up @@ -406,6 +407,13 @@ size_t wsrep_guess_ip (char* buf, size_t buf_len)
return ip_len;
}

/*
getifaddrs() is avaiable at least on Linux since glib 2.3, FreeBSD,
MAC OSX, OpenSolaris, Solaris.
On platforms which do not support getifaddrs() this function returns
a failure and user is prompted to do manual configuration.
*/
#if HAVE_GETIFADDRS
struct ifaddrs *ifaddr, *ifa;
if (getifaddrs(&ifaddr) == 0)
Expand All @@ -415,34 +423,23 @@ size_t wsrep_guess_ip (char* buf, size_t buf_len)
if (!ifa->ifa_addr || ifa->ifa_addr->sa_family != AF_INET) // TODO AF_INET6
continue;

if (vio_getnameinfo(ifa->ifa_addr, buf, buf_len, NULL, 0, NI_NUMERICHOST))
// Skip loopback interfaces (like lo:127.0.0.1)
if (ifa->ifa_flags & IFF_LOOPBACK)
continue;

if (strcmp(buf, "127.0.0.1") == 0) // lame
if (vio_getnameinfo(ifa->ifa_addr, buf, buf_len, NULL, 0, NI_NUMERICHOST))
continue;

freeifaddrs(ifaddr);
return strlen(buf);
}
freeifaddrs(ifaddr);
}
#endif
#endif /* HAVE_GETIFADDRS */

return 0;
}

size_t wsrep_guess_address(char* buf, size_t 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,
":%u", mysqld_port);
}

return addr_len;
}

/*
* WSREPXid
*/
Expand Down
1 change: 0 additions & 1 deletion sql/wsrep_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

unsigned int wsrep_check_ip (const char* addr);
size_t wsrep_guess_ip (char* buf, size_t buf_len);
size_t wsrep_guess_address(char* buf, size_t buf_len);

namespace wsp {
class node_status
Expand Down

0 comments on commit 8ee5668

Please sign in to comment.