dnsmasq: refuse to add empty DHCP range
authorLeon M. George <leon@georgemail.eu>
Sun, 8 May 2022 21:29:06 +0000 (23:29 +0200)
committerChristian Marangi <ansuelsmth@gmail.com>
Tue, 7 Feb 2023 20:05:57 +0000 (21:05 +0100)
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@georgemail.eu>
package/network/services/dnsmasq/files/dnsmasq.init

index d3928c23993a890f0744a4b6ce5d59717b3072b7..21e330ec28c1a00d5b5a2c9cfd81bbfa812f321f 100755 (executable)
@@ -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.