ctdb-daemon: Move interface addition into interface parsing
[metze/samba/wip.git] / ctdb / server / ctdb_takeover.c
index 0dbef03660cbedccf5654408eb0335818bcda366..f34803217f0b3b79c28e5920eda7199a2929bc5f 100644 (file)
@@ -116,9 +116,16 @@ static int ctdb_add_local_iface(struct ctdb_context *ctdb, const char *iface)
 
        /* create a new structure for this interface */
        i = talloc_zero(ctdb, struct ctdb_interface);
-       CTDB_NO_MEMORY_FATAL(ctdb, i);
+       if (i == NULL) {
+               DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));
+               return -1;
+       }
        i->name = talloc_strdup(i, iface);
-       CTDB_NO_MEMORY(ctdb, i->name);
+       if (i->name == NULL) {
+               DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));
+               talloc_free(i);
+               return -1;
+       }
 
        i->link_up = true;
 
@@ -1045,7 +1052,6 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb,
        uint32_t num = 0;
        char *tmp;
        const char *iface;
-       int i;
        int ret;
 
        /* Verify that we don't have an entry for this IP yet */
@@ -1058,17 +1064,7 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb,
                }
        }
 
-       tmp = strdup(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)));
-                       free(tmp);
-                       return -1;
-               }
-       }
-       free(tmp);
-
-       /* create a new vnn structure for this ip address */
+       /* Create a new VNN structure for this IP address */
        vnn = talloc_zero(ctdb, struct ctdb_vnn);
        if (vnn == NULL) {
                DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));
@@ -1087,6 +1083,24 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb,
                return -1;
        }
        for (iface = strtok(tmp, ","); iface; iface = strtok(NULL, ",")) {
+               if (!ctdb_sys_check_iface_exists(iface)) {
+                       DEBUG(DEBUG_ERR,
+                             ("Unknown interface %s for public address %s\n",
+                              iface, ctdb_addr_to_str(addr)));
+                       talloc_free(vnn);
+                       return -1;
+               }
+
+               ret = ctdb_add_local_iface(ctdb, iface);
+               if (ret != 0) {
+                       DEBUG(DEBUG_ERR,
+                             ("Failed to add interface '%s' "
+                              "for public address %s\n",
+                              iface, ctdb_addr_to_str(addr)));
+                       talloc_free(vnn);
+                       return -1;
+               }
+
                vnn->ifaces = talloc_realloc(vnn, vnn->ifaces, const char *, num + 2);
                if (vnn->ifaces == NULL) {
                        DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));
@@ -1107,17 +1121,6 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb,
        vnn->public_netmask_bits = mask;
        vnn->pnn                 = -1;
 
-       for (i=0; vnn->ifaces[i]; i++) {
-               ret = ctdb_add_local_iface(ctdb, vnn->ifaces[i]);
-               if (ret != 0) {
-                       DEBUG(DEBUG_CRIT, (__location__ " failed to add iface[%s] "
-                                          "for public_address[%s]\n",
-                                          vnn->ifaces[i], ctdb_addr_to_str(addr)));
-                       talloc_free(vnn);
-                       return -1;
-               }
-       }
-
        DLIST_ADD(ctdb->vnn, vnn);
 
        return 0;