Check for duplicate supplied vif MACs, and make sure that randomly generated MACs for a domain are all different Signed-off-by: Jody Belka <knew-xen@pimb.org> diffstat: create.py | 11 +++++++++++ 1 files changed, 11 insertions(+) diff -durN xen.orig/tools/python/xen/xm/create.py xen/tools/python/xen/xm/create.py --- xen.orig/tools/python/xen/xm/create.py 2005-01-30 00:46:29.000000000 +0100 +++ xen/tools/python/xen/xm/create.py 2005-01-31 18:33:34.744204752 +0100 @@ -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 _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
Please can you explain how the randomly generated MACs are kept different -- I was expecting to see the vif number being folded into the random MAC generation. (I''m not saying what you''ve done doesn''t work, I''d just like an explanation) Thanks, Ian> -----Original Message----- > From: xen-devel-admin@lists.sourceforge.net > [mailto:xen-devel-admin@lists.sourceforge.net] On Behalf Of Jody Belka > Sent: 31 January 2005 22:33 > To: xen-devel@lists.sourceforge.net > Subject: [Xen-devel] [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 > > Signed-off-by: Jody Belka <knew-xen@pimb.org> > > > diffstat: > create.py | 11 +++++++++++ > 1 files changed, 11 insertions(+) > > > diff -durN xen.orig/tools/python/xen/xm/create.py > xen/tools/python/xen/xm/create.py > --- xen.orig/tools/python/xen/xm/create.py 2005-01-30 > 00:46:29.000000000 +0100 > +++ xen/tools/python/xen/xm/create.py 2005-01-31 > 18:33:34.744204752 +0100 > @@ -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 > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/xen-devel >------------------------------------------------------- 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 _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
On Mon, Jan 31, 2005 at 11:07:16PM -0000, Ian Pratt wrote:> > Please can you explain how the randomly generated MACs are kept > different -- I was expecting to see the vif number being folded into the > random MAC generation. > > (I''m not saying what you''ve done doesn''t work, I''d just like an > explanation)It doesn''t prevent different domains from getting the same random MACs, only within a domain. It keeps a list of generated MACs as it processes the vifs, and loops until one is generated that hasn''t been used yet. For some reason i''d usually get several copies of the same MAC without this code when creating multiple vifs within one domain. J -- Jody Belka knew (at) pimb (dot) org ------------------------------------------------------- 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 _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
> > Please can you explain how the randomly generated MACs are kept > > different -- I was expecting to see the vif number being > folded into the > > random MAC generation. > > > > (I''m not saying what you''ve done doesn''t work, I''d just like an > > explanation) > > It doesn''t prevent different domains from getting the same > random MACs, > only within a domain. It keeps a list of generated MACs as it > processes > the vifs, and loops until one is generated that hasn''t been used yet. > For some reason i''d usually get several copies of the same MAC without > this code when creating multiple vifs within one domain.Your patch certainly helps by rejecting duplicates, but I''d also like to see the algorithm used to generate the MACs changed too. We currently seed the random number generator with random.seed() which I suspect seeds it with the system time in seconds. At the very least, we should use something more fine grained to avoid other domains started in quick succession getting the same MACs. A better approach might be to seed it with a hash of the config file plus any parameters passed into it (e.g. vmid), plus the vif number. Would you mind knocking something up? Thanks, Ian ------------------------------------------------------- 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 _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel
On Mon, Jan 31, 2005 at 11:36:16PM -0000, Ian Pratt wrote:> Your patch certainly helps by rejecting duplicates, but I''d also like to > see the algorithm used to generate the MACs changed too. > > We currently seed the random number generator with random.seed() which I > suspect seeds it with the system time in seconds. At the very least, we > should use something more fine grained to avoid other domains started in > quick succession getting the same MACs. > > A better approach might be to seed it with a hash of the config file > plus any parameters passed into it (e.g. vmid), plus the vif number. > > Would you mind knocking something up?Sure, i''d be happy to. If nothing comes up i''ll try and have something posted sometime tomorrow. J -- Jody Belka knew (at) pimb (dot) org ------------------------------------------------------- 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 _______________________________________________ Xen-devel mailing list Xen-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xen-devel