diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c index 6fe4c719f00..b4275b1fc64 100644 --- a/ctdb/common/system_socket.c +++ b/ctdb/common/system_socket.c @@ -160,10 +160,7 @@ bool ctdb_sys_local_ip_check(const struct ctdb_sys_local_ips_context *ips_ctx, return false; } -/* - * See if the given IP is currently on an interface - */ -bool ctdb_sys_have_ip(const ctdb_sock_addr *_addr) +bool ctdb_sys_bind_ip_check(const ctdb_sock_addr *_addr) { int s; int ret; @@ -193,6 +190,28 @@ bool ctdb_sys_have_ip(const ctdb_sock_addr *_addr) return ret == 0; } +/* + * See if the given IP is currently on an interface + */ +bool ctdb_sys_have_ip(const ctdb_sock_addr *addr) +{ + struct ctdb_sys_local_ips_context *ips_ctx = NULL; + bool have_ip; + int ret; + + ret = ctdb_sys_local_ips_init(NULL, &ips_ctx); + if (ret != 0) { + DBG_DEBUG("Failed to get local addresses, depending on bind\n"); + have_ip = ctdb_sys_bind_ip_check(addr); + return have_ip; + } + + have_ip = ctdb_sys_local_ip_check(ips_ctx, addr); + talloc_free(ips_ctx); + + return have_ip; +} + /* * simple TCP checksum - assumes data is multiple of 2 bytes long */ diff --git a/ctdb/common/system_socket.h b/ctdb/common/system_socket.h index 3edc9e146e4..f4d092cce0a 100644 --- a/ctdb/common/system_socket.h +++ b/ctdb/common/system_socket.h @@ -30,6 +30,7 @@ int ctdb_sys_local_ips_init(TALLOC_CTX *ctx, struct ctdb_sys_local_ips_context **ips_ctx); bool ctdb_sys_local_ip_check(const struct ctdb_sys_local_ips_context *ips_ctx, const ctdb_sock_addr *addr); +bool ctdb_sys_bind_ip_check(const ctdb_sock_addr *addr); bool ctdb_sys_have_ip(const ctdb_sock_addr *addr); int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);