udhcpd: account for script delay in lease
authorJohn Schroeder <jschroed@gmail.com>
Thu, 25 Dec 2014 20:12:51 +0000 (21:12 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 25 Dec 2014 20:12:51 +0000 (21:12 +0100)
Prevent nasty surprises if script runs longer than lease time / 2.

Signed-off-by: John Schroeder <jschroed@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/udhcp/dhcpc.c

index a34829c3a554ba85623f098e054c3e9a6ac7659b..9d3d1a31caf95647d06fd15215df8b5f45d8e029 100644 (file)
@@ -1752,7 +1752,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
                                }
 #endif
                                /* enter bound state */
-                               timeout = lease_seconds / 2;
                                temp_addr.s_addr = packet.yiaddr;
                                bb_info_msg("Lease of %s obtained, lease time %u",
                                        inet_ntoa(temp_addr), (unsigned)lease_seconds);
@@ -1761,6 +1760,11 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
                                start = monotonic_sec();
                                udhcp_run_script(&packet, state == REQUESTING ? "bound" : "renew");
                                already_waited_sec = (unsigned)monotonic_sec() - start;
+                               timeout = lease_seconds / 2;
+                               if ((unsigned)timeout < already_waited_sec) {
+                                       /* Something went wrong. Back to discover state */
+                                       timeout = already_waited_sec = 0;
+                               }
 
                                state = BOUND;
                                change_listen_mode(LISTEN_NONE);