What's new

YazFi YazFi DHCP lease times

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

eightiescalling

Senior Member
One for @Jack Yaz ....

I've been playing around with some automations linked to state of the DHCP pool and noticed that the lease times for YazFi configured DHCP pools are hard coded to a day.

Instead of hard coded to a day, what would you say to linking the DHCP lease timer to the config in LAN/DHCP Server tab? (Accessible from nvram using dhcp_lease)
 
These are tiny packets and the load of renewing devices once a day should be negligible. I'm curious what you're trying to achieve :)
 
I'm not worried about the network traffic. Quite the opposite - in my case I tend to use 1 hour lease times which if anything increases DHCP traffic as leases are renewed.

There is an existing script that feeds a bunch of information to Home Assistant including DHCP pool usage. That was being used to turn off the guest wifi network when there have been no clients on it for a while (instead of time limits that ASUS supports) - not as good as tacking things hooked to specific SSIDs but uses the setup I have.
 
Happy to put in a PR if Jack wants but in the meantime in the (unlikely!) event anyone else is interested, this patch links the YazFi DHCP leases to the broader DHCP lease time configuration:

Code:
--- YazFi.4.4.2    2022-11-29 09:18:07.959443800 +0000
+++ YazFi.4.4.3    2022-11-29 09:17:06.647625033 +0000
@@ -1868,8 +1868,10 @@
            
             ENABLED_WINS="$(nvram get smbd_wins)"
             ENABLED_SAMBA="$(nvram get enable_samba)"
+            DHCP_LEASETIME="$(nvram get dhcp_lease)"
             if ! Validate_Number "" "$ENABLED_SAMBA" silent; then ENABLED_SAMBA=0; fi
             if ! Validate_Number "" "$ENABLED_WINS" silent; then ENABLED_WINS=0; fi
+            if ! Validate_Number "" "$DHCP_LEASETIME" silent; then DHCP_LEASETIME=86400; fi
            
             ENABLED_NTPD=0
             if [ -f /jffs/scripts/nat-start ]; then
@@ -1884,7 +1886,7 @@
                 CONFADDSTRING="$CONFADDSTRING||||dhcp-option=$2,42,$(nvram get lan_ipaddr)"
             fi
            
-            CONFSTRING="interface=$2||||dhcp-range=$2,$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(eval echo '$'"$(Get_Iface_Var "$2")_DHCPSTART"),$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(eval echo '$'"$(Get_Iface_Var "$2")_DHCPEND"),255.255.255.0,86400s||||dhcp-option=$2,3,$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(nvram get lan_ipaddr | cut -f4 -d".")||||dhcp-option=$2,6,$(eval echo '$'"$(Get_Iface_Var "$2")_DNS1"),$(eval echo '$'"$(Get_Iface_Var "$2")_DNS2")$CONFADDSTRING"
+            CONFSTRING="interface=$2||||dhcp-range=$2,$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(eval echo '$'"$(Get_Iface_Var "$2")_DHCPSTART"),$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(eval echo '$'"$(Get_Iface_Var "$2")_DHCPEND"),255.255.255.0,${DHCP_LEASETIME}s||||dhcp-option=$2,3,$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(nvram get lan_ipaddr | cut -f4 -d".")||||dhcp-option=$2,6,$(eval echo '$'"$(Get_Iface_Var "$2")_DNS1"),$(eval echo '$'"$(Get_Iface_Var "$2")_DNS2")$CONFADDSTRING"
            
             BEGIN="### Start of script-generated configuration for interface $2 ###"
             END="### End of script-generated configuration for interface $2 ###"
 
Happy to put in a PR if Jack wants but in the meantime in the (unlikely!) event anyone else is interested, this patch links the YazFi DHCP leases to the broader DHCP lease time configuration:

Code:
--- YazFi.4.4.2    2022-11-29 09:18:07.959443800 +0000
+++ YazFi.4.4.3    2022-11-29 09:17:06.647625033 +0000
@@ -1868,8 +1868,10 @@
           
             ENABLED_WINS="$(nvram get smbd_wins)"
             ENABLED_SAMBA="$(nvram get enable_samba)"
