From: "cron2 (Code Review)" Date: Thu, 26 Jun 2025 09:26:39 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., heiko@...515..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <9c5fcf9f5d86195510e4cf8f6ea62e093c472110-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="4xsGhJrTh/w="; charset=UTF-8 Subject: [Openvpn-devel] [XS] Change in openvpn[master]: fix macOS dns-updown handling of parallel full redirects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: d12fk Cc: plaisthos , flichtenheld , openvpn-devel --4xsGhJrTh/w= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/10= 66?usp=3Demail ) Change subject: fix macOS dns-updown handling of parallel full redirects ...................................................................... fix macOS dns-updown handling of parallel full redirects The script didn't handle scenarios well where two or more parallel VPN connections want to replace the default DNS server. The DNS configuration has a chance to get broken by the connections going down in a different order than they came up in. Disallowing all but the first connection to modify the default DNS server will effectively prevent this issue. While it may break DNS for the latter connections, it is the best we can do without knowing specifics about the configurations. Change-Id: I7b413578a8fc0c65fca26f72b901a9f7bc34b137 Signed-off-by: Heiko Hund Acked-by: Arne Schwabe Message-Id: <20250626091959.23505-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31= 988.html Signed-off-by: Gert Doering --- M distro/dns-scripts/macos-dns-updown.sh 1 file changed, 9 insertions(+), 0 deletions(-) diff --git a/distro/dns-scripts/macos-dns-updown.sh b/distro/dns-scripts/ma= cos-dns-updown.sh index 89d6882..c15abaa 100644 --- a/distro/dns-scripts/macos-dns-updown.sh +++ b/distro/dns-scripts/macos-dns-updown.sh @@ -30,6 +30,7 @@ itf_dns_key=3D"State:/Network/Service/openvpn-${dev}/DNS" dns_backup_key=3D"State:/Network/Service/openvpn-${dev}/DnsBackup" +dns_backup_key_pattern=3D"State:/Network/Service/openvpn-.*/DnsBackup" function primary_dns_key { local uuid=3D$(echo "show State:/Network/Global/IPv4" | /usr/sbin/scut= il | grep "PrimaryService" | cut -d: -f2 | xargs) @@ -166,6 +167,11 @@ echo -e "${cmds}" | /usr/sbin/scutil set_search_domains "$search_domains" else + echo list ${dns_backup_key_pattern} | /usr/sbin/scutil | grep -q '= no key' || { + echo "setting DNS failed, already redirecting to another tunne= l" + exit 1 + } + local cmds=3D"" cmds+=3D"get $(primary_dns_key)\n" cmds+=3D"set ${dns_backup_key}\n" @@ -200,6 +206,9 @@ echo "remove ${itf_dns_key}" | /usr/sbin/scutil unset_search_domains "$search_domains" else + # Do not unset if this tunnel did not set/backup DNS before + echo list ${dns_backup_key} | /usr/sbin/scutil | grep -qv 'no key'= || return + local cmds=3D"" cmds+=3D"get ${dns_backup_key}\n" cmds+=3D"set $(primary_dns_key)\n" -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1066?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I7b413578a8fc0c65fca26f72b901a9f7bc34b137 Gerrit-Change-Number: 1066 Gerrit-PatchSet: 3 Gerrit-Owner: d12fk Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --4xsGhJrTh/w= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

fix macOS dns-updown handling of parallel ful=
l redirects

The script didn't handle scenarios well where two or= more parallel VPN
connections want to replace the default DNS server. T= he DNS configuration
has a chance to get broken by the connections going= down in a different
order than they came up in.

Disallowing all = but the first connection to modify the default DNS server
will effective= ly prevent this issue. While it may break DNS for the
latter connections= , it is the best we can do without knowing specifics
about the configura= tions.

Change-Id: I7b413578a8fc0c65fca26f72b901a9f7bc34b137
Signe= d-off-by: Heiko Hund <heiko@...2662...>
Acked-by: Arne Schwabe <= ;arne-openvpn@...1227...>
Message-Id: <20250626091959.23505-1-gert= @...1296...>
URL: https://www.mail-archive.com/openvpn-devel@...1466...= urceforge.net/msg31988.html
Signed-off-by: Gert Doering <gert@...1726...= ...>
---
M distro/dns-scripts/macos-dns-updown.sh
1 file change= d, 9 insertions(+), 0 deletions(-)

diff --git a/distro/dns-scripts/macos-dns-updown.sh b/distro/dns-scripts=
/macos-dns-updown.sh
index 89d6882..c15abaa 100644--- a/distro/dns-scripts/macos-dns-updown.sh
+++ b/= distro/dns-scripts/macos-dns-updown.sh
@@ -30,6 +30,7 @@

itf_dns_key=3D"State:/Network/Service= /openvpn-${dev}/DNS"
dns_backup_key=3D"State:/Ne= twork/Service/openvpn-${dev}/DnsBackup"
+dns_backup_key_pattern=3D"State:/Network/Serv= ice/openvpn-.*/DnsBackup"

function = primary_dns_key {
local uuid=3D$(echo "show State= :/Network/Global/IPv4" | /usr/sbin/scutil | grep "PrimaryService&= quot; | cut -d: -f2 | xargs)
@@ -166,6 +167,11 @@ echo -e "${cmds}" | /usr/sbin/scutil
set_search_domains "$search_domains"

else
+ e= cho list ${dns_backup_key_pattern} | /usr/sbin/scutil | grep -q 'no key= ' || {
+ = echo "setting DNS failed, already redirecting to another tunnel&quo= t;
+ exit = 1
+ }+
lo= cal cmds=3D""
cmds+=3D"get $(primar= y_dns_key)\n"
cmds+=3D"set ${dns_backup_= key}\n"
@@ -200,6 +206,9 @@
e= cho "remove ${itf_dns_key}" | /usr/sbin/scutil
= unset_search_domains "$search_domains"
= else
+ # Do = not unset if this tunnel did not set/backup DNS before
+ echo list ${dns_backup_key} | /u= sr/sbin/scutil | grep -qv 'no key' || return
+
local cmds=3D&q= uot;"
cmds+=3D"get ${dns_backup_key}\n&q= uot;
cmds+=3D"set $(primary_dns_key)\n"<= /span>

To view, visit change 1066. To unsubscribe,= or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7b413578a8fc0c65fca26f72b90= 1a9f7bc34b137
Gerrit-Change-Number: 1066
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--4xsGhJrTh/w=--