From patchwork Wed Sep 16 09:15:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfgang Denk X-Patchwork-Id: 518641 X-Patchwork-Delegate: wd@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 7601614033E for ; Thu, 17 Sep 2015 08:23:35 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F37184B81E; Thu, 17 Sep 2015 00:23:33 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2LFF3yaLXpiy; Thu, 17 Sep 2015 00:23:33 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6F3974A01C; Thu, 17 Sep 2015 00:20:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 711184B6A8 for ; Wed, 16 Sep 2015 11:15:30 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2CCZWSfQ76RZ for ; Wed, 16 Sep 2015 11:15:28 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by theia.denx.de (Postfix) with ESMTPS id A336C4B67F for ; Wed, 16 Sep 2015 11:15:20 +0200 (CEST) Received: from frontend02.mail.m-online.net (unknown [192.168.8.183]) by mail-out.m-online.net (Postfix) with ESMTP id 3nGG3j0xY2z3hkr8; Wed, 16 Sep 2015 11:15:12 +0200 (CEST) Received: from localhost (dynscan2.mnet-online.de [192.168.6.69]) by mail.m-online.net (Postfix) with ESMTP id 3nGG3h57y9zvdWV; Wed, 16 Sep 2015 11:15:12 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.184]) by localhost (dynscan2.mail.m-online.net [192.168.6.69]) (amavisd-new, port 10024) with ESMTP id thI1_ziDy-hn; Wed, 16 Sep 2015 11:15:11 +0200 (CEST) X-Auth-Info: fugmDDPmQJwanVq9U1TxpwG0gZ66U0w87YVcqSCBpho= Received: from diddl.denx.de (host-80-81-18-216.customer.m-online.net [80.81.18.216]) by smtp-auth.mnet-online.de (Postfix) with ESMTPA; Wed, 16 Sep 2015 11:15:11 +0200 (CEST) Received: from gemini.denx.de (gemini.denx.de [10.0.0.2]) by diddl.denx.de (Postfix) with ESMTP id 88F151A2B29; Wed, 16 Sep 2015 11:15:11 +0200 (CEST) Received: from gemini.denx.de (localhost [IPv6:::1]) by gemini.denx.de (Postfix) with ESMTP id 5238F380905; Wed, 16 Sep 2015 11:15:11 +0200 (MEST) To: Josh Wu From: Wolfgang Denk MIME-Version: 1.0 In-reply-to: <55F91588.3040305@atmel.com> References: <1442373526-842-1-git-send-email-josh.wu@atmel.com> <20150916063701.44C0C380905@gemini.denx.de> <55F91588.3040305@atmel.com> Comments: In-reply-to Josh Wu message dated "Wed, 16 Sep 2015 15:08:56 +0800." Date: Wed, 16 Sep 2015 11:15:11 +0200 Message-Id: <20150916091511.5238F380905@gemini.denx.de> Cc: U-Boot Mailing List Subject: Re: [U-Boot] [PATCH] tools: gen_eth_addr: remove getpid() operation for the random seed X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Dear Josh, In message <55F91588.3040305@atmel.com> you wrote: > > In above commands, I have two duplicated eth addr: > 92:33:16:3f:0a:56 > d2:41:66:54:64:aa Agreed. Randomness is really poor; for a sequence of 1000 invocations of gen_eth_addr in a shell loop I would only gt 124 different MAC addresses: -> for i in {1..1000} ; do ./gen_eth_addr ; done >/tmp/0 -> sort -u /tmp/0 >/tmp/1 ; wc -l /tmp/[01] 1000 /tmp/0 124 /tmp/1 In a second run, even only 41 :-( But without the getpid() part, it gets even worse - the same loop would produce only 15 different addresses! Changing the '|' into a '+' would reliably generate 1000 different MAC addresses. > I understand your concern. My intention is make it harder to generate > the duplicated result. I understand this, and agree that we should implement such a fix. > Maybe we can ORing the MSB of time(0)? > I'll investigate it little more. The following patch appears to work fine for me. Maybe you can test it? Thanks. Best regards, Wolfgang Denk diff --git a/tools/gen_eth_addr.c b/tools/gen_eth_addr.c index bf9d935..834163a 100644 --- a/tools/gen_eth_addr.c +++ b/tools/gen_eth_addr.c @@ -15,7 +15,7 @@ main(int argc, char *argv[]) { unsigned long ethaddr_low, ethaddr_high; - srand(time(0) | getpid()); + srand(time(0) + getpid()); /* * setting the 2nd LSB in the most significant byte of