[U-Boot] [PATCH v2 03/21] net: Move MAC-seeded rand out of bootp.c
Joe Hershberger
joe.hershberger at gmail.com
Wed May 16 22:30:17 CEST 2012
Hi Simon,
On Fri, Apr 20, 2012 at 9:54 PM, Simon Glass <sjg at chromium.org> wrote:
> Hi Joe,
>
> On Tue, Mar 27, 2012 at 4:42 PM, Joe Hershberger <joe.hershberger at ni.com> wrote:
>> diff --git a/net/bootp.c b/net/bootp.c
>> index d0a7da2..5949e77 100644
>> --- a/net/bootp.c
>> +++ b/net/bootp.c
>> @@ -12,6 +12,9 @@
>> #include <command.h>
>> #include <net.h>
>> #include "bootp.h"
>> +#ifdef CONFIG_BOOTP_RANDOM_DELAY
>> +#include "net_rand.h"
>> +#endif
>
> How about just always including it?
OK.
>> #include "tftp.h"
>> #include "nfs.h"
>> #ifdef CONFIG_STATUS_LED
>> diff --git a/net/net_rand.c b/net/net_rand.c
>> new file mode 100644
>> index 0000000..744e2f9
>> --- /dev/null
>> +++ b/net/net_rand.c
>> @@ -0,0 +1,68 @@
>> +/*
>> + * Based on LiMon - BOOTP.
>> + *
>> + * Copyright 1994, 1995, 2000 Neil Russell.
>> + * (See License)
>> + * Copyright 2000 Roland Borde
>> + * Copyright 2000 Paolo Scaffardi
>> + * Copyright 2000-2004 Wolfgang Denk, wd at denx.de
>> + */
>> +
>> +#include <common.h>
>> +#include <net.h>
>> +#include "net_rand.h"
>> +
>> +static ulong seed1, seed2;
>> +
>> +void srand_mac(void)
>
> Perhaps pass in the place to put the random mac, rather than using a global?
In this case it is using the env to read the mac. It is not creating
a random mac. The point is to create a random number based on the MAC
so that the numbers vary from device to device in the absence of other
entropy. In the link-local case it also should lead to the same
device choosing the same address each time by default and most likely
different than other devices.
In the future I could make it take an index for which MAC address to
seed with, but for now, using the first is best suited to its
application.
>> +{
>> + ulong tst1, tst2, m_mask;
>> + ulong m_value = 0;
>> + int reg;
>> + unsigned char bi_enetaddr[6];
>> +
>> + /* get our mac */
>> + eth_getenv_enetaddr("ethaddr", bi_enetaddr);
>> diff --git a/net/net_rand.h b/net/net_rand.h
>> new file mode 100644
>> index 0000000..8569f93
>> --- /dev/null
>> +++ b/net/net_rand.h
>> @@ -0,0 +1,17 @@
>> +/*
>> + * Copied from LiMon - BOOTP.
>> + *
>> + * Copyright 1994, 1995, 2000 Neil Russell.
>> + * (See License)
>> + * Copyright 2000 Paolo Scaffardi
>> + */
>> +
>> +#ifndef __NET_RAND_H__
>> +#define __NET_RAND_H__
>> +
>> +#define RAND_MAX 0xFFFFFFFF
>
> Do we want lower case hex? Not sure.
OK
>> +
>> +void srand_mac(void);
>> +unsigned long rand(void);
>
> Function comments are nice :-)
OK
>> +
>> +#endif /* __NET_RAND_H__ */
>> --
Thanks,
-Joe
More information about the U-Boot
mailing list