From 4df035ced379e529658c1e6e45154556ab10eea0 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Mon, 19 Oct 2020 05:39:08 -0400 Subject: [PATCH] Make sure xids in packets sent conform to RFC2131 pg36 table5. --- src/ndhc.c | 1 + src/state.c | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ndhc.c b/src/ndhc.c index 2dc5894..62e55a9 100644 --- a/src/ndhc.c +++ b/src/ndhc.c @@ -544,6 +544,7 @@ int main(int argc, char *argv[]) parse_cmdline(argc, argv); nk_random_init(&cs.rnd_state); + cs.xid = nk_random_u32(&cs.rnd_state); if (getuid()) suicide("I need to be started as root."); diff --git a/src/state.c b/src/state.c index 64d1509..3466f59 100644 --- a/src/state.c +++ b/src/state.c @@ -75,6 +75,7 @@ static int delay_timeout(struct client_state_t cs[static 1], size_t numpackets) static void reinit_shared_deconfig(struct client_state_t cs[static 1]) { + cs->xid = nk_random_u32(&cs->rnd_state); cs->clientAddr = 0; cs->num_dhcp_requests = 0; cs->server_arp_sent = 0; @@ -289,6 +290,7 @@ static int selecting_packet(struct client_state_t cs[static 1], client_config.interface); return ANP_IGNORE; } + cs->xid = packet->xid; // Use for subsequent DHCPREQUESTs cs->clientAddr = packet->yiaddr; cs->serverAddr = sid; cs->srcAddr = srcaddr; @@ -351,8 +353,6 @@ static int selecting_timeout(struct client_state_t cs[static 1], } else if (client_config.abort_if_no_lease) suicide("%s: No lease; failing.", client_config.interface); } - if (cs->num_dhcp_requests == 0) - cs->xid = nk_random_u32(&cs->rnd_state); if (send_discover(cs) < 0) { log_warning("%s: Failed to send a discover request packet.", client_config.interface); @@ -450,7 +450,6 @@ int dhcp_handle(struct client_state_t cs[static 1], long long nowts, { scrBegin; reinit: - cs->xid = nk_random_u32(&cs->rnd_state); // We're in the SELECTING state here. for (;;) { int ret = COR_SUCCESS;