* [Qemu-devel] [PATCH] net/net: Change the default mac address of nic
@ 2013-10-14 7:26 y
0 siblings, 0 replies; only message in thread
From: y @ 2013-10-14 7:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Mike Qiu, stefanha, aliguori
From: Mike Qiu <qiudayu@linux.vnet.ibm.com>
The default mac address is 52:54:00:12:34:56 + index, this will
cause problem that when we boot up more than one guest with all
mac addresses unset by default, assume that each guest has one
nic. In this situation, all the guest's nic has the same mac address.
This patch is to solve this bug.
Signed-off-by: Mike Qiu <qiudayu@linux.vnet.ibm.com>
---
net/net.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/net.c b/net/net.c
index c330c9a..2796d04 100644
--- a/net/net.c
+++ b/net/net.c
@@ -21,6 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
+#include <time.h>
+
#include "config-host.h"
#include "net/net.h"
@@ -147,12 +149,13 @@ void qemu_macaddr_default_if_unset(MACAddr *macaddr)
if (memcmp(macaddr, &zero, sizeof(zero)) != 0)
return;
+ srand((unsigned)time(NULL));
macaddr->a[0] = 0x52;
macaddr->a[1] = 0x54;
macaddr->a[2] = 0x00;
- macaddr->a[3] = 0x12;
- macaddr->a[4] = 0x34;
- macaddr->a[5] = 0x56 + index++;
+ macaddr->a[3] = rand() % 256;
+ macaddr->a[4] = rand() % 256;
+ macaddr->a[5] = rand() % 256 + index++;
}
/**
--
1.8.2.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-10-14 7:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-14 7:26 [Qemu-devel] [PATCH] net/net: Change the default mac address of nic y
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).