From cdd5af4b21c44fdccb8df47672d0e40524a8cc1b Mon Sep 17 00:00:00 2001 From: Philip Prindeville Date: Thu, 10 Sep 2020 10:16:09 -0600 Subject: [PATCH] isc-dhcp: add support for RFC-3442 classless routes to hosts Also avoid forward references to functions. Signed-off-by: Philip Prindeville --- net/isc-dhcp/Makefile | 2 +- net/isc-dhcp/files/dhcpd.init | 129 +++++++++++++++++----------------- 2 files changed, 66 insertions(+), 65 deletions(-) diff --git a/net/isc-dhcp/Makefile b/net/isc-dhcp/Makefile index 5f0f75652..9ec28a453 100644 --- a/net/isc-dhcp/Makefile +++ b/net/isc-dhcp/Makefile @@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=isc-dhcp UPSTREAM_NAME:=dhcp PKG_VERSION:=4.4.1 -PKG_RELEASE:=8 +PKG_RELEASE:=9 PKG_LICENSE:=BSD-3-Clause PKG_LICENSE_FILES:=LICENSE diff --git a/net/isc-dhcp/files/dhcpd.init b/net/isc-dhcp/files/dhcpd.init index 2a1111697..7dfe127cd 100755 --- a/net/isc-dhcp/files/dhcpd.init +++ b/net/isc-dhcp/files/dhcpd.init @@ -57,70 +57,6 @@ hex_to_hostid() { return 0 } -static_host_add() { - local cfg="$1" - local broadcast hostid macn macs mac name ip leasetime - - config_get macs "$cfg" "mac" - [ -n "$macs" ] || return 0 - config_get name "$cfg" "name" - [ -n "$name" ] || return 0 - config_get ip "$cfg" "ip" - [ -n "$ip" ] || return 0 - - config_get_bool broadcast "$cfg" "broadcast" 0 - config_get dns "$cfg" "dns" - config_get gateway "$cfg" "gateway" - config_get leasetime "$cfg" "leasetime" - if [ -n "$leasetime" ] ; then - leasetime="$(time2seconds "$leasetime")" - [ "$?" -ne 0 ] && return 1 - fi - - config_get hostid "$cfg" "hostid" - if [ -n "$hostid" ] ; then - hex_to_hostid hostid "$hostid" || return 1 - fi - - macn=0 - for mac in $macs; do - macn=$(( macn + 1 )) - done - - for mac in $macs; do - local secname="$name" - if [ $macn -gt 1 ] ; then - secname="${name}-${mac//:}" - fi - echo "host $secname {" - echo " hardware ethernet $mac;" - echo " fixed-address $ip;" - echo " option host-name \"$name\";" - if [ "$broadcast" -eq 1 ] ; then - echo " always-broadcast true;" - fi - if [ -n "$leasetime" ] ; then - echo " default-lease-time $leasetime;" - echo " max-lease-time $leasetime;" - fi - if [ -n "$hostid" ] ; then - echo " option dhcp-client-identifier $hostid;" - fi - if [ -n "$dns" ] ; then - echo " option domain-name-servers $dns;" - fi - if [ -n "$gateway" ] ; then - echo " option routers $gateway;" - fi - config_list_foreach "$cfg" "dhcp_option" append_dhcp_options - echo "}" - done -} - -static_hosts() { - config_foreach static_host_add host "$@" -} - typeof() { echo "$1" | awk ' /^\d+\.\d+\.\d+\.\d+$/ { print "ip\n"; next; } @@ -186,6 +122,71 @@ append_dhcp_options() { echo " option $tag $formatted;" } +static_host_add() { + local cfg="$1" + local broadcast hostid macn macs mac name ip leasetime + + config_get macs "$cfg" "mac" + [ -n "$macs" ] || return 0 + config_get name "$cfg" "name" + [ -n "$name" ] || return 0 + config_get ip "$cfg" "ip" + [ -n "$ip" ] || return 0 + + config_get_bool broadcast "$cfg" "broadcast" 0 + config_get dns "$cfg" "dns" + config_get gateway "$cfg" "gateway" + config_get leasetime "$cfg" "leasetime" + if [ -n "$leasetime" ] ; then + leasetime="$(time2seconds "$leasetime")" + [ "$?" -ne 0 ] && return 1 + fi + + config_get hostid "$cfg" "hostid" + if [ -n "$hostid" ] ; then + hex_to_hostid hostid "$hostid" || return 1 + fi + + macn=0 + for mac in $macs; do + macn=$(( macn + 1 )) + done + + for mac in $macs; do + local secname="$name" + if [ $macn -gt 1 ] ; then + secname="${name}-${mac//:}" + fi + echo "host $secname {" + echo " hardware ethernet $mac;" + echo " fixed-address $ip;" + echo " option host-name \"$name\";" + if [ "$broadcast" -eq 1 ] ; then + echo " always-broadcast true;" + fi + if [ -n "$leasetime" ] ; then + echo " default-lease-time $leasetime;" + echo " max-lease-time $leasetime;" + fi + if [ -n "$hostid" ] ; then + echo " option dhcp-client-identifier $hostid;" + fi + if [ -n "$dns" ] ; then + echo " option domain-name-servers $dns;" + fi + if [ -n "$gateway" ] ; then + echo " option routers $gateway;" + fi + config_list_foreach "$cfg" "routes" append_routes + config_list_foreach "$cfg" "dhcp_option" append_dhcp_options + echo "}" + done +} + +static_hosts() { + config_foreach static_host_add host "$@" +} + gen_dhcp_subnet() { local cfg="$1"