+            DHCP_LEASETIME="$(nvram get dhcp_lease)"
             if ! Validate_Number "" "$ENABLED_SAMBA" silent; then ENABLED_SAMBA=0; fi
             if ! Validate_Number "" "$ENABLED_WINS" silent; then ENABLED_WINS=0; fi
+            if ! Validate_Number "" "$DHCP_LEASETIME" silent; then DHCP_LEASETIME=86400; fi
           
             ENABLED_NTPD=0
             if [ -f /jffs/scripts/nat-start ]; then
@@ -1884,7 +1886,7 @@
                 CONFADDSTRING="$CONFADDSTRING||||dhcp-option=$2,42,$(nvram get lan_ipaddr)"
             fi
           
-            CONFSTRING="interface=$2||||dhcp-range=$2,$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(eval echo '$'"$(Get_Iface_Var "$2")_DHCPSTART"),$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(eval echo '$'"$(Get_Iface_Var "$2")_DHCPEND"),255.255.255.0,86400s||||dhcp-option=$2,3,$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(nvram get lan_ipaddr | cut -f4 -d".")||||dhcp-option=$2,6,$(eval echo '$'"$(Get_Iface_Var "$2")_DNS1"),$(eval echo '$'"$(Get_Iface_Var "$2")_DNS2")$CONFADDSTRING"
+            CONFSTRING="interface=$2||||dhcp-range=$2,$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(eval echo '$'"$(Get_Iface_Var "$2")_DHCPSTART"),$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(eval echo '$'"$(Get_Iface_Var "$2")_DHCPEND"),255.255.255.0,${DHCP_LEASETIME}s||||dhcp-option=$2,3,$(eval echo '$'"$(Get_Iface_Var "$2")_IPADDR" | cut -f1-3 -d".").$(nvram get lan_ipaddr | cut -f4 -d".")||||dhcp-option=$2,6,$(eval echo '$'"$(Get_Iface_Var "$2")_DNS1"),$(eval echo '$'"$(Get_Iface_Var "$2")_DNS2")$CONFADDSTRING"
           
             BEGIN="### Start of script-generated configuration for interface $2 ###"
             END="### End of script-generated configuration for interface $2 ###"
patches always welcome!
 
Instead of hard coded to a day, what would you say to linking the DHCP lease timer to the config in LAN/DHCP Server tab? (Accessible from nvram using dhcp_lease)
My suggestion & preference would be to have greater flexibility with YazFi by keeping the "DHCP Lease Time" configuration option *separate* between the MAIN LAN (which uses the "dhcp_lease" NVRAM setting) & the GUEST WLANs. This can be done by having the "DHCP Lease Time" value for *each* GUEST network defined in the "/jffs/addons/YazFi.d/config" file.

For example:
...
wl01_ENABLED=true
wl01_IPADDR=172.26.225.0
wl01_DHCPSTART=2
wl01_DHCPEND=126
wl01_DHCPLEASE=172800
wl01_DNS1=9.9.9.9
wl01_DNS2=1.1.1.2
wl01_FORCEDNS=false
wl01_ALLOWINTERNET=true
wl01_REDIRECTALLTOVPN=false
wl01_VPNCLIENTNUMBER=1
wl01_TWOWAYTOGUEST=false
wl01_ONEWAYTOGUEST=false
wl01_CLIENTISOLATION=true
...
The user then has the option to set a different value from the initial default by manually setting the appropriate "wXXX_DHCPLEASE" variable in the config file to whatever valid DHCP lease time (in seconds) they so desire, independently of the setting for the MAIN network or any other GUEST networks.

Attached to this post is a text file (YazFi_v4.4.2.ORIG_vs_MOD_DIFFs.txt) containing the result of diffing the original YazFi script & the modified version with my code changes.
EDIT: Updated the DIFFs text file because I had the wrong file revision when running diff.

