]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blobdiff - src/initscripts/init.d/dnsmasq
dnsmasq: Fix appending arguments to the argument list.
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / dnsmasq
index 583e55ea2c3b1e3c6dade0331870e83b0eafc6cb..34eee0c26e8fbb2aa2bab5fe9b098c03d66ba8bd 100644 (file)
 . /etc/sysconfig/rc
 . ${rc_functions}
 
+# Pull custom configuration file
+if [ -e "/etc/sysconfig/dnsmasq" ]; then
+       . /etc/sysconfig/dnsmasq
+fi
+
+SHOW_SRV=1
+
+function dns_forward_args() {
+       local file="${1}"
+
+       # Do nothing if file is empty.
+       [ -s "${file}" ] || return
+
+       local cmdline
+
+       local enabled zone server remark
+       while IFS="," read -r enabled zone server remark; do
+               # Line must be enabled.
+               [ "${enabled}" = "on" ] || continue
+
+               cmdline="${cmdline} --server=/${zone}/${server}"
+       done < ${file}
+
+       echo "${cmdline}"
+}
+
+
 case "${1}" in
        start)
+               # kill already running copy of dnsmasq...
+               killproc /usr/sbin/dnsmasq 2>&1 > /dev/null
+
                boot_mesg "Starting Domain Name Service Proxy..."
                
                eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
-               ARGS=
-               [ "$DOMAIN_NAME_GREEN" != "" ] && ARGS="-s $DOMAIN_NAME_GREEN "
-               [ -e "/var/ipfire/red/active" ] && ARGS+="-r /var/ipfire/red/resolv.conf"
+               ARGS="$CUSTOM_ARGS"
+               [ "$DOMAIN_NAME_GREEN" != "" ] && ARGS="$ARGS -s $DOMAIN_NAME_GREEN"
                
+               echo > /var/ipfire/red/resolv.conf # Clear it
+               if [ -e "/var/ipfire/red/dns1" ]; then
+                   DNS1=$(cat /var/ipfire/red/dns1 2>/dev/null)
+                   if [ ! -z ${DNS1} ]; then
+                       echo "nameserver ${DNS1}" >> /var/ipfire/red/resolv.conf
+                   fi
+               fi
+               if [ -e "/var/ipfire/red/dns2" ]; then
+                   DNS2=$(cat /var/ipfire/red/dns2 2>/dev/null)
+                   if [ ! -z ${DNS2} ]; then
+                       echo "nameserver ${DNS2}" >> /var/ipfire/red/resolv.conf
+                   fi
+               fi
+               [ -e "/var/ipfire/red/active" ] && ARGS="$ARGS -r /var/ipfire/red/resolv.conf"
+       
+               ARGS="$ARGS --domain=`cat /var/ipfire/main/settings |grep DOMAIN |cut -d = -f 2`"
+
+               # Add custom forward dns zones.
+               ARGS="${ARGS} $(dns_forward_args /var/ipfire/dnsforward/config)"
+
                loadproc /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $ARGS
+               
+               if [ "${SHOW_SRV}" -eq 1 ] && [ "${DNS1}" != "" -o "${DNS2}" != "" ]; then
+                   boot_mesg "Using DNS server(s): ${DNS1} ${DNS2}"
+                   boot_mesg_flush
+               fi
                ;;
 
        stop)