From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VVzup-0001uV-Jq for qemu-devel@nongnu.org; Tue, 15 Oct 2013 04:23:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VVzug-0005Vt-5o for qemu-devel@nongnu.org; Tue, 15 Oct 2013 04:23:43 -0400 Received: from e28smtp03.in.ibm.com ([122.248.162.3]:47799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VVzuf-0005VM-GY for qemu-devel@nongnu.org; Tue, 15 Oct 2013 04:23:34 -0400 Received: from /spool/local by e28smtp03.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 15 Oct 2013 13:53:25 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id A6C3EE0057 for ; Tue, 15 Oct 2013 13:54:47 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r9F8Q3MH35389500 for ; Tue, 15 Oct 2013 13:56:04 +0530 Received: from d28av04.in.ibm.com (localhost [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r9F8NMuR005384 for ; Tue, 15 Oct 2013 13:53:22 +0530 Message-ID: <525CFB78.2010606@linux.vnet.ibm.com> Date: Tue, 15 Oct 2013 16:23:20 +0800 From: mike MIME-Version: 1.0 References: <1381810677-4369-1-git-send-email-qiudayu@linux.vnet.ibm.com> <525CCD98.7010707@weilnetz.de> <525CD932.1080807@linux.vnet.ibm.com> <525CDB16.2040607@weilnetz.de> In-Reply-To: <525CDB16.2040607@weilnetz.de> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [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: Stefan Weil Cc: qemu-devel@nongnu.org, stefanha@redhat.com, aliguori@amazon.com On 10/15/2013 02:05 PM, Stefan Weil wrote: > Am 15.10.2013 07:57, schrieb mike: >> On 10/15/2013 01:07 PM, Stefan Weil wrote: >>> Am 15.10.2013 06:17, schrieb Mike Qiu: >>>> 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; >>>> } >>>> /** >>> There is no overflow which must be handled because a[5] is an uint8_t >>> value, so the assignment automatically limits the range to 0...255. >> OK, you are right, but I think we'd better to ensure this, >> even though a[5] is an uint8_t. >>> Is it reasonable to get a random mac address in your guest? I don't >>> think so. It would no longer be possible to connect to a guest using >>> ssh, restart that guest and connect again with ssh. >> Why not? I have do the experiment, after reboot, the mac is not changed. >> and the ip address always the same. >> >> And can be login to the guest after reboot. > "restart" means terminate QEMU and start it again. OK, qemu support the mac address unset right ? So it may be a joke if just can start only one VM with mac address unset :). In your case, also can use monitor to get the mac address, simply 'info network' :) Then you can do as if you set the mac address. Thanks Mike > > >