//! //! Retrieves a given device information (assigned IPs and NMS). //! //! @param[in] dev //! @param[out] outips //! @param[out] outnms //! @param[out] len //! //! @return EUCA_OK on success and the out fields will be set properly. On failure the //! following error codes are returned: //! - EUCA_ERROR: if we fail to retrieve the interfaces addresses. //! - EUCA_INVALID_ERROR: if any parameter does not meet the preconditions //! //! @pre dev, outips, outnms and len must not be NULL. //! //! @note //! @todo replace with a better version. //! int getdevinfo(char *dev, u32 ** outips, u32 ** outnms, int *len) { int rc = 0; int count = 0; char host[NI_MAXHOST] = ""; char buf[32] = ""; void *tmpAddrPtr = NULL; struct ifaddrs *ifaddr = NULL; struct ifaddrs *ifa = NULL; struct sockaddr_in *ifs = NULL; if ((dev == NULL) || (outips == NULL) || (outnms == NULL) || (len == NULL)) return (EUCA_INVALID_ERROR); if ((rc = getifaddrs(&ifaddr)) != 0) { return (EUCA_ERROR); } *outips = *outnms = NULL; *len = 0; count = 0; for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { if (!strcmp(dev, "all") || !strcmp(ifa->ifa_name, dev)) { if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) { if ((rc = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) == 0) { count++; //! @todo handle graceful out of memory condition and report it *outips = EUCA_REALLOC(*outips, count, sizeof(u32)); *outnms = EUCA_REALLOC(*outnms, count, sizeof(u32)); (*outips)[count - 1] = dot2hex(host); ifs = ((struct sockaddr_in *)ifa->ifa_netmask); tmpAddrPtr = &ifs->sin_addr; if (inet_ntop(AF_INET, tmpAddrPtr, buf, 32)) { (*outnms)[count - 1] = dot2hex(buf); } } } } } freeifaddrs(ifaddr); *len = count; return (EUCA_OK); }
//! //! Function description. //! //! @param[in] ipsh pointer to the IP set handler structure //! @param[in] setname a string pointer to the ipset name //! @param[in] findipstr a string pointer to the IP address we're looking for //! @param[in] findnm the IP netmask address we're looking for //! //! @return //! //! @see //! //! @pre //! //! @post //! //! @note //! u32 *ips_set_find_net(ips_handler * ipsh, char *setname, char *findipstr, int findnm) { int i, found = 0, ipidx = 0; ips_set *set = NULL; u32 findip; if (!ipsh || !setname || !findipstr || !ipsh->init) { return (NULL); } set = ips_handler_find_set(ipsh, setname); if (!set) { return (NULL); } findip = dot2hex(findipstr); found = 0; for (i = 0; i < set->max_member_ips && !found; i++) { ipidx = i; if (set->member_ips[i] == findip && set->member_nms[i] == findnm) found++; } if (!found) { return (NULL); } return (&(set->member_ips[ipidx])); }
//! //! Function description. //! //! @param[in] ipsh pointer to the IP set handler structure //! @param[in] setname a string pointer to the ipset name //! @param[in] ipname a string pointer to the ip address //! @param[in] nmname the netmask address //! //! @return //! //! @see //! //! @pre //! //! @post //! //! @note //! int ips_set_add_net(ips_handler * ipsh, char *setname, char *ipname, int nmname) { ips_set *set = NULL; u32 *ip = NULL; if (!ipsh || !setname || !ipname || !ipsh->init) { return (1); } set = ips_handler_find_set(ipsh, setname); if (!set) { return (1); } ip = ips_set_find_net(ipsh, setname, ipname, nmname); if (!ip) { set->member_ips = realloc(set->member_ips, sizeof(u32) * (set->max_member_ips + 1)); if (!set->member_ips) { LOGFATAL("out of memory!\n"); exit(1); } set->member_nms = realloc(set->member_nms, sizeof(int) * (set->max_member_ips + 1)); if (!set->member_nms) { LOGFATAL("out of memory!\n"); exit(1); } bzero(&(set->member_ips[set->max_member_ips]), sizeof(u32)); bzero(&(set->member_nms[set->max_member_ips]), sizeof(int)); set->member_ips[set->max_member_ips] = dot2hex(ipname); set->member_nms[set->max_member_ips] = nmname; set->max_member_ips++; set->ref_count++; } return (0); }
/** * Perform network driver upgrade. This function should be invoked once when eucanetd * starts. * @param pConfig [in] a pointer to eucanetd system-wide configuration * @param pGni [in] a pointer to the Global Network Information structure * @return 0 on success. Integer number on failure. */ static int network_driver_upgrade(eucanetdConfig *pConfig, globalNetworkInfo *pGni) { int ret = 0; int rc = 0; // Skip upgrade in flush mode if (pMidoConfig && pMidoConfig->config && (pMidoConfig->config->flushmode != FLUSH_NONE)) { LOGTRACE("\tflush mode selected. Skipping upgrade\n"); return (0); } LOGDEBUG("Upgrade '%s' network driver.\n", DRIVER_NAME()); if (!pConfig || !pGni) { LOGERROR("Invalid argument: cannot process upgrade with NULL config.\n"); return (1); } // Make sure midoname buffer is available midonet_api_cache_midos_init(); u32 mido_euca_version = 0; char *mido_euca_version_str = NULL; midoname **ipgs = NULL; int max_ipgs = 0; midoname **ips = NULL; int max_ips = 0; rc = mido_get_ipaddrgroups(VPCMIDO_TENANT, &ipgs, &max_ipgs); boolean found = FALSE; boolean do_upgrade = FALSE; if (!rc && max_ipgs) { for (int i = 0; i < max_ipgs && !found; i++) { if (!strcmp(ipgs[i]->name, "euca_version")) { rc = mido_get_ipaddrgroup_ips(ipgs[i], &ips, &max_ips); if (!rc && ips && max_ips) { if (max_ips > 1) { LOGFATAL("Unable to detect eucanetd artifacts version - %d versions\n", max_ips); LOGINFO("eucanetd going down.\n"); exit(1); } mido_euca_version = euca_version_dot2hex(ips[0]->ipagip->ip); mido_euca_version_str = hex2dot(mido_euca_version); found = TRUE; LOGTRACE("\tFound %s artifacts\n", mido_euca_version_str); if (mido_euca_version < dot2hex("4.4.0.0")) { LOGWARN("Unable to upgrade from version %s\n", mido_euca_version_str); LOGINFO("eucanetd going down.\n"); exit(1); } if (mido_euca_version < pConfig->euca_version) { LOGINFO("Upgrading Eucalyptus %s to %s\n", mido_euca_version_str, pConfig->euca_version_str); mido_delete_resource(ipgs[i], ips[0]); do_upgrade = TRUE; } if (mido_euca_version > pConfig->euca_version) { LOGFATAL("Downgrading Eucalyptus %s to %s not supported\n", mido_euca_version_str, pConfig->euca_version_str); LOGFATAL("eucanetd going down.\n"); exit(1); } } EUCA_FREE(ips); } } } EUCA_FREE(ipgs); if (do_upgrade) { // No 4.4->5.0 upgrade action required /* // Retrieve all objects rc = midonet_api_cache_refresh_v_threads(MIDO_CACHE_REFRESH_ALL); if (rc) { LOGERROR("failed to retrieve objects from MidoNet.\n"); } else { mido_config *mido = pMidoConfig; rc = do_midonet_populate(mido); if (rc) { LOGWARN("failed to populate VPC models prior to upgrade.\n"); } } */ } EUCA_FREE(mido_euca_version_str); return (ret); }