Check interfaces: when reading the public addresses file to create the vnn list
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 6 Sep 2011 06:11:00 +0000 (16:11 +1000)
committerMichael Adam <obnox@samba.org>
Fri, 6 Jun 2014 13:00:34 +0000 (15:00 +0200)
check that the actual interface exist, print error and fail startup if the interface does not exist.
(cherry picked from commit cd33bbe6454b7b0316bdfffbd06c67b29779e873)

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

index 5fe54130d423595d34523c71a120a4a20d850093..1404a8290138ef3736a4e7d90c5e32024cd3352a 100644 (file)
@@ -357,4 +357,8 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
 }
 
 
+bool ctdb_sys_check_iface_exists(const char *iface)
+{
+       return true;
+}
 
index 9aa4620bd82c5e7dee61621d5f51514f60a32e47..9a0600b15f02214013f3aeb268f7afd7ea81f646 100644 (file)
@@ -70,3 +70,5 @@ bool ctdb_sys_have_ip(ctdb_sock_addr *_addr)
        close(s);
        return ret == 0;
 }
+
+
index b36a78d4fa89a216c1c915706772ebc68c05398b..102a3480379925e5eecf487f6def14594143c8aa 100644 (file)
@@ -538,3 +538,25 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data,
 }
 
 
+bool ctdb_sys_check_iface_exists(const char *iface)
+{
+       int s;
+       struct ifreq ifr;
+
+       s = socket(PF_PACKET, SOCK_RAW, 0);
+       if (s == -1){
+               /* We dont know if the interface exists, so assume yes */
+               DEBUG(DEBUG_CRIT,(__location__ " failed to open raw socket\n"));
+               return true;
+       }
+
+       strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
+       if (ioctl(s, SIOCGIFINDEX, &ifr) < 0 && errno == ENODEV) {
+               DEBUG(DEBUG_CRIT,(__location__ " interface '%s' not found\n", iface));
+               close(s);
+               return false;
+       }
+       close(s);
+       
+       return true;
+}
index 355f3612d9245fb09799e2770f3c668eb3cfc917..ec2111127f8f18e8d56deef9c3b916e6e23ad17a 100644 (file)
@@ -1417,6 +1417,7 @@ int ctdb_ctrl_set_iface_link(struct ctdb_context *ctdb,
 uint32_t uint16_checksum(uint16_t *data, size_t n);
 int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface);
 bool ctdb_sys_have_ip(ctdb_sock_addr *addr);
+bool ctdb_sys_check_iface_exists(const char *iface);
 int ctdb_sys_send_tcp(const ctdb_sock_addr *dest, 
                      const ctdb_sock_addr *src,
                      uint32_t seq, uint32_t ack, int rst);
index 62f54d88168f7ad4ca3a70f5a12ca998863685b7..73a4222748ccd6ec65ed85fe8ce746ae2a3a2e1d 100644 (file)
@@ -855,6 +855,16 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb,
        int i;
        int ret;
 
+       tmp = talloc_strdup(vnn, ifaces);
+       for (iface = strtok(tmp, ","); iface; iface = strtok(NULL, ",")) {
+               if (!ctdb_sys_check_iface_exists(iface)) {
+                       DEBUG(DEBUG_CRIT,("Interface %s does not exist. Can not add public-address : %s\n", iface, ctdb_addr_to_str(addr)));
+                       talloc_free(tmp);
+                       return -1;
+               }
+       }
+       talloc_free(tmp);
+
        /* Verify that we dont have an entry for this ip yet */
        for (vnn=ctdb->vnn;vnn;vnn=vnn->next) {
                if (ctdb_same_sockaddr(addr, &vnn->public_address)) {