]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
we don't need the is_loopback logic in ctdb any more
authorAndrew Tridgell <tridge@samba.org>
Thu, 13 Sep 2007 00:45:06 +0000 (10:45 +1000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 13 Sep 2007 00:45:06 +0000 (10:45 +1000)
(This used to be ctdb commit 4ecf29ade0099c7180932288191de9840c8d90a9)

ctdb/common/system_aix.c
ctdb/common/system_linux.c
ctdb/include/ctdb_private.h
ctdb/server/ctdb_takeover.c

index 5d5af10336244808b1bbce3060e85c2d638ee96b..f296e17d8192f79a946303bf7b87044072238054 100644 (file)
@@ -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) {
index 82a6575bab333198a2fbe042cfd2bb1b73045757..6e42199e83a62d9dd60157779e6db8d7e8ec6808 100644 (file)
@@ -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; i<num_ifs;i++) {
-               struct sockaddr_in *sa;
-
-               /* we only care bout ipv4 addresses */
-               sa = (struct sockaddr_in *)&ifr[i].ifr_addr;
-               if (sa->sin_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;
 }
index 8c8e8b151a4dd4574bcd92e86f993a49e0b592e4..e2be8eda709e04be4ad346c771e7f16496031a86 100644 (file)
@@ -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,
index c0e11fef2d577c8f9898c2d14576685b7c7ed36d..796617adf25c64f853c8b6dac6556a9e4673bca7 100644 (file)
@@ -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);
 }