The modified script adds the corresponding variable "wXXX_DHCPLEASE" (when not found) for each GUEST network and sets the initial value (obtained via the cmd "nvram get dhcp_lease") in the "/jffs/addons/YazFi.d/config" file; from then on the user is free to modify the settings manually as they see fit.

I've been running this configuration setup for over 7 months now, and it's been working well so far. I like the flexibility of having a different DHCP lease time for each GUEST WLAN (e.g. one for IoTs devices, another for the GUEST network for relatives & friends that come to visit, etc.).

If you want to see, verify, or check out the changes I've made, the modified YazFi script is in PasteBin. You can download it directly onto your router with this cmd:
Bash:
curl -kLSs --retry 3 --retry-delay 5 --retry-connrefused pastebin.com/raw/qAJ7RgpJ | tr -d '\r' > "$HOME/YazFi_v4.4.2.MOD.sh"

P.S.
The modified script also includes a fix that I made as explained in this thread:
NOTE:
AFAICT, @Jack Yaz has not made the proposed changes for the fix in the old thread above since no new releases have been made since the "4.4.2" version.
 

Attachments

  • YazFi_v4.4.2.ORIG_vs_MOD_DIFFs.txt
    5.2 KB · Views: 55
Last edited:
Must admit, I did contemplate that but between the UI changes also needed and my use case it felt over the top.

Have you looked at the ASP changes or just the scripting side?
 
Must admit, I did contemplate that but between the UI changes also needed and my use case it felt over the top.

