[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 1/5] conf: Change statically allocated MAC to dynamic



We need this so we can later suppress generation and know whether user
supplied one or not in XML.
---
 src/conf/domain_conf.c   |    4 +++-
 src/conf/domain_conf.h   |    2 +-
 src/openvz/openvz_conf.c |    3 ++-
 src/qemu/qemu_command.c  |    3 ++-
 src/qemu/qemu_hotplug.c  |    2 +-
 src/vbox/vbox_tmpl.c     |    4 +++-
 src/vmx/vmx.c            |    3 ++-
 src/xen/xm_internal.c    |    5 ++---
 src/xenxs/xen_sxpr.c     |    3 ++-
 src/xenxs/xen_xm.c       |    3 ++-
 10 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 16e1291..c2c7057 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -594,6 +594,7 @@ void virDomainNetDefFree(virDomainNetDefPtr def)
     if (!def)
         return;
 
+    VIR_FREE(def->mac);
     VIR_FREE(def->model);
 
     switch (def->type) {
@@ -2490,7 +2491,8 @@ virDomainNetDefParseXML(virCapsPtr caps,
     xmlNodePtr oldnode = ctxt->node;
     int ret;
 
-    if (VIR_ALLOC(def) < 0) {
+    if ((VIR_ALLOC(def) < 0) ||
+        (VIR_ALLOC_N(def->mac,VIR_MAC_BUFLEN) < 0)) {
         virReportOOMError();
         return NULL;
     }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 30aeccc..476e122 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -345,7 +345,7 @@ typedef struct _virDomainNetDef virDomainNetDef;
 typedef virDomainNetDef *virDomainNetDefPtr;
 struct _virDomainNetDef {
     enum virDomainNetType type;
-    unsigned char mac[VIR_MAC_BUFLEN];
+    unsigned char *mac;
     char *model;
     union {
         struct {
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 0eb5ab3..458f107 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -236,7 +236,8 @@ openvzReadNetworkConf(virDomainDefPtr def,
         token = strtok_r(temp, ";", &saveptr);
         while (token != NULL) {
             /*add new device to list*/
-            if (VIR_ALLOC(net) < 0)
+            if ((VIR_ALLOC(net) < 0) ||
+                (VIR_ALLOC_N(net->mac, VIR_MAC_BUFLEN) < 0))
                 goto no_memory;
 
             net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c9b9850..35d695d 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5017,7 +5017,8 @@ qemuParseCommandLineNet(virCapsPtr caps,
         nkeywords = 0;
     }
 
-    if (VIR_ALLOC(def) < 0) {
+    if ((VIR_ALLOC(def) < 0) ||
+        (VIR_ALLOC_N(def->mac, VIR_MAC_BUFLEN) < 0)) {
         virReportOOMError();
         goto cleanup;
     }
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e4ba526..d8a8e5d 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1479,7 +1479,7 @@ int qemuDomainDetachNetDevice(struct qemud_driver *driver,
     for (i = 0 ; i < vm->def->nnets ; i++) {
         virDomainNetDefPtr net = vm->def->nets[i];
 
-        if (!memcmp(net->mac, dev->data.net->mac,  sizeof(net->mac))) {
+        if (!memcmp(net->mac, dev->data.net->mac, VIR_MAC_BUFLEN)) {
             detach = net;
             break;
         }
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index e8ac48f..f964e4b 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -2709,7 +2709,9 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
             /* Allocate memory for the networkcards which are enabled */
             if ((def->nnets > 0) && (VIR_ALLOC_N(def->nets, def->nnets) >= 0)) {
                 for (i = 0; i < def->nnets; i++) {
-                    if (VIR_ALLOC(def->nets[i]) >= 0) {
+                    if ((VIR_ALLOC(def->nets[i]) >= 0) ||
+                        (VIR_ALLOC_N(def->nets[i]->mac,
+                                     VIR_MAC_BUFLEN) >= 0)) {
                     } else
                         virReportOOMError();
                 }
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 9f4d5fb..77f18c2 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2271,7 +2271,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
         return -1;
     }
 
-    if (VIR_ALLOC(*def) < 0) {
+    if ((VIR_ALLOC(*def) < 0) ||
+        (VIR_ALLOC_N((*def)->mac, VIR_MAC_BUFLEN) < 0)) {
         virReportOOMError();
         return -1;
     }
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 7f73588..9a9fa0c 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -1501,9 +1501,8 @@ xenXMDomainDetachDeviceFlags(virDomainPtr domain, const char *xml,
     case VIR_DOMAIN_DEVICE_NET:
     {
         for (i = 0 ; i < def->nnets ; i++) {
-            if (!memcmp(def->nets[i]->mac,
-                        dev->data.net->mac,
-                        sizeof(def->nets[i]->mac))) {
+            if (!memcmp(def->nets[i]->mac, dev->data.net->mac,
+                        VIR_MAC_BUFLEN)) {
                 virDomainNetDefFree(def->nets[i]);
                 if (i < (def->nnets - 1))
                     memmove(def->nets + i,
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index 3a412a6..e918801 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -518,7 +518,8 @@ xenParseSxprNets(virDomainDefPtr def,
             model = sexpr_node(node, "device/vif/model");
             type = sexpr_node(node, "device/vif/type");
 
-            if (VIR_ALLOC(net) < 0)
+            if ((VIR_ALLOC(net) < 0) ||
+                (VIR_ALLOC_N(net->mac, VIR_MAC_BUFLEN) < 0))
                 goto no_memory;
 
             if (tmp != NULL ||
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 0acd120..6a94b09 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -647,7 +647,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
                 key = nextkey;
             }
 
-            if (VIR_ALLOC(net) < 0)
+            if ((VIR_ALLOC(net) < 0) ||
+                (VIR_ALLOC_N(net->mac, VIR_MAC_BUFLEN) < 0))
                 goto no_memory;
 
             if (mac[0]) {
-- 
1.7.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]