From: Andrew Tridgell Date: Thu, 13 Sep 2007 00:45:06 +0000 (+1000) Subject: we don't need the is_loopback logic in ctdb any more X-Git-Tag: tevent-0.9.20~348^2~2415 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3c0f61cb9279c5116e38a066be8db56d20bdf7db;p=thirdparty%2Fsamba.git we don't need the is_loopback logic in ctdb any more (This used to be ctdb commit 4ecf29ade0099c7180932288191de9840c8d90a9) --- diff --git a/ctdb/common/system_aix.c b/ctdb/common/system_aix.c index 5d5af103362..f296e17d819 100644 --- a/ctdb/common/system_aix.c +++ b/ctdb/common/system_aix.c @@ -165,15 +165,11 @@ int ctdb_sys_send_tcp(int s, we try to bind to it, and if that fails then we don't have that IP on an interface */ -bool ctdb_sys_have_ip(struct sockaddr_in ip, bool *is_loopback, TALLOC_CTX *mem_ctx, char **ifname) +bool ctdb_sys_have_ip(struct sockaddr_in ip) { int s; int ret; - if (is_loopback) { - DEBUG(0,(__location__ " NOT IMPLEMENTED YET: ctdb_sys_have_ip() does not yet support is_loopback on AIX. This needs to be implemented similar to system_linux.c\n")); - } - ip.sin_port = 0; s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == -1) { diff --git a/ctdb/common/system_linux.c b/ctdb/common/system_linux.c index 82a6575bab3..6e42199e83a 100644 --- a/ctdb/common/system_linux.c +++ b/ctdb/common/system_linux.c @@ -241,100 +241,20 @@ int ctdb_sys_send_tcp(int s, we try to bind to it, and if that fails then we don't have that IP on an interface - if is_loopback is specified it will also return whether the ip address - is attached to the loopback interface or not ifname, if non-NULL, will return the name of the interface this ip is tied to */ -bool ctdb_sys_have_ip(struct sockaddr_in ip, bool *is_loopback, TALLOC_CTX *mem_ctx, char **ifname) +bool ctdb_sys_have_ip(struct sockaddr_in ip) { - struct ifreq *ifr = NULL; - struct ifconf ifc; - int s, i, num_ifs; + int s; int ret; - if (is_loopback) { - *is_loopback = false; - } - if (*ifname) { - *ifname = NULL; - } - ip.sin_port = 0; s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == -1) { return false; } ret = bind(s, (struct sockaddr *)&ip, sizeof(ip)); - if (ret) { - goto finished; - } - - - /* find out how much space we need to store the interface details */ - ifc.ifc_len = 0; - ifc.ifc_req = NULL; - ret = ioctl(s, SIOCGIFCONF, &ifc); - if (ret) { - DEBUG(0,(__location__ " ioctl to read interface list failed\n")); - goto finished; - } - - ifr = talloc_size(mem_ctx, ifc.ifc_len); - - /* get a list of all interface names and addresses */ - ifc.ifc_req = ifr; - ret = ioctl(s, SIOCGIFCONF, &ifc); - if (ret) { - DEBUG(0,(__location__ " ioctl to read interface list failed\n")); - goto finished; - } - - /* loop over all interfaces and search for the one matching ip */ - num_ifs = ifc.ifc_len/sizeof(struct ifreq); - for (i=0; isin_family != AF_INET) { - continue; - } - - /* this is not the interface you are looking for */ - if (!ctdb_same_ip(sa, &ip)) { - continue; - } - - /* this is the ifr entry for this interface/address - read the interface flags so we can tell if it is - loopback or not - */ - ret = ioctl(s, SIOCGIFFLAGS, &ifr[i]); - if (ret) { - DEBUG(0,(__location__ " failed to read interface flags for interface %s\n", ifr[i].ifr_name)); - goto finished; - } - - /* was this ip tied to a loopback interface ? */ - if (ifr[i].ifr_flags & IFF_LOOPBACK) { - if (is_loopback != NULL) { - *is_loopback = true; - } - } - - if (ifname) { - *ifname = talloc_asprintf(mem_ctx, "%s", ifr[i].ifr_name); - } - - /* if we got this far, we have found our interface so we can - exit the loop. - */ - break; - } - -finished: - talloc_free(ifr); close(s); return ret == 0; } diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 8c8e8b151a4..e2be8eda709 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -1062,7 +1062,7 @@ int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb, /* from takeover/system.c */ int ctdb_sys_send_arp(const struct sockaddr_in *saddr, const char *iface); -bool ctdb_sys_have_ip(struct sockaddr_in ip, bool *is_loopback, TALLOC_CTX *mem_ctx, char **ifname); +bool ctdb_sys_have_ip(struct sockaddr_in ip); int ctdb_sys_send_tcp(int fd, const struct sockaddr_in *dest, const struct sockaddr_in *src, diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index c0e11fef2d5..796617adf25 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -205,29 +205,22 @@ int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb, TDB_DATA indata, bool *async_reply) { - TALLOC_CTX *tmp_ctx = talloc_new(ctdb); int ret; struct takeover_callback_state *state; struct ctdb_public_ip *pip = (struct ctdb_public_ip *)indata.dptr; struct ctdb_vnn *vnn; - bool have_ip, is_loopback; - char *ifname = NULL; /* update out vnn list */ vnn = find_public_ip_vnn(ctdb, pip->sin); if (vnn == NULL) { DEBUG(0,("takeoverip called for an ip '%s' that is not a public address\n", inet_ntoa(pip->sin.sin_addr))); - talloc_free(tmp_ctx); return 0; } vnn->pnn = pip->pnn; /* if our kernel already has this IP, do nothing */ - have_ip = ctdb_sys_have_ip(pip->sin, &is_loopback, tmp_ctx, &ifname); - /* if we have the ip and it is not set to a loopback address */ - if (have_ip && !is_loopback) { - talloc_free(tmp_ctx); + if (ctdb_sys_have_ip(pip->sin)) { return 0; } @@ -257,7 +250,6 @@ int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb, if (ret != 0) { DEBUG(0,(__location__ " Failed to takeover IP %s on interface %s\n", inet_ntoa(pip->sin.sin_addr), vnn->iface)); - talloc_free(tmp_ctx); talloc_free(state); return -1; } @@ -265,7 +257,6 @@ int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb, /* tell ctdb_control.c that we will be replying asynchronously */ *async_reply = true; - talloc_free(tmp_ctx); return 0; } @@ -334,20 +325,16 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb, TDB_DATA indata, bool *async_reply) { - TALLOC_CTX *tmp_ctx = talloc_new(ctdb); int ret; struct takeover_callback_state *state; struct ctdb_public_ip *pip = (struct ctdb_public_ip *)indata.dptr; struct ctdb_vnn *vnn; - bool have_ip, is_loopback; - char *ifname = NULL; /* update our vnn list */ vnn = find_public_ip_vnn(ctdb, pip->sin); if (vnn == NULL) { DEBUG(0,("releaseip called for an ip '%s' that is not a public address\n", inet_ntoa(pip->sin.sin_addr))); - talloc_free(tmp_ctx); return 0; } vnn->pnn = pip->pnn; @@ -356,12 +343,10 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb, talloc_free(vnn->takeover_ctx); vnn->takeover_ctx = NULL; - have_ip = ctdb_sys_have_ip(pip->sin, &is_loopback, tmp_ctx, &ifname); - if ( (!have_ip) || is_loopback) { - DEBUG(0,("Redundant release of IP %s/%u on interface %s (ip not held)\n", + if (!ctdb_sys_have_ip(pip->sin)) { + DEBUG(2,("Redundant release of IP %s/%u on interface %s (ip not held)\n", inet_ntoa(pip->sin.sin_addr), vnn->public_netmask_bits, vnn->iface)); - talloc_free(tmp_ctx); return 0; } @@ -391,15 +376,12 @@ int32_t ctdb_control_release_ip(struct ctdb_context *ctdb, if (ret != 0) { DEBUG(0,(__location__ " Failed to release IP %s on interface %s\n", inet_ntoa(pip->sin.sin_addr), vnn->iface)); - talloc_free(tmp_ctx); talloc_free(state); return -1; } /* tell the control that we will be reply asynchronously */ *async_reply = true; - - talloc_free(tmp_ctx); return 0; } @@ -1147,21 +1129,17 @@ void ctdb_takeover_client_destructor_hook(struct ctdb_client *client) void ctdb_release_all_ips(struct ctdb_context *ctdb) { struct ctdb_vnn *vnn; - TALLOC_CTX *tmp_ctx = talloc_new(ctdb); - bool have_ip, is_loopback; - char *ifname = NULL; for (vnn=ctdb->vnn;vnn;vnn=vnn->next) { - have_ip = ctdb_sys_have_ip(vnn->public_address, &is_loopback, tmp_ctx, &ifname); - if (have_ip && !is_loopback) { - ctdb_event_script(ctdb, "releaseip %s %s %u", - vnn->iface, - inet_ntoa(vnn->public_address.sin_addr), - vnn->public_netmask_bits); - release_kill_clients(ctdb, vnn->public_address); + if (!ctdb_sys_have_ip(vnn->public_address)) { + continue; } + ctdb_event_script(ctdb, "releaseip %s %s %u", + vnn->iface, + inet_ntoa(vnn->public_address.sin_addr), + vnn->public_netmask_bits); + release_kill_clients(ctdb, vnn->public_address); } - talloc_free(tmp_ctx); }