aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/utils.c
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@osdl.org>2006-10-17 03:09:42 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-17 11:18:43 -0400
commitaaa248f6c9c81b2683db7dbb0689cd5ed1c86d88 (patch)
tree106d9ce5ebac4175b0fb97ff80a92e399fcf2a33 /net/core/utils.c
parent0187f879ee8d4b914e74ffa3cc5df268311fc2d2 (diff)
[PATCH] rename net_random to random32
Make net_random() more widely available by calling it random32 akpm: hopefully this will permit the removal of carta_random32. That needs confirmation from Stephane - this code looks somewhat more computationally expensive, and has a different (ie: callee-stateful) interface. [akpm@osdl.org: lots of build fixes, cleanups] Signed-off-by: Stephen Hemminger <shemminger@osdl.org> Signed-off-by: David S. Miller <davem@davemloft.net> Cc: Stephane Eranian <eranian@hpl.hp.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'net/core/utils.c')
-rw-r--r--net/core/utils.c116
1 files changed, 0 insertions, 116 deletions
diff --git a/net/core/utils.c b/net/core/utils.c
index 94c5d761c830..d93fe64f6693 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -30,119 +30,6 @@
30#include <asm/system.h> 30#include <asm/system.h>
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32 32
33/*
34 This is a maximally equidistributed combined Tausworthe generator
35 based on code from GNU Scientific Library 1.5 (30 Jun 2004)
36
37 x_n = (s1_n ^ s2_n ^ s3_n)
38
39 s1_{n+1} = (((s1_n & 4294967294) <<12) ^ (((s1_n <<13) ^ s1_n) >>19))
40 s2_{n+1} = (((s2_n & 4294967288) << 4) ^ (((s2_n << 2) ^ s2_n) >>25))
41 s3_{n+1} = (((s3_n & 4294967280) <<17) ^ (((s3_n << 3) ^ s3_n) >>11))
42
43 The period of this generator is about 2^88.
44
45 From: P. L'Ecuyer, "Maximally Equidistributed Combined Tausworthe
46 Generators", Mathematics of Computation, 65, 213 (1996), 203--213.
47
48 This is available on the net from L'Ecuyer's home page,
49
50 http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme.ps
51 ftp://ftp.iro.umontreal.ca/pub/simulation/lecuyer/papers/tausme.ps
52
53 There is an erratum in the paper "Tables of Maximally
54 Equidistributed Combined LFSR Generators", Mathematics of
55 Computation, 68, 225 (1999), 261--269:
56 http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme2.ps
57
58 ... the k_j most significant bits of z_j must be non-
59 zero, for each j. (Note: this restriction also applies to the
60 computer code given in [4], but was mistakenly not mentioned in
61 that paper.)
62
63 This affects the seeding procedure by imposing the requirement
64 s1 > 1, s2 > 7, s3 > 15.
65
66*/
67struct nrnd_state {
68 u32 s1, s2, s3;
69};
70
71static DEFINE_PER_CPU(struct nrnd_state, net_rand_state);
72
73static u32 __net_random(struct nrnd_state *state)
74{
75#define TAUSWORTHE(s,a,b,c,d) ((s&c)<<d) ^ (((s <<a) ^ s)>>b)
76
77 state->s1 = TAUSWORTHE(state->s1, 13, 19, 4294967294UL, 12);
78 state->s2 = TAUSWORTHE(state->s2, 2, 25, 4294967288UL, 4);
79 state->s3 = TAUSWORTHE(state->s3, 3, 11, 4294967280UL, 17);
80
81 return (state->s1 ^ state->s2 ^ state->s3);
82}
83
84static void __net_srandom(struct nrnd_state *state, unsigned long s)
85{
86 if (s == 0)
87 s = 1; /* default seed is 1 */
88
89#define LCG(n) (69069 * n)
90 state->s1 = LCG(s);
91 state->s2 = LCG(state->s1);
92 state->s3 = LCG(state->s2);
93
94 /* "warm it up" */
95 __net_random(state);
96 __net_random(state);
97 __net_random(state);
98 __net_random(state);
99 __net_random(state);
100 __net_random(state);
101}
102
103
104unsigned long net_random(void)
105{
106 unsigned long r;
107 struct nrnd_state *state = &get_cpu_var(net_rand_state);
108 r = __net_random(state);
109 put_cpu_var(state);
110 return r;
111}
112
113
114void net_srandom(unsigned long entropy)
115{
116 struct nrnd_state *state = &get_cpu_var(net_rand_state);
117 __net_srandom(state, state->s1^entropy);
118 put_cpu_var(state);
119}
120
121void __init net_random_init(void)
122{
123 int i;
124
125 for_each_possible_cpu(i) {
126 struct nrnd_state *state = &per_cpu(net_rand_state,i);
127 __net_srandom(state, i+jiffies);
128 }
129}
130
131static int net_random_reseed(void)
132{
133 int i;
134 unsigned long seed;
135
136 for_each_possible_cpu(i) {
137 struct nrnd_state *state = &per_cpu(net_rand_state,i);
138
139 get_random_bytes(&seed, sizeof(seed));
140 __net_srandom(state, seed);
141 }
142 return 0;
143}
144late_initcall(net_random_reseed);
145
146int net_msg_cost = 5*HZ; 33int net_msg_cost = 5*HZ;
147int net_msg_burst = 10; 34int net_msg_burst = 10;
148 35
@@ -153,10 +40,7 @@ int net_ratelimit(void)
153{ 40{
154 return __printk_ratelimit(net_msg_cost, net_msg_burst); 41 return __printk_ratelimit(net_msg_cost, net_msg_burst);
155} 42}
156
157EXPORT_SYMBOL(net_random);
158EXPORT_SYMBOL(net_ratelimit); 43EXPORT_SYMBOL(net_ratelimit);
159EXPORT_SYMBOL(net_srandom);
160 44
161/* 45/*
162 * Convert an ASCII string to binary IP. 46 * Convert an ASCII string to binary IP.