From 1be0c756c3a52e7b120da3e50be579d8e92ad5ac Mon Sep 17 00:00:00 2001 From: Anjali Nijhara Date: Fri, 22 Dec 2023 10:46:50 +0530 Subject: Reset timeval to default value when tv_sec parameter become invalid. Change-Id: I43fe8f9c252734aecb73a85776030d09ac51684b --- toys/pending/dhcpd.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/toys/pending/dhcpd.c b/toys/pending/dhcpd.c index 0a3a2c5..3bac14d 100644 --- a/toys/pending/dhcpd.c +++ b/toys/pending/dhcpd.c @@ -1707,6 +1707,13 @@ void dhcpd_main(void) int maxfd = (sigfd.rd > gstate.listensock)? sigfd.rd : gstate.listensock; dbg("select waiting ....\n"); + if (tv.tv_sec < 0) { + dbg("timestmp: %u waited: %u tv_sec: %u, reset tv_sec to default value\n", timestmp, waited, tv.tv_sec); + waited = 0; + tv.tv_sec = gconfig.auto_time - waited; + tv.tv_usec = 0; + } + retval = select(maxfd + 1, &rfds, NULL, NULL, (gconfig.auto_time?&tv:NULL)); if (retval < 0) { if (errno == EINTR) { @@ -2035,6 +2042,7 @@ void dhcpd_main(void) msgtype = DHCPNAK; optptr = set_optval(optptr, DHCP_OPT_MESSAGE_TYPE, &msgtype, 1); send_packet(1); + dbg("Send Message Type : DHCPNAK\n"); break; } get_optval((uint8_t*) &gstate.rcvd.rcvd_pkt.options, @@ -2045,6 +2053,7 @@ void dhcpd_main(void) optptr = set_optval(optptr, DHCP_OPT_LEASE_TIME, &reqested_lease, 4); optptr = set_reqparam(optptr, gstate.rqopt); send_packet(1); + dbg("Send Message Type : DHCPOFFER\n"); break; case DHCPREQUEST: msgtype = DHCPACK; @@ -2063,6 +2072,7 @@ void dhcpd_main(void) msgtype = DHCPNAK; optptr = set_optval(optptr, DHCP_OPT_MESSAGE_TYPE, &msgtype, 1); send_packet(1); + dbg("Send Message Type : DHCPNAK\n"); break; } get_reqparam(&gstate.rqopt); @@ -2072,6 +2082,7 @@ void dhcpd_main(void) optptr = set_optval(optptr, DHCP_OPT_LEASE_TIME, &reqested_lease, 4); optptr = set_reqparam(optptr, gstate.rqopt); send_packet(1); + dbg("Send Message Type : DHCPACK\n"); write_leasefile(); break; case DHCPDECLINE:// FALL THROUGH -- cgit v1.2.3