Skip to contentSkip to conversation

xen: xm/create mac selection

PATCH In review Jody Belka 1 participant 1 message Jan 31, 2005

lore
Share & tools
lore

Jody Belka

author
#0 lore raw

PATCH 3/5 xen: xm/create mac selection

Check for duplicate supplied vif MACs, and make sure that randomly generated MACs for a domain are all different

diffstat:

 create.py |   11 +++++++++++
 1 files changed, 11 insertions(+)
tools/python/xen/xm/create.py +11 -0
diff -durN xen.orig/tools/python/xen/xm/create.py xen/tools/python/xen/xm/create.py
@@ -279,10 +279,15 @@
     vifs = vals.vif
     vifs_n = max(vals.nics, len(vifs))
 
+    macs = []
+    mac_vifs = {}
+
     for idx in range(0, vifs_n):
         if idx < len(vifs):
             d = vifs[idx]
             mac = d.get('mac')
+            if mac in macs:
+                gopts.err('Duplicate MAC: %s selected for both vif%i and vif%i' % (mac, mac_vifs[mac], idx + 1))
             if not mac:
                 mac = randomMAC()
             bridge = d.get('bridge')
@@ -295,6 +300,12 @@
             script = None
             backend = None
             ip = None
+
+        while mac in macs:
+            mac = randomMAC()
+        macs.append(mac)
+        mac_vifs[mac] = idx + 1
+
         config_vif = ['vif']
         config_vif.append(['mac', mac])
         if bridge:

-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl