aboutsummaryrefslogtreecommitdiff
path: root/net/isc-dhcp/files
diff options
context:
space:
mode:
authorPhilip Prindeville <philipp@redfish-solutions.com>2018-03-25 02:17:52 -0600
committerPhilip Prindeville <philipp@redfish-solutions.com>2018-03-29 20:12:03 -0600
commita0cd1691c35e9f1bbee85efe68e6692084501de2 (patch)
tree57da9fe7cc7a8e642f1b58d4f752c6f00635a7d7 /net/isc-dhcp/files
parent05ca13e17c29938ddf26a5e7050eb1fa7bae9b66 (diff)
isc-dhcp: support generic DHCP options
Allow specifying NTP servers, search domains, etc. by the administrator directly specifying DHCP options (per interface, i.e. per pool). Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Diffstat (limited to 'net/isc-dhcp/files')
-rw-r--r--net/isc-dhcp/files/dhcpd.init40
1 files changed, 39 insertions, 1 deletions
diff --git a/net/isc-dhcp/files/dhcpd.init b/net/isc-dhcp/files/dhcpd.init
index 453adfa81..fdcbe2490 100644
--- a/net/isc-dhcp/files/dhcpd.init
+++ b/net/isc-dhcp/files/dhcpd.init
@@ -120,7 +120,44 @@ static_hosts() {
config_foreach static_host_add host "$@"
}
+typeof() {
+ echo "$1" | awk '
+/^\d+\.\d+\.\d+\.d+$/ { print "ip\n"; next; }
+/^(true|false)$/ { print "bool\n"; next; }
+/^\d+$/ { print "integer\n"; next; }
+/^"[^"]*"$/ { print "string\n"; next; }
+ { print "other\n"; next; }
+'
+}
+
+append_dhcp_options() {
+ local tuple="$1"
+
+ # strip redundant "option:" prefix
+ tuple="${tuple#option:}"
+
+ local tag="${tuple%%,*}"
+ local values="${tuple#$tag,}"
+
+ local formatted value
+ local IFS=$', \n'
+ for value in $values; do
+ # detect type of $value and quote if necessary
+ case $(typeof "$value") in
+ ip|bool|integer|string)
+ ;;
+ other)
+ value="\"$value\""
+ ;;
+ esac
+ formatted="$formatted${formatted:+, }$value"
+ done
+ echo " option $tag $formatted;"
+}
+
gen_dhcp_subnet() {
+ local cfg="$1"
+
echo "subnet $NETWORK netmask $NETMASK {"
echo " range $START $END;"
echo " option subnet-mask $netmask;"
@@ -140,6 +177,7 @@ gen_dhcp_subnet() {
fi
echo " option routers $gateway;"
echo " option domain-name-servers $DNS;"
+ config_list_foreach "$cfg" "dhcp_option" append_dhcp_options
echo "}"
}
@@ -193,7 +231,7 @@ dhcpd_add() {
gateway="$IP"
fi
- gen_dhcp_subnet >> $config_file
+ gen_dhcp_subnet "$cfg" >> $config_file
}
general_config() {