Have you looked at the ASP changes or just the scripting side?
I've looked at & made changes only to the shell script, not the related JavaScript/HTML code needed for support in the WebGUI. I haven't had a lot of practice in JavaScript programming, and I'm so used to a CLI that I don't miss the GUI portion (I don't make changes often enough I supposed, and honestly I rarely looked at the GUI). However, I can see where it would certainly be nice & useful to have the corresponding GUI support.
 
I tend to use the WebGUI to set but lack of practice on ASP/JS was the reason I went for the easy option.

I've not used ASP before but @Jack Yaz - Dare I ask the reason github shows line 164 of the ASP as being about 32K long! o_O I was tempted to have a go at the WebGUI side until I saw that!

(Of course needing a test router to avoid breaking things in the house just gives an excuse to replace the AC88U!)
 
I tend to use the WebGUI to set but lack of practice on ASP/JS was the reason I went for the easy option.

I've not used ASP before but @Jack Yaz - Dare I ask the reason github shows line 164 of the ASP as being about 32K long! o_O I was tempted to have a go at the WebGUI side until I saw that!

(Of course needing a test router to avoid breaking things in the house just gives an excuse to replace the AC88U!)
Well, my innate curiosity got me again, and it led me to look into the WebGUI support for the new "DHCP Lease Time" variables I have stored in the YazFi config file. It took me about 2 hours to study the JavaScript/HTML code, understand the framework I had to work with, and find all the "hooks" where new code needed to be placed to support the new config variable. Anyway, I have now written about 90% of the necessary code, and this is what I got so far.

RT-AC86U_YazFi_Mod.jpg


I've got to say, I found the existing GUI code well-organized, readable, fairly straightforward, and easy to follow. My hat's off to you, @Jack Yaz !

I believe tomorrow I should have some free time after work to finish writing the code and then start testing (after everybody here at home is done with their work/homework/entertaining/streaming and doesn't need the internet so I'm free to reboot the router if/when needed).

Just FYI.
 
I was going to take a look next week when things quietened down here but you beat me too it - looks like testing only by then. Let me know when you're done and I'll drop it on my router for a spin.

Agree on the code - gave me more insight on how the firmware works in general between UI and backend. That's why I was curious on the reason for the minified line!
 
I was going to take a look next week when things quietened down here but you beat me too it - looks like testing only by then. Let me know when you're done and I'll drop it on my router for a spin.

Agree on the code - gave me more insight on how the firmware works in general between UI and backend. That's why I was curious on the reason for the minified line!
I've finished making all the required changes to both the shell script and the JavaScript code and did some quick tests. The valid range of values for "DHCP Lease Time" is the same as the one defined in the built-in "LAN - DCHP Server" WebGUI tab. I haven't had the time to do more testing due to work commitments and family stuff, but here's another screenshot now showing the tooltip.

RT-AC86U_YazFi_Mod.jpg


I'd like to do some more testing before I issue a version so you can give it a try. Hopefully, this weekend I'll have more free time.
 
Let me know when you're done and I'll drop it on my router for a spin.
OK, I've done a bit of refactoring on the JavaScript source code that I added/modified and did more testing. So far it's working as intended on my RT-AC86U router (the only one I can test with).

If you want to "kick the tires" on this modified version, the files are now in PasteBin. There are 3 files to download: The YazFi script file, the YazFi webpage file, and a helper script that I wrote to assist with setting up the files for testing.

Bash:
curlOPTs="-kLSs --retry 3 --retry-delay 5 --retry-connrefused"
curl $curlOPTs pastebin.com/raw/S0jVxfhC | tr -d '\r' > /jffs/scripts/Setup_YazFi_TEST.sh
curl $curlOPTs pastebin.com/raw/B2AUvqS9 | tr -d '\r' > /jffs/scripts/YazFi.v4.4.2.MOD.sh
curl $curlOPTs pastebin.com/raw/QhD7kEJs | tr -d '\r' > /jffs/addons/YazFi.d/YazFi_www.asp.v4.4.2.MOD.ASP
chmod 755 /jffs/scripts/*.sh

The helper script makes testing much easier, and it can also help you go back to the previous YazFi files you had *before* setting up the new modified versions. This way you can avoid mixing up the set of files from your current setup with the test versions.

Once the files are downloaded, you could simply call the "Setup_YazFi_TEST.sh" script without any parameters.
Bash:
/jffs/scripts/Setup_YazFi_TEST.sh
When the helper script finishes the setup, you can go to the router WebGUI and check out the new "DHCP Lease" option. BTW, do *not* change the names of the modified YazFi files that were downloaded because the helper script is looking for them with the exact name specified above with the curl command.

Before you start, I'd recommend saving a copy of your current configuration file "/jffs/addons/YazFi.d/config" so you have a backup, just in case.

HTH
 
Thanks @Martinski . I've got those and taking a look through the changes - out of interest more than anything. It'll be tomorrow before I can start bouncing the wifi without getting hassle from the family now...
 
Thanks @Martinski . I've got those and taking a look through the changes - out of interest more than anything. It'll be tomorrow before I can start bouncing the wifi without getting hassle from the family now...
I was doing some more testing with my modified YazFi version so that I could "dot my i's and cross my t's" and make sure that I didn't break anything due to my recent code changes, and I found three GUI bugs (very trivial & really cosmetic) in the valid range validation for "DHCP Start" & "DHCP End" parameters. I did double-check the official YazFi installation, and the bugs were already there before my changes. As stated, the bugs are really cosmetic and do not actually result in any bad output or wrong action by the rest of the code.

In any case, my s/w developer "OCD tendencies" took over, and so I made fixes in both the shell script & the JavaScript source code.

Here are some screenshots of what was found and fixed:

RT-AC86U_YazFi_UImsg1.jpg



RT-AC86U_YazFi_UImsg2.jpg



RT-AC86U_YazFi_UImsg3.jpg


If you want to have the latest fixes/changes, all updated files are in PasteBin.
 
@Martinski, could you provide that link within PasteBin, please?
 
@Martinski, could you provide that link within PasteBin, please?
Do you mean the PasteBin URL for *each* file?

Here they are below, but keep this in mind:
BTW, do *not* change the names of the modified YazFi files that were downloaded because the helper script is looking for them with the exact name specified above with the curl command.
Also, if you get the files via the URLs, remember to check for proper EOL chars on the downloaded files and place them in the correct/expected folder in the router (this is why I like giving the curl commands that were provided earlier in post #16).

Setup_YazFi_TEST.sh

YazFi.v4.4.2.MOD.sh

YazFi_www.asp.v4.4.2.MOD.ASP
 
Last edited:

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top