Replace the remaining calls to rand() with nk_random_u32().
This commit is contained in:
parent
009f80b428
commit
71db577ed5
@ -561,10 +561,11 @@ static int arp_is_query_reply(struct arpMsg *am)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int arp_gen_probe_wait(void)
|
||||
static int arp_gen_probe_wait(struct client_state_t *cs)
|
||||
{
|
||||
// This is not a uniform distribution but it doesn't matter here.
|
||||
return arp_probe_min + rand() % (arp_probe_max - arp_probe_min);
|
||||
return arp_probe_min + (nk_random_u32(&cs->rnd32_state) & 0x7fffffffu)
|
||||
% (arp_probe_max - arp_probe_min);
|
||||
}
|
||||
|
||||
static void arp_defense_timeout(struct client_state_t *cs, long long nowts)
|
||||
@ -642,7 +643,7 @@ static void arp_collision_timeout(struct client_state_t *cs, long long nowts)
|
||||
}
|
||||
if (arp_ip_anon_ping(cs, arp_dhcp_packet.yiaddr) == -1)
|
||||
log_warning("arp: Failed to send ARP ping in retransmission.");
|
||||
probe_wait_time = arp_gen_probe_wait();
|
||||
probe_wait_time = arp_gen_probe_wait(cs);
|
||||
arp_wake_ts[AS_COLLISION_CHECK] =
|
||||
arp_send_stats[ASEND_COLLISION_CHECK].ts + probe_wait_time;
|
||||
}
|
||||
|
@ -77,13 +77,14 @@ static const dhcp_state_t dhcp_states[] = {
|
||||
static unsigned int num_dhcp_requests;
|
||||
static long long dhcp_wake_ts = -1;
|
||||
|
||||
static int delay_timeout(size_t numpackets)
|
||||
static int delay_timeout(struct client_state_t *cs, size_t numpackets)
|
||||
{
|
||||
int to = 64;
|
||||
char tot[] = { 4, 8, 16, 32, 64 };
|
||||
if (numpackets < sizeof tot)
|
||||
to = tot[numpackets];
|
||||
return to * 1000 + rand() % 1000;
|
||||
// Distribution is a bit biased but it doesn't really matter.
|
||||
return to * 1000 + (nk_random_u32(&cs->rnd32_state) & 0x7fffffffu) % 1000;
|
||||
}
|
||||
|
||||
static void reinit_shared_deconfig(struct client_state_t *cs)
|
||||
@ -123,7 +124,7 @@ static void requesting_timeout(struct client_state_t *cs, long long nowts)
|
||||
{
|
||||
if (num_dhcp_requests < 5) {
|
||||
send_selecting(cs);
|
||||
dhcp_wake_ts = nowts + delay_timeout(num_dhcp_requests);
|
||||
dhcp_wake_ts = nowts + delay_timeout(cs, num_dhcp_requests);
|
||||
num_dhcp_requests++;
|
||||
} else
|
||||
reinit_selecting(cs, 0);
|
||||
@ -309,7 +310,7 @@ static void selecting_timeout(struct client_state_t *cs, long long nowts)
|
||||
if (num_dhcp_requests == 0)
|
||||
cs->xid = nk_random_u32(&cs->rnd32_state);
|
||||
send_discover(cs);
|
||||
dhcp_wake_ts = nowts + delay_timeout(num_dhcp_requests);
|
||||
dhcp_wake_ts = nowts + delay_timeout(cs, num_dhcp_requests);
|
||||
num_dhcp_requests++;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user