diff options
author | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2011-09-06 16:11:00 +1000 |
---|---|---|
committer | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2011-09-06 16:11:00 +1000 |
commit | 64378fea58c28ce9cf1ad6171e41bccb88c1bafc (patch) | |
tree | 0bfaa476009465ff468bfcf0353b09f996ebe051 | |
parent | a3e007956864f5d902f7bec22a2c51d1c391a7ff (diff) | |
download | samba-64378fea58c28ce9cf1ad6171e41bccb88c1bafc.tar.gz samba-64378fea58c28ce9cf1ad6171e41bccb88c1bafc.tar.xz samba-64378fea58c28ce9cf1ad6171e41bccb88c1bafc.zip |
Check interfaces: when reading the public addresses file to create the vnn list
check that the actual interface exist, print error and fail startup if the interface does not exist.
(This used to be ctdb commit cd33bbe6454b7b0316bdfffbd06c67b29779e873)
-rw-r--r-- | ctdb/common/system_aix.c | 4 | ||||
-rw-r--r-- | ctdb/common/system_common.c | 2 | ||||
-rw-r--r-- | ctdb/common/system_linux.c | 22 | ||||
-rw-r--r-- | ctdb/include/ctdb_private.h | 1 | ||||
-rw-r--r-- | ctdb/server/ctdb_takeover.c | 10 |
5 files changed, 39 insertions, 0 deletions
diff --git a/ctdb/common/system_aix.c b/ctdb/common/system_aix.c index 5fe54130d4..1404a82901 100644 --- a/ctdb/common/system_aix.c +++ b/ctdb/common/system_aix.c @@ -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; +} diff --git a/ctdb/common/system_common.c b/ctdb/common/system_common.c index f28045f95e..3fe90e6ef3 100644 --- a/ctdb/common/system_common.c +++ b/ctdb/common/system_common.c @@ -73,3 +73,5 @@ bool ctdb_sys_have_ip(ctdb_sock_addr *_addr) close(s); return ret == 0; } + + diff --git a/ctdb/common/system_linux.c b/ctdb/common/system_linux.c index a498ab2d68..2dcdffb3ec 100644 --- a/ctdb/common/system_linux.c +++ b/ctdb/common/system_linux.c @@ -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; +} diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index b24efcc64a..52c0be28c5 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -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); diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 1e2e829e4d..f364442787 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -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)) { |