]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
unbound: Write hosts to unbound configuration file
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 13 Jan 2020 20:10:18 +0000 (21:10 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 13 Jan 2020 20:10:18 +0000 (21:10 +0100)
This will allow us to read more hosts in a shorter time.

Fixes: #11743
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/unbound/unbound.conf
src/initscripts/system/unbound

index ce51f63a0042d72a73cb0192826b1ed7b0fff05d..10d5660e81b8cfec0cba09692732f45994973f97 100644 (file)
@@ -85,6 +85,9 @@ server:
        # Include DHCP leases
        include: "/etc/unbound/dhcp-leases.conf"
 
+       # Include hosts
+       include: "/etc/unbound/hosts.conf"
+
        # Include any forward zones
        include: "/etc/unbound/forward.conf"
 
index 37da15dbd99ad5592aa0c67c2310bca38c626b6c..5fb1d68d795ea47e848a23b58043e09a9f045ca6 100644 (file)
@@ -58,47 +58,45 @@ config_header() {
        echo
 }
 
-own_hostname() {
-       local hostname=$(hostname -f)
-       # 1.1.1.1 is reserved for unused green, skip this
-       if [ -n "${GREEN_ADDRESS}" -a "${GREEN_ADDRESS}" != "1.1.1.1" ]; then
-               unbound-control -q local_data "${hostname} ${LOCAL_TTL} IN A ${GREEN_ADDRESS}"
-       fi
-
-       local address
-       for address in ${GREEN_ADDRESS} ${BLUE_ADDRESS} ${ORANGE_ADDRESS}; do
-               [ -n "${address}" ] || continue
-               [ "${address}" = "1.1.1.1" ] && continue
-
-               address=$(ip_address_revptr ${address})
-               unbound-control -q local_data "${address} ${LOCAL_TTL} IN PTR ${hostname}"
-       done
-}
+write_hosts_conf() {
+       (
+               config_header
 
-update_hosts() {
-       # Make own hostname resolveable
-       own_hostname
+               # Make own hostname resolveable
+               # 1.1.1.1 is reserved for unused green, skip this
+               if [ -n "${GREEN_ADDRESS}" -a "${GREEN_ADDRESS}" != "1.1.1.1" ]; then
+                       echo "local-data: \"${HOSTNAME} ${LOCAL_TTL} IN A ${GREEN_ADDRESS}\""
+               fi
 
-       local enabled address hostname domainname generateptr
+               local address
+               for address in ${GREEN_ADDRESS} ${BLUE_ADDRESS} ${ORANGE_ADDRESS}; do
+                       [ -n "${address}" ] || continue
+                       [ "${address}" = "1.1.1.1" ] && continue
 
-       while IFS="," read -r enabled address hostname domainname generateptr; do
-               [ "${enabled}" = "on" ] || continue
+                       address=$(ip_address_revptr ${address})
+                       echo "local-data: \"${address} ${LOCAL_TTL} IN PTR ${HOSTNAME}\""
+               done
 
-               # Build FQDN
-               local fqdn="${hostname}.${domainname}"
+               # Add all hosts
+               local enabled address hostname domainname generateptr
+               while IFS="," read -r enabled address hostname domainname generateptr; do
+                       [ "${enabled}" = "on" ] || continue
 
-               unbound-control -q local_data "${fqdn} ${LOCAL_TTL} IN A ${address}"
+                       # Build FQDN
+                       local fqdn="${hostname}.${domainname}"
+                       echo "local-data: \"${fqdn} ${LOCAL_TTL} IN A ${address}\""
 
-               # Skip reverse resolution if the address equals the GREEN address
-               [ "${address}" = "${GREEN_ADDRESS}" ] && continue
+                       # Skip reverse resolution if the address equals the GREEN address
+                       [ "${address}" = "${GREEN_ADDRESS}" ] && continue
 
-               # Skip reverse resolution if user requested not to do so
-               [ "${generateptr}" = "off" ] && continue
+                       # Skip reverse resolution if user requested not to do so
+                       [ "${generateptr}" = "off" ] && continue
 
-               # Add RDNS
-               address=$(ip_address_revptr ${address})
-               unbound-control -q local_data "${address} ${LOCAL_TTL} IN PTR ${fqdn}"
-       done < /var/ipfire/main/hosts
+                       # Add RDNS
+                       address=$(ip_address_revptr ${address})
+                       echo "local-data: \"${address} ${LOCAL_TTL} IN PTR ${fqdn}\""
+               done < /var/ipfire/main/hosts
+       ) > /etc/unbound/hosts.conf
 }
 
 write_forward_conf() {
@@ -573,6 +571,7 @@ case "$1" in
 
                # Update configuration files
                write_tuning_conf
+               write_hosts_conf
                write_forward_conf
 
                boot_mesg "Starting Unbound DNS Proxy..."
@@ -582,9 +581,6 @@ case "$1" in
                if [ -e "/var/ipfire/red/active" ]; then
                        update_safe_search
                fi
-
-               # Update hosts
-               update_hosts
                ;;
 
        stop)
@@ -600,15 +596,13 @@ case "$1" in
        reload)
                # Update configuration files
                write_forward_conf
+               write_hosts_conf
 
                # Update Safe Search rules if the system is online.
                if [ -e "/var/ipfire/red/active" ]; then
                        update_safe_search
                fi
 
-               # Update hosts.
-               update_hosts
-
                # Call unbound-control and perform the reload
                /usr/sbin/unbound-control -q reload
                ;;