48b9d19d02627f9d8c829f958a5febfc5ebe5c28
[ipfire-2.x.git] / src / initscripts / init.d / dnsmasq
1 #!/bin/sh
2 ########################################################################
3 # Begin $rc_base/init.d/dnsmasq
4 #
5 # Description : dnsmasq init script
6 #
7 # Authors : Michael Tremer - mitch@ipfire.org
8 #
9 # Version : 01.00
10 #
11 # Notes :
12 #
13 ########################################################################
14
15 . /etc/sysconfig/rc
16 . ${rc_functions}
17
18 # Pull custom configuration file
19 if [ -e "/etc/sysconfig/dnsmasq" ]; then
20 . /etc/sysconfig/dnsmasq
21 fi
22
23 CACHE_SIZE=2500
24 ENABLE_DNSSEC=1
25 SHOW_SRV=1
26 TRUST_ANCHOR=".,19036,8,2,49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5"
27
28 function dnssec_args() {
29 local cmdline="--dnssec"
30
31 if [ -n "${TRUST_ANCHOR}" ]; then
32 cmdline="${cmdline} --trust-anchor=${TRUST_ANCHOR}"
33 fi
34
35 echo "${cmdline}"
36 }
37
38 function dns_forward_args() {
39 local file="${1}"
40
41 # Do nothing if file is empty.
42 [ -s "${file}" ] || return
43
44 local cmdline
45
46 local enabled zone server remark
47 while IFS="," read -r enabled zone server remark; do
48 # Line must be enabled.
49 [ "${enabled}" = "on" ] || continue
50
51 cmdline="${cmdline} --server=/${zone}/${server}"
52 done < ${file}
53
54 echo "${cmdline}"
55 }
56
57 case "${1}" in
58 start)
59 # kill already running copy of dnsmasq...
60 killproc /usr/sbin/dnsmasq 2>&1 > /dev/null
61
62 boot_mesg "Starting Domain Name Service Proxy..."
63
64 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
65 ARGS="$CUSTOM_ARGS"
66 [ "$DOMAIN_NAME_GREEN" != "" ] && ARGS="$ARGS -s $DOMAIN_NAME_GREEN"
67
68 echo > /var/ipfire/red/resolv.conf # Clear it
69 if [ -e "/var/ipfire/red/dns1" ]; then
70 DNS1=$(cat /var/ipfire/red/dns1 2>/dev/null)
71 if [ ! -z ${DNS1} ]; then
72 echo "nameserver ${DNS1}" >> /var/ipfire/red/resolv.conf
73 fi
74 fi
75 if [ -e "/var/ipfire/red/dns2" ]; then
76 DNS2=$(cat /var/ipfire/red/dns2 2>/dev/null)
77 if [ ! -z ${DNS2} ]; then
78 echo "nameserver ${DNS2}" >> /var/ipfire/red/resolv.conf
79 fi
80 fi
81 [ -e "/var/ipfire/red/active" ] && ARGS="$ARGS -r /var/ipfire/red/resolv.conf"
82
83 ARGS="$ARGS --domain=`cat /var/ipfire/main/settings |grep DOMAIN |cut -d = -f 2`"
84
85 # Add custom forward dns zones.
86 ARGS="${ARGS} $(dns_forward_args /var/ipfire/dnsforward/config)"
87
88 # Enabled DNSSEC validation
89 if [ "${ENABLE_DNSSEC}" -eq 1 ]; then
90 ARGS="${ARGS} $(dnssec_args)"
91 fi
92
93 if [ -n "${CACHE_SIZE}" ]; then
94 ARGS="${ARGS} --cache-size=${CACHE_SIZE}"
95 fi
96
97 loadproc /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $ARGS
98
99 if [ "${SHOW_SRV}" -eq 1 ] && [ "${DNS1}" != "" -o "${DNS2}" != "" ]; then
100 boot_mesg "Using DNS server(s): ${DNS1} ${DNS2}"
101 boot_mesg_flush
102 fi
103 ;;
104
105 stop)
106 boot_mesg "Stopping Domain Name Service Proxy..."
107 killproc /usr/sbin/dnsmasq
108 ;;
109
110 restart)
111 ${0} stop
112 sleep 1
113 ${0} start
114 ;;
115
116 status)
117 statusproc /usr/sbin/dnsmasq
118 ;;
119
120 *)
121 echo "Usage: ${0} {start|stop|restart|status}"
122 exit 1
123 ;;
124 esac
125
126 # End $rc_base/init.d/dnsmasq