Subject: Re: kernel ip_randomid() and libc randomid(3) still "broken"
To: Jun-ichiro itojun Hagino <itojun@itojun.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-net
Date: 11/26/2003 08:37:31
Jun-ichiro itojun Hagino wrote:

> > 	ip_randomid() and friends are all corrected.  they have the desired
> > 	property of having certain amount of gap between appearance of the
> > 	same output.  now, could I make RANDOM_IP_ID default to 1 so that it
> > 	will be compiled in always (less #define is always better)?
> > 	we have ip_do_randomid variable so people can enable/disable it as they
> > 	wish.
> 
> 	btw here's the analysis code i used today.  this is openbsd
> 	ip_random.c with some mods.  "ru_seed2 + ru_x" is suggested by provos
> 	and has the non-repeating property.  the commit i made was the removal
> 	of ru_seed2.

Even with this code, the gap still settles down to just under 12000 and
not the 36000 advertised in the manpage.  src/regress/lib/libc/randomid
still fails because of this.  See this following bit of code:

> X	/* Skip a random number of ids */
> X	n = tmp & 0x3; tmp = tmp >> 2;
> X	if (ru_counter + n >= RU_MAX)
> X		ip_initid();
> X
> X	for (i = 0; i <= n; i++)
> X		/* Linear Congruential Generator */
> X		ru_x = (ru_a * ru_x + ru_b) % RU_M;

While we throw away up to 3 random numbers each time we ask for a single
random number, we're always going to have a minimum gap of approximately
1/3rd the theoretical gap.

Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD Support and Service:         http://www.wasabisystems.com/