aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2026-06-26 14:43:26 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2026-06-26 14:43:26 +0000
commitf0a861efbafeb81428d5e8c23dac9da73fe14007 (patch)
tree10be4e595622a51113a710a5576dab9b923bebc5
parent45efa4e61623e3eeee7fd0a3f4436616e24c8e98 (diff)
local-unbound-setup: Support IPv6-only systems
* In the server configuration, disable protocols not supported by the kernel. * In resolv.conf, instead of only using 127.0.0.1, use either 127.0.0.1, ::1, or both depending on which protocols the kernel supports. MFC after: 1 week Reviewed by: jlduran Differential Revision: https://reviews.freebsd.org/D57840
-rwxr-xr-xusr.sbin/unbound/setup/local-unbound-setup.sh50
1 files changed, 40 insertions, 10 deletions
diff --git a/usr.sbin/unbound/setup/local-unbound-setup.sh b/usr.sbin/unbound/setup/local-unbound-setup.sh
index ec3aeb673ecc..6b217ec574cd 100755
--- a/usr.sbin/unbound/setup/local-unbound-setup.sh
+++ b/usr.sbin/unbound/setup/local-unbound-setup.sh
@@ -73,6 +73,19 @@ RE_forward_name="(${RE_dnsname}(@${RE_port})?)"
RE_forward_tls="(${RE_forward_addr}(#${RE_dnsname})?)"
#
+# Check if a kernel feature is available
+#
+has_feature() {
+ local name=$1 v
+ eval "v=\$kern_features_${name}"
+ if [ -z "$v" ] ; then
+ v="$(sysctl -qn "kern.features.${name}")"
+ eval "kern_features_${name}=$((v))"
+ fi
+ return $((!v))
+}
+
+#
# Set default values for unset configuration variables.
#
set_defaults() {
@@ -136,13 +149,12 @@ get_nameservers() {
#
# Scan through /etc/resolv.conf looking for uncommented nameserver
-# lines. Comment out any that don't point to localhost. Finally,
-# append a nameserver line that points to localhost, if there wasn't
-# one already, and enable the edns0 option.
+# lines and comment out any that don't point to localhost. Finally,
+# append the correct nameserver lines and enable the edns0 option.
#
gen_resolv_conf() {
- local localhost=no
- local edns0=no
+ local localhost4=false localhost6=false
+ local edns0=false
while read line ; do
local bareline=${line%%\#*}
local key=${bareline%%[[:space:]]*}
@@ -150,8 +162,17 @@ gen_resolv_conf() {
case ${key} in
nameserver)
case ${value} in
- 127.0.0.1|::1|localhost|localhost.*)
- localhost=yes
+ 127.0.0.1)
+ localhost4=true
+ if ! has_feature inet ; then
+ continue
+ fi
+ ;;
+ ::1)
+ localhost6=true
+ if ! has_feature inet6 ; then
+ continue
+ fi
;;
*)
echo -n "# "
@@ -161,17 +182,20 @@ gen_resolv_conf() {
options)
case ${value} in
*edns0*)
- edns0=yes
+ edns0=true
;;
esac
;;
esac
echo "${line}"
done
- if [ "${localhost}" = "no" ] ; then
+ if ! $localhost4 && has_feature inet ; then
echo "nameserver 127.0.0.1"
fi
- if [ "${edns0}" = "no" ] ; then
+ if ! $localhost6 && has_feature inet6 ; then
+ echo "nameserver ::1"
+ fi
+ if ! $edns0 ; then
echo "options edns0"
fi
}
@@ -261,6 +285,12 @@ gen_unbound_conf() {
if [ "${use_tls}" = "yes" ] ; then
echo " tls-cert-bundle: /etc/ssl/cert.pem"
fi
+ if ! has_feature inet ; then
+ echo " do-ip4: no"
+ fi
+ if ! has_feature inet6 ; then
+ echo " do-ip6: no"
+ fi
echo " so-sndbuf: 0"
echo ""
if [ -f "${forward_conf}" ] ; then