Browse code

Add information-gathering about DNS resolvers configured to t_client.sh(.in)

With the patchsets to add DNS configuration on Unix+MacOS systems, and
the addition of test stanzas to excercise and verify the OS specific
"dns-updown" script, it becomes important to trace test failures
("did it not ping because the DNS was not installed, or did something
else fail?") and also verify that DNS config is properly restored at
the end of each test.

Linux is probed with "resolvectl status", if available, and
"cat resolv.conf" if not. MacOS uses scutil --dns.

All other platforms use "cat resolv.conf" for now (because even if
"a tool to maintain DNS config" is available, in the end resolv.conf
is always where the final config lands).

Include a bit of restructuring to handle linux iproute2 testing in the
"Linux" branch, and make the control flow more amenable to having a
second case / esac block.

Change-Id: I9cae7314203424e4a604073c5445559260172477
Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20250505142224.24935-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31568.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Gert Doering authored on 2025/05/05 23:22:16
Showing 1 changed files
... ...
@@ -166,53 +166,71 @@ fail()
166 166
 # this is higly system dependent...
167 167
 get_ifconfig_route()
168 168
 {
169
-    # linux / iproute2? (-> if configure got a path)
170
-    if [ -n "@IPROUTE@" ]
171
-    then
172
-	echo "-- linux iproute2 --"
173
-	@IPROUTE@ addr show     | grep -v valid_lft
174
-	@IPROUTE@ route show
175
-	@IPROUTE@ -o -6 route show | grep -v ' cache' | sed -E -e 's/ expires [0-9]*sec//' -e 's/ (mtu|hoplimit|cwnd|ssthresh) [0-9]+//g' -e 's/ (rtt|rttvar) [0-9]+ms//g'
176
-	return
177
-    fi
178
-
179
-    # try uname
180
-    case `uname -s` in
169
+    UNAME=`uname -s`
170
+    case $UNAME in
181 171
 	Linux)
182
-	   echo "-- linux / ifconfig --"
183
-	   LANG=C @IFCONFIG@ -a |egrep  "( addr:|encap:)"
184
-	   LANG=C @NETSTAT@ -rn -4 -6
185
-	   return
186
-	   ;;
172
+            # linux / iproute2? (-> if configure got a path)
173
+            if [ -n "@IPROUTE@" ]
174
+            then
175
+                echo "-- linux iproute2 --"
176
+                @IPROUTE@ addr show     | grep -v valid_lft
177
+                @IPROUTE@ route show
178
+                @IPROUTE@ -o -6 route show | grep -v ' cache' | sed -E -e 's/ expires [0-9]*sec//' -e 's/ (mtu|hoplimit|cwnd|ssthresh) [0-9]+//g' -e 's/ (rtt|rttvar) [0-9]+ms//g'
179
+            else
180
+	        echo "-- linux / ifconfig --"
181
+	        LANG=C @IFCONFIG@ -a |egrep  "( addr:|encap:)"
182
+	        LANG=C @NETSTAT@ -rn -4 -6
183
+            fi
184
+            ;;
187 185
 	FreeBSD|NetBSD|Darwin)
188 186
 	   echo "-- FreeBSD/NetBSD/Darwin [MacOS X] --"
189 187
 	   @IFCONFIG@ -a | egrep "(flags=|inet)"
190 188
 	   @NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }'
191
-	   return
192 189
 	   ;;
193 190
 	OpenBSD)
194 191
 	   echo "-- OpenBSD --"
195 192
 	   @IFCONFIG@ -a | egrep "(flags=|inet)" | \
196 193
 		sed -e 's/pltime [0-9]*//' -e 's/vltime [0-9]*//'
197 194
 	   @NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }'
198
-	   return
199 195
 	   ;;
200 196
 	SunOS)
201 197
 	   echo "-- Solaris --"
202 198
 	   @IFCONFIG@ -a | egrep "(flags=|inet)"
203 199
 	   @NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$6 }'
204
-	   return
205 200
 	   ;;
206 201
 	AIX)
207 202
 	   echo "-- AIX --"
208 203
 	   @IFCONFIG@ -a | egrep "(flags=|inet)"
209 204
 	   @NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$6 }'
210
-	   return
211 205
 	   ;;
206
+        *)
207
+           echo "get_ifconfig_route(): no idea how to get info on your OS (`uname -s`).  FAIL." >&2
208
+           exit 20
209
+           ;;
212 210
     esac
213 211
 
214
-    echo "get_ifconfig_route(): no idea how to get info on your OS.  FAIL." >&2
215
-    exit 20
212
+    # another round of per-platform information gathering, for DNS info
213
+    # for most of the platforms "cat /etc/resolv.conf" is good enough
214
+    # except Linux and MacOS
215
+    case $UNAME in
216
+	Linux)
217
+            if [ -x /usr/bin/resolvectl ] ; then
218
+                echo "-- linux resolvectl --"
219
+                resolvectl status
220
+            else
221
+                echo "-- linux resolv.conf --"
222
+                cat /etc/resolv.conf
223
+            fi
224
+            ;;
225
+	Darwin)
226
+            echo "-- MacOS scutil --dns"
227
+            scutil --dns
228
+            ;;
229
+        *)
230
+            echo "-- resolv.conf --"
231
+            cat /etc/resolv.conf
232
+            ;;
233
+    esac
216 234
 }
217 235
 
218 236
 # ----------------------------------------------------------