unbound: Write hosts to unbound configuration file

This will allow us to read more hosts in a shorter time.

Fixes: #11743
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Michael Tremer
2020-01-13 21:10:18 +01:00
parent 903247fef8
commit 6137797cb3
2 changed files with 36 additions and 39 deletions

View 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"

View File

@@ -58,11 +58,14 @@ config_header() {
echo
}
own_hostname() {
local hostname=$(hostname -f)
write_hosts_conf() {
(
config_header
# 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
unbound-control -q local_data "${hostname} ${LOCAL_TTL} IN A ${GREEN_ADDRESS}"
echo "local-data: \"${HOSTNAME} ${LOCAL_TTL} IN A ${GREEN_ADDRESS}\""
fi
local address
@@ -71,23 +74,17 @@ own_hostname() {
[ "${address}" = "1.1.1.1" ] && continue
address=$(ip_address_revptr ${address})
unbound-control -q local_data "${address} ${LOCAL_TTL} IN PTR ${hostname}"
echo "local-data: \"${address} ${LOCAL_TTL} IN PTR ${HOSTNAME}\""
done
}
update_hosts() {
# Make own hostname resolveable
own_hostname
# Add all hosts
local enabled address hostname domainname generateptr
while IFS="," read -r enabled address hostname domainname generateptr; do
[ "${enabled}" = "on" ] || continue
# Build FQDN
local fqdn="${hostname}.${domainname}"
unbound-control -q local_data "${fqdn} ${LOCAL_TTL} IN A ${address}"
echo "local-data: \"${fqdn} ${LOCAL_TTL} IN A ${address}\""
# Skip reverse resolution if the address equals the GREEN address
[ "${address}" = "${GREEN_ADDRESS}" ] && continue
@@ -97,8 +94,9 @@ update_hosts() {
# Add RDNS
address=$(ip_address_revptr ${address})
unbound-control -q local_data "${address} ${LOCAL_TTL} IN PTR ${fqdn}"
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
;;