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
case.

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

Regards,

Daniel

Begin forwarded message:

Date: Thu, 19 Jan 2017 22:38:34 -0800
From: NvrBst <notificati...@github.com>
To: openwrt/luci <l...@noreply.github.com>
Mention
<ment...@noreply.github.com> Subject: Re: [openwrt/luci] BUG: DHCP
Leases "infinite" time shows as "expired" not as "unlimited" in IPv4
(#963)


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://192.168.0.1/cgi-bin/luci/admin/network/dhcplease_status_ 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:

_luci/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm
luci/modules/luci-mod-admin-full/luasrc/view/admin_network/lease_status.htm_
```
                                        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:
https://github.com/openwrt/luci/issues/963#issuecomment-273989416

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://192.168.0.1/cgi-bin/luci/admin/network/dhcplease_status 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:

luci/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm
luci/modules/luci-mod-admin-full/luasrc/view/admin_network/lease_status.htm

					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, view it on GitHub, or mute the thread.

_______________________________________________
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev

Reply via email to