dnsmasq: support dhcp_option config as a list
[openwrt/openwrt.git] / package / network / services / dnsmasq / files / dnsmasq.init
index 51b841bcb49e62368fb85d44f700c692b2fbe4d9..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() {
@@ -655,13 +672,14 @@ dhcp_relay_add() {
        if [ -z "$interface" ]; then
                xappend "--dhcp-relay=$local_addr,$server_addr"
        else
-               xappend "--dhcp-relay=$local_addr,$server_addr,$interface"
+               network_get_device ifname "$interface" || return
+               xappend "--dhcp-relay=$local_addr,$server_addr,$ifname"
        fi
 }
 
 dnsmasq_start()
 {
-       local cfg="$1" disabled
+       local cfg="$1" disabled resolvfile
 
        config_get_bool disabled "$cfg" disabled 0
        [ "$disabled" -gt 0 ] && return 0
@@ -697,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
 
 
@@ -719,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"
@@ -766,7 +793,6 @@ dnsmasq_start()
        config_list_foreach "$cfg" "addnhosts" append_addnhosts
        config_list_foreach "$cfg" "bogusnxdomain" append_bogusnxdomain
        append_parm "$cfg" "leasefile" "--dhcp-leasefile" "/tmp/dhcp.leases"
-       append_parm "$cfg" "resolvfile" "--resolv-file" "/tmp/resolv.conf.auto"
        append_parm "$cfg" "serversfile" "--servers-file"
        append_parm "$cfg" "tftp_root" "--tftp-root"
        append_parm "$cfg" "dhcp_boot" "--dhcp-boot"
@@ -788,7 +814,6 @@ dnsmasq_start()
        config_get_bool readethers "$cfg" readethers
        [ "$readethers" = "1" -a \! -e "/etc/ethers" ] && touch /etc/ethers
 
-       config_get resolvfile $cfg resolvfile
        config_get dhcpscript $cfg dhcpscript
 
        config_get leasefile $cfg leasefile "/tmp/dhcp.leases"
@@ -802,6 +827,8 @@ dnsmasq_start()
                [ -n "$resolvfile" -a \! -e "$resolvfile" ] && touch "$resolvfile"
        fi
 
+       [ -n "$resolvfile" ] && xappend "--resolv-file=$resolvfile"
+
        config_get hostsfile "$cfg" dhcphostsfile
        [ -e "$hostsfile" ] && xappend "--dhcp-hostsfile=$hostsfile"