File Support-systemd-resolved-split-dns-setup.patch of Package wireguard-tools

From 7fb4d491fab1e8e8b64c652f5e762b8025452c3a Mon Sep 17 00:00:00 2001
From: Dominik Heidler <dheidler@suse.de>
Date: Thu, 17 Feb 2022 15:31:20 +0100
Subject: [PATCH] Support systemd-resolved split-dns setup

---
 contrib/dns-hatchet/hatchet.bash | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/contrib/dns-hatchet/hatchet.bash b/contrib/dns-hatchet/hatchet.bash
index bc4d090..db44842 100644
--- a/contrib/dns-hatchet/hatchet.bash
+++ b/contrib/dns-hatchet/hatchet.bash
@@ -5,7 +5,8 @@ set_dns() {
 		{ printf 'nameserver %s\n' "${DNS[@]}"
 		  [[ ${#DNS_SEARCH[@]} -eq 0 ]] || printf 'search %s\n' "${DNS_SEARCH[*]}"
 		} | cmd resolvconf -a "$INTERFACE" -m 0 -x
-	else
+	# Don't ruin a proper split dns setup
+	elif [[ "$(readlink /etc/resolv.conf)" != "/run/systemd/resolve/stub-resolv.conf" ]] ; then
 		echo "[#] mount \`${DNS[*]}' /etc/resolv.conf" >&2
 		[[ -e /etc/resolv.conf ]] || touch /etc/resolv.conf
 		{ cat <<-_EOF
@@ -30,6 +31,15 @@ set_dns() {
 		_EOF
 		)"
 	fi
+	# If systemd-resolved is installed, set the dns configuration there (as well).
+	# It might be used additionally (eg for containers) or even for the whole system.
+	# A teardown is not really needed as resolvectl detects the interface disappearing.
+	if resolvectl status >/dev/null 2>&1 ; then
+		cmd resolvectl dns "$INTERFACE" "${DNS[@]}"
+		# Prefix each domain with '~' which will tell resolvectl to use that domain
+		# for dns routing but not as a search domain
+		cmd resolvectl domain "$INTERFACE" ${DNS_SEARCH[*]/#/\~}
+	fi
 	HAVE_SET_DNS=1
 }
 
-- 
2.35.1

openSUSE Build Service is sponsored by