From a9c2c027afeeaa771f650047c13c619459c993ef Mon Sep 17 00:00:00 2001 From: root Date: Sat, 5 Mar 2011 12:41:54 -0800 Subject: [PATCH] HAize SYSTEM and STATIC mode(s) --- cluster/handlers-state.c | 2 +- cluster/handlers.c | 66 +++++++++++++++++++--------------------- net/vnetwork.c | 44 +++++++++++++++++++-------- 3 files changed, 64 insertions(+), 48 deletions(-) diff --git a/cluster/handlers-state.c b/cluster/handlers-state.c index 50852fd7247..5d4ac451611 100644 --- a/cluster/handlers-state.c +++ b/cluster/handlers-state.c @@ -350,7 +350,7 @@ int instNetParamsSet(ccInstance *inst, void *in) { snprintf(vnetconfig->users[inst->ccnet.vlan].userName, 48, "%s", inst->accountId); } } - } + } if (!ret) { // so far so good diff --git a/cluster/handlers.c b/cluster/handlers.c index cb04bf9d6c8..e9852aa36e4 100644 --- a/cluster/handlers.c +++ b/cluster/handlers.c @@ -954,7 +954,7 @@ int doDescribePublicAddresses(ncMetadata *ccMeta, publicip **outAddresses, int * } else { *outAddresses = NULL; *outAddressesLen = 0; - ret=2; + ret=0; } logprintfl(EUCADEBUG, "DescribePublicAddresses(): done. \n"); @@ -3721,33 +3721,34 @@ int restoreNetworkState() { ret = 1; } - // restore iptables state, if internal iptables state exists - logprintfl(EUCADEBUG, "restoreNetworkState(): restarting iptables\n"); - rc = vnetRestoreTablesFromMemory(vnetconfig); - if (rc) { - logprintfl(EUCAERROR, "restoreNetworkState(): cannot restore iptables state\n"); - ret = 1; - } - - // re-create all active networks (bridges, vlan<->bridge mappings) - logprintfl(EUCADEBUG, "restoreNetworkState(): restarting networks\n"); - for (i=2; inetworks[i].active) { - char *brname=NULL; - logprintfl(EUCADEBUG, "restoreNetworkState(): found active network: %d\n", i); - rc = vnetStartNetwork(vnetconfig, i, NULL, vnetconfig->users[i].userName, vnetconfig->users[i].netName, &brname); - if (rc) { - logprintfl(EUCADEBUG, "restoreNetworkState(): failed to reactivate network: %d", i); + if (!strcmp(vnetconfig->mode, "MANAGED") || !strcmp(vnetconfig->mode, "MANAGED-NOVLAN")) { + // restore iptables state, if internal iptables state exists + logprintfl(EUCADEBUG, "restoreNetworkState(): restarting iptables\n"); + rc = vnetRestoreTablesFromMemory(vnetconfig); + if (rc) { + logprintfl(EUCAERROR, "restoreNetworkState(): cannot restore iptables state\n"); + ret = 1; + } + + // re-create all active networks (bridges, vlan<->bridge mappings) + logprintfl(EUCADEBUG, "restoreNetworkState(): restarting networks\n"); + for (i=2; inetworks[i].active) { + char *brname=NULL; + logprintfl(EUCADEBUG, "restoreNetworkState(): found active network: %d\n", i); + rc = vnetStartNetwork(vnetconfig, i, NULL, vnetconfig->users[i].userName, vnetconfig->users[i].netName, &brname); + if (rc) { + logprintfl(EUCADEBUG, "restoreNetworkState(): failed to reactivate network: %d", i); + } + if (brname) free(brname); } - if (brname) free(brname); } - } - - // ret = vnetReassignAddress(vnetconfig, uuid, src, dst); - rc = map_instanceCache(validCmp, NULL, instNetReassignAddrs, NULL); - if (rc) { - logprintfl(EUCAERROR, "restoreNetworkState(): could not (re)assign public/private IP mappings\n"); - ret = 1; + + rc = map_instanceCache(validCmp, NULL, instNetReassignAddrs, NULL); + if (rc) { + logprintfl(EUCAERROR, "restoreNetworkState(): could not (re)assign public/private IP mappings\n"); + ret = 1; + } } // get DHCPD back up and running @@ -3760,14 +3761,6 @@ int restoreNetworkState() { sem_mypost(VNET); - /* - // get current rules from CLC - rc = reconfigureNetworkFromCLC(); - if (rc) { - logprintfl(EUCAWARN, "restoreNetworkState(): cannot get network ground truth from CLC\n"); - } - */ - logprintfl(EUCADEBUG, "restoreNetworkState(): done restoring network state\n"); return(ret); @@ -3779,6 +3772,10 @@ int reconfigureNetworkFromCLC() { int fd=0, i=0, rc=0, ret=0, usernetlen=0; FILE *FH=NULL; + if (strcmp(vnetconfig->mode, "MANAGED") && strcmp(vnetconfig->mode, "MANAGED-NOVLAN")) { + return(0); + } + // get the latest cloud controller IP address if (vnetconfig->cloudIp) { cloudIp = hex2dot(vnetconfig->cloudIp); @@ -3790,7 +3787,6 @@ int reconfigureNetworkFromCLC() { } } - // create and populate network state files snprintf(clcnetfile, MAX_PATH, "/tmp/euca-clcnet-XXXXXX"); snprintf(chainmapfile, MAX_PATH, "/tmp/euca-chainmap-XXXXXX"); diff --git a/net/vnetwork.c b/net/vnetwork.c index 6c13795718f..676e108acea 100644 --- a/net/vnetwork.c +++ b/net/vnetwork.c @@ -1084,32 +1084,52 @@ int vnetGetAllVlans(vnetConfig *vnetconfig, char ***outusers, char ***outnets, i } int vnetGenerateNetworkParams(vnetConfig *vnetconfig, char *instId, int vlan, int nidx, char *outmac, char *outpubip, char *outprivip) { - int rc, ret=0, networkIdx; + int rc, ret=0, networkIdx, found, i; + uint32_t inip; if (!instId || !outmac || !outpubip || !outprivip) { logprintfl(EUCAERROR, "vnetGenerateNetworkParams(): bad input params\n"); return(1); } - rc = instId2mac(instId, outmac); - if (rc) { - logprintfl(EUCAERROR, "vnetGenerateNetworkParams(): unable to convert instanceId (%s) to mac address\n", instId); - return(1); - } - ret = 1; // define/get next mac and allocate IP if (!strcmp(vnetconfig->mode, "STATIC") || !strcmp(vnetconfig->mode, "STATIC-DYNMAC")) { + // search for existing entry + inip = dot2hex(outprivip); + found=0; + for (i=2; inumaddrs-2 && !found; i++) { + logprintfl(EUCADEBUG, "HELLO: %d %s %s %s %d %d\n", i, outmac, hex2dot(inip), hex2dot(vnetconfig->networks[0].addrs[i].ip), machexcmp(outmac, vnetconfig->networks[0].addrs[i].mac), (vnetconfig->networks[0].addrs[i].ip == inip)); + if (!machexcmp(outmac, vnetconfig->networks[0].addrs[i].mac) && (vnetconfig->networks[0].addrs[i].ip == inip)) { + logprintfl(EUCADEBUG, "WOOT: %d %s %s %s %d %d\n", i, outmac, hex2dot(inip), hex2dot(vnetconfig->networks[0].addrs[i].ip), machexcmp(outmac, vnetconfig->networks[0].addrs[i].mac), (vnetconfig->networks[0].addrs[i].ip == inip)); + vnetconfig->networks[0].addrs[i].active = 1; + found++; + ret=0; + } + } // get the next valid mac/ip pairing for this vlan - outmac[0] = '\0'; - rc = vnetGetNextHost(vnetconfig, outmac, outprivip, 0, -1); - if (!rc) { - snprintf(outpubip, strlen(outprivip)+1, "%s", outprivip); - ret = 0; + if (!found) { + outmac[0] = '\0'; + rc = vnetGetNextHost(vnetconfig, outmac, outprivip, 0, -1); + if (!rc) { + snprintf(outpubip, strlen(outprivip)+1, "%s", outprivip); + ret = 0; + } } } else if (!strcmp(vnetconfig->mode, "SYSTEM")) { + rc = instId2mac(instId, outmac); + if (rc) { + logprintfl(EUCAERROR, "vnetGenerateNetworkParams(): unable to convert instanceId (%s) to mac address\n", instId); + return(1); + } ret = 0; } else if (!strcmp(vnetconfig->mode, "MANAGED") || !strcmp(vnetconfig->mode, "MANAGED-NOVLAN")) { + rc = instId2mac(instId, outmac); + if (rc) { + logprintfl(EUCAERROR, "vnetGenerateNetworkParams(): unable to convert instanceId (%s) to mac address\n", instId); + return(1); + } + if (nidx == -1) { networkIdx = -1; } else {