dnsmasq: support dhcp_option config as a list
[openwrt/openwrt.git] / package / network / services / dnsmasq / files / dnsmasq.init
index 5f69be79b40997dd9f6fa5648b415e0235fd8604..4291df2544bafe10947bd2155ee9ac7f895a21e6 100644 (file)
@@ -538,6 +538,14 @@ dhcp_add() {
        dhcp_option_add "$cfg" "$networkid"
 }
 
+dhcp_option_append() {
+       local option="$1"
+       local networkid="$2"
+       local force="$3"
+
+       xappend "--dhcp-option${force:+-force}=${networkid:+$networkid,}$option"
+}
+
 dhcp_option_add() {
        # NOTE: dnsmasq has explicit "option6:" prefix for DHCPv6 so no collisions
        local cfg="$1"
@@ -546,11 +554,20 @@ dhcp_option_add() {
 
        [ "$force" = "0" ] && force=
 
-       config_get dhcp_option "$cfg" dhcp_option
-       for o in $dhcp_option; do
-               xappend "--dhcp-option${force:+-force}=${networkid:+$networkid,}$o"
-       done
+       local list_len
+       config_get list_len "$cfg" dhcp_option_LENGTH
 
+       if [ -n "$list_len" ]; then
+               config_list_foreach "$cfg" dhcp_option dhcp_option_append "$networkid" "$force"
+       else
+               echo "Warning: the 'option dhcp_option' syntax is deprecated, use 'list dhcp_option'" >&2
+               config_get dhcp_option "$cfg" dhcp_option
+
+               local option
+               for option in $dhcp_option; do
+                       dhcp_option_append "$option" "$networkid" "$force"
+               done
+       fi
 }
 
 dhcp_domain_add() {
@@ -698,7 +715,7 @@ dnsmasq_start()
 
        if [ -x /usr/sbin/odhcpd -a -x /etc/init.d/odhcpd ] ; then
                local odhcpd_is_main odhcpd_is_enabled
-               config_get odhcpd_is_main odhcpd maindhcp
+               config_get odhcpd_is_main odhcpd maindhcp 0
                /etc/init.d/odhcpd enabled && odhcpd_is_enabled=1 || odhcpd_is_enabled=0
 
 
@@ -720,6 +737,15 @@ dnsmasq_start()
                DNSMASQ_DHCP_VER=4
        fi
 
+       # Allow DHCP/DHCPv6 to be handled by ISC DHCPD
+       if [ -x /usr/sbin/dhcpd ] ; then
+               if [ -x /etc/init.d/dhcpd ] ; then
+                       /etc/init.d/dhcpd enabled && DNSMASQ_DHCP_VER=0
+               fi
+               if [ -x /etc/init.d/dhcpd6 -a "$DNSMASQ_DHCP_VER" -gt 0 ] ; then
+                       /etc/init.d/dhcpd6 enabled && DNSMASQ_DHCP_VER=4
+               fi
+       fi
 
        append_bool "$cfg" authoritative "--dhcp-authoritative"
        append_bool "$cfg" nodaemon "--no-daemon"