[Libvirt-cim] [PATCH] Check for duplicate MAC addresses

Sharad Mishra snmishra at us.ibm.com
Wed Jul 15 05:16:32 UTC 2009


# HG changeset patch
# User snmishra at us.ibm.com
# Date 1247634781 25200
# Node ID ab9ad4cf3cb6f65ef082f4fb0fce23258e2af199
# Parent  3730865ecff94af45926b110373817e6ce38576d
Check for duplicate MAC addresses.

This patch gets all MAC addresses assigned
to the VMs on the host and verifies that the
generated or passed MAC does not conflict with
an existing MAC.

Signed-off-by: Sharad Mishra <snmishra at us.ibm.com>

diff -r 3730865ecff9 -r ab9ad4cf3cb6 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Tue Jul 07 14:13:30 2009 -0700
+++ b/src/Virt_VirtualSystemManagementService.c	Tue Jul 14 22:13:01 2009 -0700
@@ -534,6 +534,69 @@
         return _mac;
 }
 
+static const char *filter_by_address(struct inst_list *src,
+                                    const char *address)
+{
+        int i;
+        CMPIrc ret;
+        const char *addr;
+        const char *msg = NULL;
+        CMPIInstance *inst;
+
+        for (i = 0; i < src->cur; i++) {
+                inst = src->list[i];
+                ret = cu_get_str_prop(inst, "Address", &addr);
+       
+                if (ret != CMPI_RC_OK) 
+                        continue;
+
+                if (STREQ(addr, address)) {
+                        msg = "Conflicting MAC Addresses";
+                        goto out;
+                }
+        }
+out:
+	return msg;
+
+}
+
+static const char *check_duplicate_mac(CMPIInstance *inst,
+                                       const char *mac,
+                                       const char *ns)
+{
+        CMPIObjectPath *op = NULL;
+        CMPIStatus s;
+        const char *msg = NULL;
+        const char *props[] = {"Address", NULL};
+        struct inst_list in_list;
+
+        op = CMGetObjectPath(inst, &s);
+        if ((op == NULL) || (s.rc != CMPI_RC_OK)) {
+                msg = "Unable to get a reference to the guest";
+                goto out;
+        }
+
+        /* FIXME:  This is a Pegasus work around. Pegsus loses the namespace
+                   when an ObjectPath is pulled from an instance */
+
+        if (STREQ(NAMESPACE(op), ""))
+                CMSetNameSpace(op, ns);
+
+        inst_list_init(&in_list);
+        s = enum_rasds(_BROKER, op, NULL, CIM_RES_TYPE_NET, props, &in_list);
+        if (s.rc != CMPI_RC_OK) {
+                msg = "Failed to enumerate network instances";
+                goto out;
+        }
+
+        msg = filter_by_address(&in_list, mac);
+
+out:
+        inst_list_free(&in_list);
+        return msg;
+}
+
+
 static const char *net_rasd_to_vdev(CMPIInstance *inst,
                                     struct virt_device *dev,
                                     const char *ns)
@@ -550,6 +613,11 @@
                 }
         }
 
+        msg = check_duplicate_mac(inst, val, ns);
+        if (msg != NULL) { 
+                goto out;
+        }
+
         free(dev->dev.net.mac);
         dev->dev.net.mac = strdup(val);
 




More information about the Libvirt-cim mailing list