isc-dhcp: fix handling multiple instances of 'routes' list
authorPhilip Prindeville <philipp@redfish-solutions.com>
Mon, 17 Jul 2023 21:27:09 +0000 (15:27 -0600)
committerPhilip Prindeville <philipp@redfish-solutions.com>
Sun, 30 Jul 2023 22:08:18 +0000 (16:08 -0600)
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
net/isc-dhcp/Makefile
net/isc-dhcp/files/dhcpd.init

index 906cae673790bff7de85a21425e924eef15aba12..8d3be4c91c54c4ba57b75c73323f25859e639bc1 100644 (file)
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=isc-dhcp
 UPSTREAM_NAME:=dhcp
 PKG_VERSION:=4.4.3-P1
-PKG_RELEASE:=4
+PKG_RELEASE:=5
 
 PKG_LICENSE:=BSD-3-Clause
 PKG_LICENSE_FILES:=LICENSE
index fd036c6ea403823a4022ac61ae430709c865f222..309d3ec87abfa37c4c3b2526ff8cd8602d64591c 100755 (executable)
@@ -138,29 +138,20 @@ create_empty_zone() {
 }
 
 append_routes() {
-       local tuple tuples="$1"
-       local string=
+       local tuple tuple="$(trim "$1")"
+       local network prefix router save octets compacted
 
-       local IFS=','
-       for tuple in $tuples; do
-               local network prefix router save octets compacted
+       save="${tuple% *}"
+       router="$(trim "${tuple#${save} }")"
 
-               tuple="$(trim "$tuple")"
+       network="$(trim "${save%/[0-9]*}")"
 
-               save="${tuple% *}"
-               router="$(trim "${tuple#${save} }")"
+       prefix="$(trim "${save##${network}/}")"
 
-               network="$(trim "${save%/[0-9]*}")"
+       octets=$((($prefix + 7) / 8))
+       compacted="$(echo "$network" | cut -d. -f1-$octets)"
 
-               prefix="$(trim "${save##${network}/}")"
-
-               octets=$((($prefix + 7) / 8))
-               compacted="$(echo "$network" | cut -d. -f1-$octets)"
-
-               string="${string:+, }$(explode "$prefix${compacted:+.$compacted}.$router")"
-       done
-
-       echo " option classless-ipv4-route $string;"
+       routes="$routes${routes:+, }$(explode "$prefix${compacted:+.$compacted}.$router")"
 }
 
 append_dhcp_options() {
@@ -308,6 +299,8 @@ static_host_add() {
                        extra_options="$extra_options${extra_options:+ }0f" ;;
                fqdn)
                        extra_options="$extra_options${extra_options:+ }51" ;;
+               routes)
+                       extra_options="$extra_options${extra_options:+ }79" ;;
                *)
                        echo "unknown option: $option" >&2 ;;
                esac
@@ -344,7 +337,11 @@ static_host_add() {
                if [ -n "$gateway" ] ; then
                        echo " option routers $gateway;"
                fi
+
+               local routes=
                config_list_foreach "$cfg" "routes" append_routes
+               [ -n "$routes" ] && echo " option classless-ipv4-route $routes;"
+
                config_list_foreach "$cfg" "dhcp_option" append_dhcp_options
                if [ -n "$extra_options" ]; then
                        echo -e " if exists dhcp-parameter-request-list {\n  option dhcp-parameter-request-list = concat(option dhcp-parameter-request-list, $extra_options);\n }"
@@ -391,7 +388,11 @@ gen_dhcp_subnet() {
                echo " option routers $gateway;"
        fi
        echo " option domain-name-servers $DNS;"
+
+       local routes=
        config_list_foreach "$cfg" "routes" append_routes
+       [ -n "$routes" ] && echo " option classless-ipv4-route $routes;"
+
        config_list_foreach "$cfg" "dhcp_option" append_dhcp_options
        echo "}"
 }