diff options
-rw-r--r-- | networking/udhcp/dhcpc.c | 14 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index e9a841204..ca82d37e6 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -407,11 +407,19 @@ static ALWAYS_INLINE uint32_t random_xid(void) | |||
407 | /* Initialize the packet with the proper defaults */ | 407 | /* Initialize the packet with the proper defaults */ |
408 | static void init_packet(struct dhcp_packet *packet, char type) | 408 | static void init_packet(struct dhcp_packet *packet, char type) |
409 | { | 409 | { |
410 | uint16_t secs; | ||
411 | |||
410 | /* Fill in: op, htype, hlen, cookie fields; message type option: */ | 412 | /* Fill in: op, htype, hlen, cookie fields; message type option: */ |
411 | udhcp_init_header(packet, type); | 413 | udhcp_init_header(packet, type); |
412 | 414 | ||
413 | packet->xid = random_xid(); | 415 | packet->xid = random_xid(); |
414 | 416 | ||
417 | client_config.last_secs = monotonic_sec(); | ||
418 | if (client_config.first_secs == 0) | ||
419 | client_config.first_secs = client_config.last_secs; | ||
420 | secs = client_config.last_secs - client_config.first_secs; | ||
421 | packet->secs = htons(secs); | ||
422 | |||
415 | memcpy(packet->chaddr, client_config.client_mac, 6); | 423 | memcpy(packet->chaddr, client_config.client_mac, 6); |
416 | if (client_config.clientid) | 424 | if (client_config.clientid) |
417 | udhcp_add_binary_option(packet, client_config.clientid); | 425 | udhcp_add_binary_option(packet, client_config.clientid); |
@@ -848,6 +856,7 @@ static void change_listen_mode(int new_mode) | |||
848 | /* else LISTEN_NONE: sockfd stays closed */ | 856 | /* else LISTEN_NONE: sockfd stays closed */ |
849 | } | 857 | } |
850 | 858 | ||
859 | /* Called only on SIGUSR1 */ | ||
851 | static void perform_renew(void) | 860 | static void perform_renew(void) |
852 | { | 861 | { |
853 | bb_info_msg("Performing a DHCP renew"); | 862 | bb_info_msg("Performing a DHCP renew"); |
@@ -1260,6 +1269,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1260 | case BOUND: | 1269 | case BOUND: |
1261 | /* 1/2 lease passed, enter renewing state */ | 1270 | /* 1/2 lease passed, enter renewing state */ |
1262 | state = RENEWING; | 1271 | state = RENEWING; |
1272 | client_config.first_secs = 0; /* make secs field count from 0 */ | ||
1263 | change_listen_mode(LISTEN_KERNEL); | 1273 | change_listen_mode(LISTEN_KERNEL); |
1264 | log1("Entering renew state"); | 1274 | log1("Entering renew state"); |
1265 | /* fall right through */ | 1275 | /* fall right through */ |
@@ -1299,6 +1309,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1299 | bb_info_msg("Lease lost, entering init state"); | 1309 | bb_info_msg("Lease lost, entering init state"); |
1300 | udhcp_run_script(NULL, "deconfig"); | 1310 | udhcp_run_script(NULL, "deconfig"); |
1301 | state = INIT_SELECTING; | 1311 | state = INIT_SELECTING; |
1312 | client_config.first_secs = 0; /* make secs field count from 0 */ | ||
1302 | /*timeout = 0; - already is */ | 1313 | /*timeout = 0; - already is */ |
1303 | packet_num = 0; | 1314 | packet_num = 0; |
1304 | continue; | 1315 | continue; |
@@ -1315,6 +1326,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1315 | /* note: udhcp_sp_read checks FD_ISSET before reading */ | 1326 | /* note: udhcp_sp_read checks FD_ISSET before reading */ |
1316 | switch (udhcp_sp_read(&rfds)) { | 1327 | switch (udhcp_sp_read(&rfds)) { |
1317 | case SIGUSR1: | 1328 | case SIGUSR1: |
1329 | client_config.first_secs = 0; /* make secs field count from 0 */ | ||
1318 | perform_renew(); | 1330 | perform_renew(); |
1319 | if (state == RENEW_REQUESTED) | 1331 | if (state == RENEW_REQUESTED) |
1320 | goto case_RENEW_REQUESTED; | 1332 | goto case_RENEW_REQUESTED; |
@@ -1446,6 +1458,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1446 | udhcp_run_script(NULL, "deconfig"); | 1458 | udhcp_run_script(NULL, "deconfig"); |
1447 | change_listen_mode(LISTEN_RAW); | 1459 | change_listen_mode(LISTEN_RAW); |
1448 | state = INIT_SELECTING; | 1460 | state = INIT_SELECTING; |
1461 | client_config.first_secs = 0; /* make secs field count from 0 */ | ||
1449 | requested_ip = 0; | 1462 | requested_ip = 0; |
1450 | timeout = tryagain_timeout; | 1463 | timeout = tryagain_timeout; |
1451 | packet_num = 0; | 1464 | packet_num = 0; |
@@ -1493,6 +1506,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1493 | change_listen_mode(LISTEN_RAW); | 1506 | change_listen_mode(LISTEN_RAW); |
1494 | sleep(3); /* avoid excessive network traffic */ | 1507 | sleep(3); /* avoid excessive network traffic */ |
1495 | state = INIT_SELECTING; | 1508 | state = INIT_SELECTING; |
1509 | client_config.first_secs = 0; /* make secs field count from 0 */ | ||
1496 | requested_ip = 0; | 1510 | requested_ip = 0; |
1497 | timeout = 0; | 1511 | timeout = 0; |
1498 | packet_num = 0; | 1512 | packet_num = 0; |
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h index 9ef053a1b..2b3599120 100644 --- a/networking/udhcp/dhcpc.h +++ b/networking/udhcp/dhcpc.h | |||
@@ -21,6 +21,9 @@ struct client_config_t { | |||
21 | uint8_t *vendorclass; /* Optional vendor class-id to use */ | 21 | uint8_t *vendorclass; /* Optional vendor class-id to use */ |
22 | uint8_t *hostname; /* Optional hostname to use */ | 22 | uint8_t *hostname; /* Optional hostname to use */ |
23 | uint8_t *fqdn; /* Optional fully qualified domain name to use */ | 23 | uint8_t *fqdn; /* Optional fully qualified domain name to use */ |
24 | |||
25 | uint16_t first_secs; | ||
26 | uint16_t last_secs; | ||
24 | } FIX_ALIASING; | 27 | } FIX_ALIASING; |
25 | 28 | ||
26 | /* server_config sits in 1st half of bb_common_bufsiz1 */ | 29 | /* server_config sits in 1st half of bb_common_bufsiz1 */ |