[openwrt/openwrt] dnsmasq: refuse to add empty DHCP range

LEDE Commits lede-commits at lists.infradead.org
Tue Feb 7 12:09:37 PST 2023


ansuel pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/e4bd3de1be8e3d49f9663a300e8b821ecca4be11

commit e4bd3de1be8e3d49f9663a300e8b821ecca4be11
Author: Leon M. George <leon at georgemail.eu>
AuthorDate: Sun May 8 23:29:06 2022 +0200

    dnsmasq: refuse to add empty DHCP range
    
    Use ipcalc's return value to react to invalid range specifications.
    By simply ignoring the range instead of aborting with an error code,
    dnsmasq should still start when there's an error (best effort).
    Aborting the config generation or working with invalid range specs leaves
    dnsmasq crash-looping which is the right thing to do concerning that
    particular interface but it also hinders DHCP service on other interfaces
    and DNS on the router itself.
    
    Signed-off-by: Leon M. George <leon at georgemail.eu>
---
 package/network/services/dnsmasq/files/dnsmasq.init | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init
index d3928c2399..21e330ec28 100755
--- a/package/network/services/dnsmasq/files/dnsmasq.init
+++ b/package/network/services/dnsmasq/files/dnsmasq.init
@@ -584,21 +584,20 @@ dhcp_add() {
 		limit=$((limit-1))
 	fi
 
-	eval "$(ipcalc.sh "${subnet%%/*}" $netmask $start $limit)"
+	# make sure the DHCP range is not empty
+	if [ "$dhcpv4" != "disabled" ] && eval "$(ipcalc.sh "${subnet%%/*}" "$netmask" "$start" "$limit")" ; then
+		[ "$dynamicdhcp" = "0" ] && END="static"
+
+		xappend "--dhcp-range=$tags$nettag$START,$END,$NETMASK,$leasetime${options:+ $options}"
+	fi
 
 	if [ "$dynamicdhcp" = "0" ] ; then
-		END="static"
 		dhcp6range="::,static"
 	else
 		dhcp6range="::1000,::ffff"
 	fi
 
 
-	if [ "$dhcpv4" != "disabled" ] ; then
-		xappend "--dhcp-range=$tags$nettag$START,$END,$NETMASK,$leasetime${options:+ $options}"
-	fi
-
-
 	if [ $DNSMASQ_DHCP_VER -eq 6 ] && [ "$ra" = "server" ] ; then
 		# Note: dnsmasq cannot just be a DHCPv6 server (all-in-1)
 		# and let some other machine(s) send RA pointing to it.




More information about the lede-commits mailing list