bootp-*|\
pxe-*)
[ -z "$dnsmasq_has_dhcp" ] ;;
- dnssec-*|\
+ dnssec*|\
trust-anchor)
- [ -z "$dnsmasq_has_dnssec" ] ;;
+ if [ -z "$dnsmasq_has_dnssec" ]; then
+ echo "dnsmasq: \"$opt\" requested, but dnssec support is not available" >&2
+ exit 1
+ fi
+ return 1
+ ;;
tftp-*)
[ -z "$dnsmasq_has_tftp" ] ;;
ipset)
[ -s "$stamp" ] && return $(cat "$stamp")
- # If there's no carrier yet, skip this interface.
+ # If interface is down, skip it.
# The init script will be called again once the link is up
- case "$(devstatus "$ifname" | jsonfilter -e @.carrier)" in
+ case "$(devstatus "$ifname" | jsonfilter -e @.up)" in
false) return 1;;
esac
udhcpc -n -q -s /bin/true -t 1 -i "$ifname" >&- && rv=1 || rv=0
- [ $rv -eq 1 ] && \
- logger -t dnsmasq \
- "found already running DHCP-server on interface '$ifname'" \
- "refusing to start, use 'option force 1' to override"
-
echo $rv > "$stamp"
return $rv
}
}
append_rev_server() {
- xappend "--rev-server=$1"
+ xappend "--rev-server=$1"
}
append_address() {
#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" || return 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
fi
}
+dnsmasq_ipset_add() {
+ local cfg="$1"
+ local ipsets domains
+
+ add_ipset() {
+ ipsets="${ipsets:+$ipsets,}$1"
+ }
+
+ add_domain() {
+ # leading '/' is expected
+ domains="$domains/$1"
+ }
+
+ config_list_foreach "$cfg" "name" add_ipset
+ config_list_foreach "$cfg" "domain" add_domain
+
+ if [ -z "$ipsets" ] || [ -z "$domains" ]; then
+ return 0
+ fi
+
+ xappend "--ipset=$domains/$ipsets"
+}
+
dnsmasq_start()
{
local cfg="$1"
append_bool "$cfg" noresolv "--no-resolv"
append_bool "$cfg" localise_queries "--localise-queries"
append_bool "$cfg" readethers "--read-ethers"
- append_bool "$cfg" dbus "--enable-dbus"
- append_bool "$cfg" ubus "--enable-ubus" 1
+
+ local instance_name="dnsmasq.$cfg"
+ if [ "$cfg" = "$DEFAULT_INSTANCE" ]; then
+ instance_name="dnsmasq"
+ fi
+ config_get_bool dbus "$cfg" "dbus" 0
+ [ $dbus -gt 0 ] && xappend "--enable-dbus=uk.org.thekelleys.$instance_name"
+ config_get_bool ubus "$cfg" "ubus" 1
+ [ $ubus -gt 0 ] && xappend "--enable-ubus=$instance_name"
+
append_bool "$cfg" expandhosts "--expand-hosts"
config_get tftp_root "$cfg" "tftp_root"
[ -n "$tftp_root" ] && mkdir -p "$tftp_root" && append_bool "$cfg" enable_tftp "--enable-tftp"
append_parm "$cfg" "minport" "--min-port"
append_parm "$cfg" "maxport" "--max-port"
append_parm "$cfg" "domain" "--domain"
- append_parm "$cfg" "local" "--server"
+ append_parm "$cfg" "local" "--local"
config_list_foreach "$cfg" "listen_address" append_listenaddress
config_list_foreach "$cfg" "server" append_server
config_list_foreach "$cfg" "rev_server" append_rev_server
append_parm "$cfg" "min_cache_ttl" "--min-cache-ttl"
append_parm "$cfg" "max_cache_ttl" "--max-cache-ttl"
append_parm "$cfg" "pxe_prompt" "--pxe-prompt"
+ append_parm "$cfg" "tftp_unique_root" "--tftp-unique-root"
config_list_foreach "$cfg" "pxe_service" append_pxe_service
config_get DOMAIN "$cfg" domain
xappend "--dhcp-broadcast=tag:needs-broadcast"
- xappend "--addn-hosts=$(dirname $HOSTFILE)"
+ config_get_bool ignore_hosts_dir "$cfg" ignore_hosts_dir 0
+ if [ "$ignore_hosts_dir" = "1" ]; then
+ xappend "--addn-hosts=$HOSTFILE"
+ else
+ xappend "--addn-hosts=$(dirname $HOSTFILE)"
+ fi
config_get dnsmasqconfdir "$cfg" confdir "/tmp/dnsmasq.d"
xappend "--conf-dir=$dnsmasqconfdir"
config_foreach filter_dnsmasq cname dhcp_cname_add "$cfg"
echo >> $CONFIGFILE_TMP
+ echo >> $CONFIGFILE_TMP
+ config_foreach filter_dnsmasq ipset dnsmasq_ipset_add "$cfg"
+ echo >> $CONFIGFILE_TMP
+
echo >> $CONFIGFILE_TMP
mv -f $CONFIGFILE_TMP $CONFIGFILE
mv -f $HOSTFILE_TMP $HOSTFILE
echo "search $DOMAIN" >> /tmp/resolv.conf
}
DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
+ [ -e /proc/sys/net/ipv6 ] && DNS_SERVERS="$DNS_SERVERS ::1"
for DNS_SERVER in $DNS_SERVERS ; do
echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
done
start_service() {
local instance="$1"
local instance_found=0
+ local first_instance=""
. /lib/functions/network.sh
if [ -n "$instance" ] && [ "$instance" = "$name" ]; then
instance_found=1
fi
+ if [ -z "$DEFAULT_INSTANCE" ]; then
+ local disabled
+ config_get_bool disabled "$name" disabled 0
+ if [ "$disabled" -eq 0 ]; then
+ # First enabled section will be assigned default instance name.
+ # Unnamed sections get precedence over named sections.
+ if expr "$cfg" : 'cfg[0-9a-f]*$' >/dev/null = "9"; then # See uci_fixup_section.
+ DEFAULT_INSTANCE="$name" # Unnamed config section.
+ elif [ -z "$first_instance" ]; then
+ first_instance="$name"
+ fi
+ fi
+ fi
fi
}
+ DEFAULT_INSTANCE=""
config_load dhcp
+ if [ -z "$DEFAULT_INSTANCE" ]; then
+ DEFAULT_INSTANCE="$first_instance" # No unnamed config section was found.
+ fi
if [ -n "$instance" ]; then
[ "$instance_found" -gt 0 ] || return