diff --git a/ndhc/config.h b/ndhc/config.h index 10cd4ce..a65ca23 100644 --- a/ndhc/config.h +++ b/ndhc/config.h @@ -31,6 +31,7 @@ #include #include +#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; }; diff --git a/ndhc/dhcp.c b/ndhc/dhcp.c index 9b337fe..9d08dfc 100644 --- a/ndhc/dhcp.c +++ b/ndhc/dhcp.c @@ -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); diff --git a/ndhc/ndhc.c b/ndhc/ndhc.c index ac5c38d..4b12961 100644 --- a/ndhc/ndhc.c +++ b/ndhc/ndhc.c @@ -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)); diff --git a/ndhc/state.c b/ndhc/state.c index 20a89b0..1f7eefd 100644 --- a/ndhc/state.c +++ b/ndhc/state.c @@ -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++;