From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VVw5n-0007F0-Kq for qemu-devel@nongnu.org; Tue, 15 Oct 2013 00:18:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VVw5e-0004mJ-Ly for qemu-devel@nongnu.org; Tue, 15 Oct 2013 00:18:47 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:41463) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VVw5e-0004lJ-0V for qemu-devel@nongnu.org; Tue, 15 Oct 2013 00:18:38 -0400 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 15 Oct 2013 14:18:02 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 434452BB0040 for ; Tue, 15 Oct 2013 15:18:00 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r9F4HmI97995710 for ; Tue, 15 Oct 2013 15:17:48 +1100 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r9F4Hxcm012111 for ; Tue, 15 Oct 2013 15:17:59 +1100 From: Mike Qiu Date: Tue, 15 Oct 2013 00:17:57 -0400 Message-Id: <1381810677-4369-1-git-send-email-qiudayu@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2] net/net: Change the default mac address of nic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Mike Qiu , stefanha@redhat.com, aliguori@amazon.com Changelog to v1: Find remainder of macaddr->a[5] by modulo 256, otherwise it may be overflow by add index++. 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 --- net/net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/net.c b/net/net.c index c330c9a..9e72764 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 + #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++) % 256; } /** -- 1.8.3.1