Browse code

Fix combination of --dev tap and --topology subnet across multiple platforms.

--topology should have no effect in tap mode (tap is always "subnet"),
but due to the way options are checked, setting "topology subnet" caught
an improper branch on all non-linux and non-win32 platforms.

Easily tested by adding "--topology subnet" to a "--dev tap" t_client
test.

Tested, verified, and fixed on FreeBSD 13.3, NetBSD 8.1, OpenBSD 6.5,
OpenIndiana 2019 (Solaris) and MacOS X Mojave.

This is a forward-port of commit 6c13e24e5709 - the original intent
for "master" was to restructure tun.c in a larger way and clean up
these if() blocks more nicely... which has not happened yet, so this
patch is basically applying exactly the same changes to context that
has changed too much for git to be able to do this automatically.

Trac: #1085

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Antonio Quartulli <a@unstable.cc>
Message-Id: <20200914070843.51678-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20987.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 860a7bc77ef515f1d042a2860f7e2bd9980e19be)

Gert Doering authored on 2020/09/14 16:08:43
Showing 1 changed files
... ...
@@ -1242,7 +1242,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1242 1242
         argv_printf(&argv, "%s %s netmask 255.255.255.255", IFCONFIG_PATH,
1243 1243
                     ifname);
1244 1244
     }
1245
-    else if (tt->topology == TOP_SUBNET)
1245
+    else if (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
1246 1246
     {
1247 1247
         argv_printf(&argv, "%s %s %s %s netmask %s mtu %d up", IFCONFIG_PATH,
1248 1248
                     ifname, ifconfig_local, ifconfig_local,
... ...
@@ -1261,7 +1261,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1261 1261
         solaris_error_close(tt, es, ifname, false);
1262 1262
     }
1263 1263
 
1264
-    if (!tun && tt->topology == TOP_SUBNET)
1264
+    if (!tun && tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
1265 1265
     {
1266 1266
         /* Add a network route for the local tun interface */
1267 1267
         struct route_ipv4 r;
... ...
@@ -1292,7 +1292,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1292 1292
                     IFCONFIG_PATH, ifname, ifconfig_local,
1293 1293
                     ifconfig_remote_netmask, tun_mtu);
1294 1294
     }
1295
-    else if (tt->topology == TOP_SUBNET)
1295
+    else if (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
1296 1296
     {
1297 1297
         remote_end = create_arbitrary_remote( tt );
1298 1298
         argv_printf(&argv, "%s %s %s %s mtu %d netmask %s up -link0",
... ...
@@ -1310,7 +1310,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1310 1310
     openvpn_execve_check(&argv, es, S_FATAL, "OpenBSD ifconfig failed");
1311 1311
 
1312 1312
     /* Add a network route for the local tun interface */
1313
-    if (!tun && tt->topology == TOP_SUBNET)
1313
+    if (!tun && tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
1314 1314
     {
1315 1315
         struct route_ipv4 r;
1316 1316
         CLEAR(r);
... ...
@@ -1330,7 +1330,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1330 1330
                     IFCONFIG_PATH, ifname, ifconfig_local,
1331 1331
                     ifconfig_remote_netmask, tun_mtu);
1332 1332
     }
1333
-    else if (tt->topology == TOP_SUBNET)
1333
+    else if (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
1334 1334
     {
1335 1335
         remote_end = create_arbitrary_remote(tt);
1336 1336
         argv_printf(&argv, "%s %s %s %s mtu %d netmask %s up", IFCONFIG_PATH,
... ...
@@ -1352,7 +1352,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1352 1352
     openvpn_execve_check(&argv, es, S_FATAL, "NetBSD ifconfig failed");
1353 1353
 
1354 1354
     /* Add a network route for the local tun interface */
1355
-    if (!tun && tt->topology == TOP_SUBNET)
1355
+    if (!tun && tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
1356 1356
     {
1357 1357
         struct route_ipv4 r;
1358 1358
         CLEAR(r);
... ...
@@ -1384,7 +1384,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1384 1384
     }
1385 1385
     else
1386 1386
     {
1387
-        if (tt->topology == TOP_SUBNET)
1387
+        if (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
1388 1388
         {
1389 1389
             argv_printf(&argv, "%s %s %s %s netmask %s mtu %d up",
1390 1390
                         IFCONFIG_PATH, ifname, ifconfig_local, ifconfig_local,
... ...
@@ -1402,7 +1402,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1402 1402
     openvpn_execve_check(&argv, es, S_FATAL, "Mac OS X ifconfig failed");
1403 1403
 
1404 1404
     /* Add a network route for the local tun interface */
1405
-    if (!tun && tt->topology == TOP_SUBNET)
1405
+    if (!tun && tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
1406 1406
     {
1407 1407
         struct route_ipv4 r;
1408 1408
         CLEAR(r);
... ...
@@ -1424,7 +1424,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1424 1424
                     IFCONFIG_PATH, ifname, ifconfig_local,
1425 1425
                     ifconfig_remote_netmask, tun_mtu);
1426 1426
     }
1427
-    else if (tt->topology == TOP_SUBNET)
1427
+    else if (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
1428 1428
     {
1429 1429
         remote_end = create_arbitrary_remote( tt );
1430 1430
         argv_printf(&argv, "%s %s %s %s mtu %d netmask %s up", IFCONFIG_PATH,
... ...
@@ -1441,7 +1441,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1441 1441
     openvpn_execve_check(&argv, es, S_FATAL, "FreeBSD ifconfig failed");
1442 1442
 
1443 1443
     /* Add a network route for the local tun interface */
1444
-    if (!tun && tt->topology == TOP_SUBNET)
1444
+    if (!tun && tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET)
1445 1445
     {
1446 1446
         struct route_ipv4 r;
1447 1447
         CLEAR(r);