Update the nk_random calls to use the new re-entrant-safe API.

This commit is contained in:
Nicholas J. Kain 2014-03-12 15:41:34 -04:00
parent 54a7f54a4a
commit 9bf79b6034
4 changed files with 6 additions and 2 deletions

View File

@ -31,6 +31,7 @@
#include <stdint.h>
#include <net/if.h>
#include "random.h"
struct client_state_t {
unsigned long long leaseStartTime;
@ -42,6 +43,7 @@ struct client_state_t {
int nlPortId;
uint32_t clientAddr, serverAddr, routerAddr;
uint32_t lease, renewTime, rebindTime, xid;
struct nk_random_state_u32 rnd32_state;
uint8_t routerArp[6], serverArp[6];
uint8_t using_dhcp_bpf, init, got_router_arp, got_server_arp;
};

View File

@ -636,7 +636,8 @@ int send_decline(struct client_state_t *cs, uint32_t server)
int send_release(struct client_state_t *cs)
{
struct dhcpmsg packet = init_packet(DHCPRELEASE, nk_random_u32());
struct dhcpmsg packet = init_packet(DHCPRELEASE,
nk_random_u32(&cs->rnd32_state));
packet.ciaddr = cs->clientAddr;
add_option_reqip(&packet, cs->clientAddr);
add_option_serverid(&packet, cs->serverAddr);

View File

@ -533,6 +533,7 @@ int main(int argc, char **argv)
} else if (ifch_pid > 0) {
close(pToIfchR);
close(pToNdhcW);
nk_random_u32_init(&cs.rnd32_state);
ndhc_main();
} else {
log_line("FATAL - failed to fork ndhc-ifch: %s", strerror(errno));

View File

@ -306,7 +306,7 @@ static void selecting_timeout(struct client_state_t *cs, long long nowts)
}
}
if (num_dhcp_requests == 0)
cs->xid = nk_random_u32();
cs->xid = nk_random_u32(&cs->rnd32_state);
send_discover(cs);
dhcp_wake_ts = nowts + delay_timeout(num_dhcp_requests);
num_dhcp_requests++;