[PATCH] udhcpd: account for script delay in lease

Denys Vlasenko vda.linux at googlemail.com
Thu Dec 25 20:15:41 UTC 2014


On Mon, Dec 22, 2014 at 6:57 AM, John Schroeder <jschroed at gmail.com> wrote:
> That solution is much better and simpler. It nicely covers the typical case
> of a short delay caused by scripts.
>
> The thing wrong with immediately going to the renew state is that the renew
> state could continue after the lease expired. (Possibly only a late renew
> request but the unlikely worst-case scenario being a renew attempt after the
> lease expired.)
>
> It might be superfluous but how about going to the discover state (init
> selecting) if the timeout (half the lease time) has been exceeded? This
> correctly handles the case when the lease has expired. The very rare case of
> being in the last half of the lease is also dealt with cleanly (rather than
> continuing beyond the lease expiration).
>
> Below is a patch with a check if the timeout is exceeded. I am not certain
> if it is worth the trade off of having the extra code but it does handle
> these cases. Again, this case is very unlikely so it might not be worth
> having this code since the current code (plus script duration) would work
> most of the time.
>
>
> Signed-off-by: John Schroeder <jschroed at gmail.com>
> --- a/networking/udhcp/dhcpc.c
> +++ b/networking/udhcp/dhcpc.c
> @@ -1742,7 +1742,14 @@
>                  bb_info_msg("Lease of %s obtained, lease time %u",
>                      inet_ntoa(temp_addr), (unsigned)lease_seconds);
>                  requested_ip = packet.yiaddr;
> +
> +                timestamp_before_wait = monotonic_sec();
>                  udhcp_run_script(&packet, state == REQUESTING ? "bound" :
> "renew");
> +                already_waited_sec = (unsigned)monotonic_sec() -
> timestamp_before_wait;
> +
> +                if (already_waited_sec > timeout) { /* immediately go to
> discover */
> +                    timeout = 0;
> +                }
>
>                  state = BOUND;
>                  change_listen_mode(LISTEN_NONE);
> @@ -1760,7 +1767,6 @@
>  #endif
>                  /* make future renew packets use different xid */
>                  /* xid = random_xid(); ...but why bother? */
> -                already_waited_sec = 0;
>                  continue; /* back to main loop */
>              }
>              if (*message == DHCPNAK) {


Applied, thanks.


More information about the busybox mailing list