[PATCH 0 of 2] Move MAC generation to DefineSystem

This set moves the MAC generation to DefineSystem and out of the example NetRASD from AC.

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1209579110 25200 # Node ID ffd90f0ed0e8e06c51db09befd3a09c956b00444 # Parent a6ad7167443f326ec96e2161127024a86259e4fb Revert the random MAC generation patch against SDC ...because it gets in the way of a client's ability to determine which RASD is min/max/def/incr. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r a6ad7167443f -r ffd90f0ed0e8 src/Virt_SettingsDefineCapabilities.c --- a/src/Virt_SettingsDefineCapabilities.c Tue Apr 29 07:05:34 2008 -0700 +++ b/src/Virt_SettingsDefineCapabilities.c Wed Apr 30 11:11:50 2008 -0700 @@ -25,7 +25,6 @@ #include <stdbool.h> #include <sys/vfs.h> #include <errno.h> -#include <time.h> #include <uuid/uuid.h> #include <libvirt/libvirt.h> @@ -54,8 +53,6 @@ const static CMPIBroker *_BROKER; #define SDC_DISK_MIN 2000 #define SDC_DISK_DEF 5000 #define SDC_DISK_INC 250 - -#define DEFAULT_MAC_PREFIX "00:16:3e" static bool system_has_vt(virConnectPtr conn) { @@ -629,74 +626,25 @@ static struct sdc_rasd_prop *net_max(con return rasd; } -static const char *_net_rand_mac(void) -{ - int r; - int ret; - unsigned int s; - char *tmp_mac = NULL; - const char *mac = NULL; - CMPIString *str = NULL; - CMPIStatus status; - - srand(time(NULL)); - r = rand_r(&s); - - ret = asprintf(&tmp_mac, - "%s:%02x:%02x:%02x", - DEFAULT_MAC_PREFIX, - r & 0xFF, - (r & 0xFF00) >> 8, - (r & 0xFF0000) >> 16); - - if (ret == -1) - goto out; - - str = CMNewString(_BROKER, tmp_mac, &status); - if ((str == NULL) || (status.rc != CMPI_RC_OK)) { - str = NULL; - CU_DEBUG("Failed to create string"); - goto out; - } - out: - free(tmp_mac); - - if (str != NULL) - mac = CMGetCharPtr(str); - else - mac = NULL; - - return mac; -} - static struct sdc_rasd_prop *net_def(const CMPIObjectPath *ref, CMPIStatus *s) { bool ret; uint16_t num_nics = 1; struct sdc_rasd_prop *rasd = NULL; - const char *mac = _net_rand_mac(); struct sdc_rasd_prop tmp[] = { {"InstanceID", (CMPIValue *)"Default", CMPI_chars}, {"VirtualQuantity", (CMPIValue *)&num_nics, CMPI_uint16}, - {"Address", (CMPIValue *)mac, CMPI_chars}, - PROP_END - }; - - if (mac == NULL) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Failed to generate new MAC address"); - goto out; - } - - ret = dup_rasd_prop_list(tmp, &rasd); - if (!ret) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Could not copy RASD"); - } - out: + PROP_END + }; + + ret = dup_rasd_prop_list(tmp, &rasd); + if (!ret) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Could not copy RASD"); + } + return rasd; }

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1209579877 25200 # Node ID ffa1024f9012873e29c732a9b355199bd61d0440 # Parent ffd90f0ed0e8e06c51db09befd3a09c956b00444 Generate a random MAC for NetRASD instances in VSMS if not specified This is a direct import of the MAC generation function previously in SettingsDefineCapabilities. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r ffd90f0ed0e8 -r ffa1024f9012 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Wed Apr 30 11:11:50 2008 -0700 +++ b/src/Virt_VirtualSystemManagementService.c Wed Apr 30 11:24:37 2008 -0700 @@ -24,6 +24,7 @@ #include <stdlib.h> #include <stdbool.h> #include <inttypes.h> +#include <time.h> #include <libvirt/libvirt.h> #include "cmpidt.h" @@ -51,6 +52,8 @@ #include "svpc_types.h" #include "config.h" + +#define DEFAULT_MAC_PREFIX "00:16:3e" const static CMPIBroker *_BROKER; @@ -311,6 +314,45 @@ static const char *kvm_net_rasd_to_vdev( return NULL; } +static const char *_net_rand_mac(void) +{ + int r; + int ret; + unsigned int s; + char *mac = NULL; + CMPIString *str = NULL; + CMPIStatus status; + + srand(time(NULL)); + r = rand_r(&s); + + ret = asprintf(&mac, + "%s:%02x:%02x:%02x", + DEFAULT_MAC_PREFIX, + r & 0xFF, + (r & 0xFF00) >> 8, + (r & 0xFF0000) >> 16); + + if (ret == -1) + goto out; + + str = CMNewString(_BROKER, mac, &status); + if ((str == NULL) || (status.rc != CMPI_RC_OK)) { + str = NULL; + CU_DEBUG("Failed to create string"); + goto out; + } + out: + free(mac); + + if (str != NULL) + mac = CMGetCharPtr(str); + else + mac = NULL; + + return mac; +} + static const char *net_rasd_to_vdev(CMPIInstance *inst, struct virt_device *dev) { @@ -319,8 +361,11 @@ static const char *net_rasd_to_vdev(CMPI const char *msg = NULL; if (cu_get_str_prop(inst, "Address", &val) != CMPI_RC_OK) { - msg = "Required field `Address' missing from NetRASD"; - goto out; + val = _net_rand_mac(); + if (val == NULL) { + msg = "Unable to generate a MAC address"; + goto out; + } } free(dev->dev.net.mac);

Dan Smith wrote:
This set moves the MAC generation to DefineSystem and out of the example NetRASD from AC.
Having already determined it's necessary to make this change, I guess there's not really a whole lot to be said about a patch that just moves code from one place to the other. So... +1! -- -Jay
participants (2)
-
Dan Smith
-
Jay Gagnon