/* Pseudorandom numbers */
+long brandom(void);
u32 random_u32(void);
void random_init(void);
+void random_init_thread(void);
void random_bytes(void *buf, size_t size);
when = loop->last_time + t->recurrent;
if (t->randomize)
- when += random() % (t->randomize + 1);
+ when += brandom() % (t->randomize + 1);
tm_set(t, when);
}
TRACE(D_EVENTS, "Starting interface %s", ifa->ifname);
- ifa->next_hello = current_time() + (random() % ifa->cf->hello_interval);
- ifa->next_regular = current_time() + (random() % ifa->cf->update_interval);
+ ifa->next_hello = current_time() + (brandom() % ifa->cf->hello_interval);
+ ifa->next_regular = current_time() + (brandom() % ifa->cf->update_interval);
ifa->next_triggered = current_time() + MIN(1 S, ifa->cf->update_interval / 2);
ifa->want_triggered = 0; /* We send an immediate update (below) */
tm_start(ifa->timer, 100 MS);
log(L_WARN "%s: Missing IPv4 next hop address for %s", p->p.name, ifa->ifname);
if (ifa->next_hello > (current_time() + new->hello_interval))
- ifa->next_hello = current_time() + (random() % new->hello_interval);
+ ifa->next_hello = current_time() + (brandom() % new->hello_interval);
if (ifa->next_regular > (current_time() + new->update_interval))
- ifa->next_regular = current_time() + (random() % new->update_interval);
+ ifa->next_regular = current_time() + (brandom() % new->update_interval);
if (new->check_link != old->check_link)
babel_iface_update_state(ifa);
babel_randomize_router_id(struct babel_proto *p)
{
p->router_id &= (u64) 0xffffffff;
- p->router_id |= ((u64) random()) << 32;
+ p->router_id |= ((u64) brandom()) << 32;
TRACE(D_EVENTS, "Randomized router ID to %lR", p->router_id);
}
timer *t;
int rv, timeout;
+ random_init_thread();
+
birdloop_set_current(loop);
tmp_init(loop->pool);
{
/* The randomization procedure is specified in RFC 4271 section 10 */
btime time = value S;
- btime randomize = random() % ((time / 4) + 1);
+ btime randomize = brandom() % ((time / 4) + 1);
tm_start(t, time - randomize);
}
else
ifa->last = now;
btime t = ifa->cf->min_ra_int S;
btime r = (ifa->cf->max_ra_int - ifa->cf->min_ra_int) S;
- t += random() % (r + 1);
+ t += brandom() % (r + 1);
if (ifa->initial)
{
if (! ifa->cf->demand_circuit)
{
- ifa->next_regular = current_time() + (random() % ifa->cf->update_time) + 100 MS;
+ ifa->next_regular = current_time() + (brandom() % ifa->cf->update_time) + 100 MS;
tm_set(ifa->timer, ifa->next_regular);
}
else
if ((! ifa->cf->demand_circuit) &&
(ifa->next_regular > (current_time() + new->update_time)))
- ifa->next_regular = current_time() + (random() % new->update_time) + 100 MS;
+ ifa->next_regular = current_time() + (brandom() % new->update_time) + 100 MS;
if (ifa->up && new->demand_circuit && (new->passive != old->passive))
{
log_switch(1, NULL, NULL);
random_init();
+ random_init_thread();
resource_init();
timer_init();
olock_init();
#include <sys/random.h>
#endif
+_Thread_local unsigned short random_state[3];
+
+long
+brandom(void)
+{
+ return jrand48(random_state);
+}
u32
random_u32(void)
{
long int rand_low, rand_high;
- rand_low = random();
- rand_high = random();
+ rand_low = brandom();
+ rand_high = brandom();
return (rand_low & 0xffff) | ((rand_high & 0xffff) << 16);
}
void
random_init(void)
{
- uint seed;
-
- /* Get random bytes to trip any errors early and to seed random() */
- random_bytes(&seed, sizeof(seed));
+ /* No global init needed */
+}
- srandom(seed);
+void
+random_init_thread(void)
+{
+ /* Initialize thread-local random structure */
+ random_bytes(random_state, sizeof random_state);
}
void
log_init_debug("");
log_switch(1, NULL, NULL);
+ random_init();
+ random_init_thread();
+
resource_init();
ev_init_list(&global_event_list);