[LEDE-DEV] Fw: [openwrt/luci] BUG: DHCP Leases "infinite" time shows as "expired" not as "unlimited" in IPv4 (#963)

Daniel Dickinson lede-daniel at cshore.thecshore.com
Thu Jan 19 22:58:45 PST 2017

Hi Hans,

In LuCI GitHub issue 963 (https://github.com/openwrt/luci/issues/963),
a user discovered that LuCI incorrectly reports dnsmasq infinite
leasetime as expired because the LuCI check is based on odhcpd's -1 for
INFINITE_VALID, but dnsmasq uses 0 in the dhcp.leases file for
infinite leases.  Would it be preferable to sync odhcpd and dnsmasq
(I know odhcpd at one time used 0 for INFINITE_VALID in the statefile
but that that was changed, and I don't know why).  From a LuCI point of
view I'm not sure if there some caveat with the 0 value (I seem to
recall odhcpd uses 0 to represent something other than infinite, but I
could be wrong).  Before hacking on LuCI for the dnsmasq case I want to
make sure I understand what values are going to be found in the odhcpd

User's findings (last comment only) reproduced below.



Begin forwarded message:

Date: Thu, 19 Jan 2017 22:38:34 -0800
From: NvrBst <notifications at github.com>
To: openwrt/luci <luci at noreply.github.com>
<mention at noreply.github.com> Subject: Re: [openwrt/luci] BUG: DHCP
Leases "infinite" time shows as "expired" not as "unlimited" in IPv4

I see! Upon looking, _dnsmasq_ stores infinite leases as "0" in the
_/tmp/dhcp.leases_ file. This corresponds to the _01/01/1970 00:00:00
GMT_, in Unix EPOCH time. Since today's date is "1484889355". But the
expires property is (EXPIRY DATE - TODAYS DATE). So it's 0-1484889355.
So any value below -1484889355 works.

So if someone wanted to do a dnsmasq infinite check properly you could:

1. Check the _/tmp/dhcp.leases_ file and see if it has a 0 as the time.
2. Since the DHCP Lease Table is pulling its information from:

3. `XHR.poll(5, '<%=url('admin/network/dhcplease_status')%>'`
4. Going to the URL:
_http:// shows
that it only gives the expiry conversion, and not the original expiry
date. So someone would have to alter the structs and put the expiry
time, and original EXPIRY DATE. Then you can use that and check to see
if it's 0 for an infinite lease --- More work. 5. The leases[i].expires
property is just EXPIRY DATE - CURRENT DATE. So you could reverse this
calculation and check to see if it's 0. Of course, playing with time
can be smudgy with rounding.

Option 2 is probably the cleanest, Option 3 is the easiest. So if we
were doing 3, we can just do the check in these two files as:

					if (info.leases[i].expires ===
false || Math.trunc((new Date().getTime()/1000 +
info.leases[i].expires)/10) == 0) timestr = '<em><%:unlimited%></em>';
else if (info.leases[i].expires <= 0) timestr = '<em><%:expired%></em>';

You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/lede-dev/attachments/20170120/09b21917/attachment.html>

More information about the Lede-dev mailing list