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)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 6 Sep 2011 06:11:00 +0000 (16:11 +1000)
check that the actual interface exist, print error and fail startup if the interface does not exist.

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 f28045f95e5362a864ade4dcfa64df4c0886e83e..3fe90e6ef39079fb49a0d780f5cfae3d99733308 100644 (file)
@@ -73,3 +73,5 @@ bool ctdb_sys_have_ip(ctdb_sock_addr *_addr)
        close(s);
        return ret == 0;
 }
+
+
index a498ab2d686999f6b596d526e2b3f8736f1ef64f..2dcdffb3ece1c342c052214b8202fd171bb97d72 100644 (file)
@@ -537,3 +537,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 b24efcc64a03001e0cbccae59bba0ac8e69e5cc6..52c0be28c5b0b0876bec49bdce90180ed166e5ea 100644 (file)
@@ -1111,6 +1111,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 1e2e829e4dbbed1b56cdaae0fcdf294a54fe1307..f3644427878dd9cc115850e1db923b2396073636 100644 (file)
@@ -880,6 +880,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)) {