dnsmasq: rework network interface ignore
[openwrt/staging/jow.git] / package / network / services / dnsmasq / files / dnsmasq.init
index 510d328cd23bd1f231169bdf912711e18a285299..c5e673029187555d1a81e8ec88fefb18b39c08d1 100755 (executable)
@@ -547,15 +547,6 @@ dhcp_add() {
 
        [ -n "$netmask" ] && prefix_or_netmask="$netmask"
 
-       #check for an already active dhcp server on the interface, unless 'force' is set
-       config_get_bool force "$cfg" force 0
-       [ $force -gt 0 ] || dhcp_check "$ifname" || {
-               logger -t dnsmasq \
-                       "found already running DHCP-server on interface '$ifname'" \
-                       "refusing to start, use 'option force 1' to override"
-               return 0
-       }
-
        config_get start "$cfg" start 100
        config_get limit "$cfg" limit 150
        config_get leasetime "$cfg" leasetime 12h
@@ -899,6 +890,12 @@ dnsmasq_start()
                xappend "--conf-file=${dnsmasqconffile}"
        }
 
+       config_get_bool boguspriv "$cfg" boguspriv 1
+       [ "$boguspriv" -gt 0 ] && {
+               xappend "--bogus-priv"
+               [ -r "$RFC6761FILE" ] && xappend "--conf-file=$RFC6761FILE"
+       }
+
        $PROG --version | grep -osqE "^Compile time options:.* DHCPv6( |$)" && DHCPv6CAPABLE=1 || DHCPv6CAPABLE=0
 
 
@@ -961,7 +958,25 @@ dnsmasq_start()
        config_get tftp_root "$cfg" "tftp_root"
        [ -n "$tftp_root" ] && mkdir -p "$tftp_root" && append_bool "$cfg" enable_tftp "--enable-tftp"
        append_bool "$cfg" tftp_no_fail "--tftp-no-fail"
-       append_bool "$cfg" nonwildcard "--bind-dynamic" 1
+
+       config_get bind "$cfg" "bind"
+       case "$bind" in
+               dynamic|interfaces)
+                       xappend "--bind-$bind"
+                       ;;
+               "")
+                       # for compatibility reasons
+                       append_bool "$cfg" nonwildcard "--bind-dynamic" 1
+                       ;;
+       esac
+
+       config_get dnsfilter "$cfg" "dnsfilter"
+       case "$dnsfilter" in
+               A|AAAA)
+                       xappend "--filter-$dnsfilter"
+                       ;;
+       esac
+
        append_bool "$cfg" fqdn "--dhcp-fqdn"
        append_bool "$cfg" proxydnssec "--proxy-dnssec"
        append_bool "$cfg" localservice "--local-service"
@@ -1009,8 +1024,8 @@ dnsmasq_start()
                xappend "--addn-hosts=$HOSTFILE"
                append EXTRA_MOUNT "$HOSTFILE"
        else
-               xappend "--addn-hosts=$HOSTFILE_DIR"
-               append EXTRA_MOUNT "$HOSTFILE_DIR"
+               xappend "--addn-hosts=$(dirname $HOSTFILE)"
+               append EXTRA_MOUNT "$(dirname $HOSTFILE)"
        fi
        config_list_foreach "$cfg" "addnhosts" append_addnhosts
        config_list_foreach "$cfg" "bogusnxdomain" append_bogusnxdomain
@@ -1114,7 +1129,6 @@ dnsmasq_start()
 
        xappend "--dhcp-broadcast=tag:needs-broadcast"
 
-
        config_get dnsmasqconfdir "$cfg" confdir "/tmp/dnsmasq.d"
        xappend "--conf-dir=$dnsmasqconfdir"
        dnsmasqconfdir="${dnsmasqconfdir%%,*}"
@@ -1156,11 +1170,6 @@ dnsmasq_start()
        config_foreach filter_dnsmasq mxhost dhcp_mx_add "$cfg"
        echo >> $CONFIGFILE_TMP
 
-       config_get_bool boguspriv "$cfg" boguspriv 1
-       [ "$boguspriv" -gt 0 ] && {
-               xappend "--bogus-priv"
-               [ -r "$RFC6761FILE" ] && xappend "--conf-file=$RFC6761FILE"
-       }
 
        if [ "$DNSMASQ_DHCP_VER" -gt 4 ] ; then
                # Enable RA feature for when/if it is constructed,
@@ -1244,10 +1253,11 @@ dnsmasq_stop()
 
 add_interface_trigger()
 {
-       local interface ignore
+       local interface ifname ignore
 
        config_get interface "$1" interface
        config_get_bool ignore "$1" ignore 0
+       network_get_device ifname "$interface" || ignore=0
 
        [ -n "$interface" ] && [ $ignore -eq 0 ] && procd_add_interface_trigger "interface.*" "$interface" /etc/init.d/dnsmasq reload
 }