2 # Begin $rc_base/init.d/unbound
4 # Description : Unbound DNS resolver boot script for IPfire
5 # Author : Marcel Lorenz <marcel.lorenz@ipfire.org>
7 # Comment : This init script additional starts the dhcpd watcher daemon
8 # if DNS-Update (RFC2136) in web interface enabled
15 # Load optional configuration
16 [ -e "/etc/sysconfig/unbound" ] && .
/etc
/sysconfig
/unbound
20 IFS
=.
read -r i1 i2 i3 i4
<<< ${1}
21 IFS
=.
read -r m1 m2 m3
m4 <<< ${2}
22 cidr
=$
(printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))")
36 *) echo "Error: $dec is not recognised"; exit 1
39 echo "${cidr}/${nbits}"
45 echo "$(</var/ipfire/red/dns${i})"
50 echo "# This file is automatically generated and any changes"
51 echo "# will be overwritten. DO NOT EDIT!"
56 local forwarders
="$(read_name_servers)"
58 if [ "${USE_FORWARDERS}" = "1" ] && [ -n "${forwarders}" ]; then
59 boot_mesg
"Using Name Server(s): ${forwarders}"
62 unbound-control
-q forward
${forwarders}
64 # If forwarders cannot be used we run in recursor mode
66 unbound-control
-q forward off
70 write_interfaces_conf
() {
74 if [ -n "${GREEN_ADDRESS}" ]; then
76 echo "interface: ${GREEN_ADDRESS}"
77 echo "access-control: $(cidr ${GREEN_NETADDRESS} ${GREEN_NETMASK}) allow"
80 if [ -n "${BLUE_ADDRESS}" ]; then
82 echo "interface: ${BLUE_ADDRESS}"
83 echo "access-control: $(cidr ${BLUE_NETADDRESS} ${BLUE_NETMASK}) allow"
85 ) > /etc
/unbound
/interfaces.conf
88 write_forward_conf
() {
92 local enabled zone server remark
93 while IFS
="," read -r enabled zone server remark
; do
94 # Line must be enabled.
95 [ "${enabled}" = "on" ] ||
continue
99 echo " forward-addr: ${server}"
101 done < /var
/ipfire
/dnsforward
/config
102 ) > /etc
/unbound
/forward.conf
108 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
109 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/dhcp
/settings
)
111 # Create control keys at first run
112 if [ ! -r "/etc/unbound/unbound_control.key" ]; then
113 unbound-control-setup
-d /etc
/unbound
&>/dev
/null
116 # Update configuration files
117 write_interfaces_conf
120 boot_mesg
"Starting Unbound DNS Proxy..."
121 loadproc
/usr
/sbin
/unbound ||
exit $?
123 # Update any known forwarding name servers
126 # Start Unbound DHCP Lease Bridge unless RFC2136 is used
127 if [ "${DNS_UPDATE_ENABLED}" != on
]; then
128 boot_mesg
"Starting Unbound DHCP Leases Bridge..."
129 loadproc
/usr
/sbin
/unbound-dhcp-leases-bridge
-d
134 boot_mesg
"Stopping Unbound DHCP Leases Bridge..."
135 killproc
/usr
/sbin
/unbound-dhcp-leases-bridge
137 boot_mesg
"Stopping Unbound DNS Proxy..."
138 killproc
/usr
/sbin
/unbound
148 statusproc
/usr
/sbin
/unbound
149 statusproc
/usr
/sbin
/unbound-dhcp-leases-bridge
157 echo "Usage: $0 {start|stop|restart|status|update-forwarders}"
162 # End $rc_base/init.d/unbound