LuCI calculates the Expiry based on the interface uptime and leasetime.
If that is the only way to know it, it’s not very reliable, I think. My wan uptime can easily exeed 100 days, and my leasetime is 2 hours. If I loose 30 seconds on each lease renew, the remaining leasetime is off by 5 hours, after 100 days.
Looking in htop at the commandline for ohhcpc, it seems it calls /etc/netifd/dhcpv6.script on renew. That script calls the scripts in /etc/odhcp6c.user.d/ (or /etc/udhcpc.user.d/ for dhcpv4). So you could put a script there, which at least creates a timestamp file for the last renew. Combined with the leasetime you should be done.
That is true. My lease time has fluctuated lately between 1 hour and 2 hours, so it isn’t going to be accurate. My point was to show that it isn’t stored anywhere. It’s guessed at on-the-fly by LuCI.
Client requests Renew at half-life of initial lease time
If not honoured, client will request Renew again at half-life of remaining lease time and will repeat this cycle until Renewal Lease is issued (exponential backoff), or lease expires.
If Renewal fails
Client broadcasts a DHCPDISCOVER message.
Client will wait for DHCPOFFER and will establish new renewal from DHCPOFFER Server .
If client cannot reach a DHCP server ¯\_(ツ)_/¯(can't remember ever encountering this scenario). Maybe link-local addressing?
So answer should be REMAINING_LEASE_Time=(CURRENT_time - RENEW_time)
I’m marking this as the solution - thanks @dave14305 - even though it may not be conceptually 100% accurate - it appears that it is as good/accurate as it (LUCI/OpenWRT/Linux/my-ISP-provider) gets.
I just wanted to aggregate a few things and make them available through my Home Assistant instance. At this point its easy to SNMP-extend this … and graph it over time.
My original/simplest-case thought was that Remaining Time would decrease and at t=0, it would renew… pretty clear that this may not be the case.
This will vary by what your particular ISP sets for their customers. In my case I get a 5 min (300 sec) lease, so my syslog gets spammed every 2.5 min (150 secs) with a Request/Renew (my ISP honours every Request without fail). On the other hand, an ISP I worked for used a server that at certain heavy volume periods would ignore Requests until the load decreased before issuing a Renew and another ISP ignored Requests until the last possible instance before issuing a Renew
You can use logread -e udhcpc over your 24 hr. Lease time to see how your ISP handles it.