aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpc.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-03-12 05:37:54 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-03-12 05:37:54 +0100
commit9ac5596a5154d789964150737a784dc4db98265b (patch)
tree4a3e3906516ebf078729e056b3f2562cb3ba81ee /networking/udhcp/dhcpc.c
parentea684c6aaf23ead57fac74c3ceaa651c1ae625ec (diff)
downloadbusybox-w32-9ac5596a5154d789964150737a784dc4db98265b.tar.gz
busybox-w32-9ac5596a5154d789964150737a784dc4db98265b.tar.bz2
busybox-w32-9ac5596a5154d789964150737a784dc4db98265b.zip
udhcpc: emit "correct" secs field
In theory, sending secs set to constant zero should be ok too. But some bleeping servers can actually be configured to answer ONLY if secs is bigger than a preset value (!!) http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man8/bootpd.8.html grep for "reply_threshold_seconds" function old new delta udhcpc_main 2573 2623 +50 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r--networking/udhcp/dhcpc.c14
1 files changed, 14 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 */
408static void init_packet(struct dhcp_packet *packet, char type) 408static 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 */
851static void perform_renew(void) 860static 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;