Browse code

Fix subnet topology on NetBSD.

Signed-off-by: Adam Ciarcin?ski <adam@netbsd.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <8110ED8B-4084-4D47-87E2-7B1C14041268@netbsd.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg17399.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Adam CiarcinĖski authored on 2018/08/02 23:17:56
Showing 1 changed files
... ...
@@ -845,7 +845,7 @@ delete_route_connected_v6_net(struct tuntap *tt,
845 845
 #endif /* if defined(_WIN32) || defined(TARGET_DARWIN) || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD) */
846 846
 
847 847
 #if defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY)  \
848
-    || defined(TARGET_OPENBSD)
848
+    || defined(TARGET_NETBSD) || defined(TARGET_OPENBSD)
849 849
 /* we can't use true subnet mode on tun on all platforms, as that
850 850
  * conflicts with IPv6 (wants to use ND then, which we don't do),
851 851
  * but the OSes want "a remote address that is different from ours"
... ...
@@ -1233,6 +1233,7 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1233 1233
     }
1234 1234
 
1235 1235
 #elif defined(TARGET_NETBSD)
1236
+    in_addr_t remote_end;           /* for "virtual" subnet topology */
1236 1237
 
1237 1238
     if (tun)
1238 1239
     {
... ...
@@ -1242,9 +1243,10 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1242 1242
     }
1243 1243
     else if (tt->topology == TOP_SUBNET)
1244 1244
     {
1245
+        remote_end = create_arbitrary_remote(tt);
1245 1246
         argv_printf(&argv, "%s %s %s %s mtu %d netmask %s up", IFCONFIG_PATH,
1246
-                    ifname, ifconfig_local, ifconfig_local, tun_mtu,
1247
-                    ifconfig_remote_netmask);
1247
+                    ifname, ifconfig_local, print_in_addr_t(remote_end, 0, &gc),
1248
+                    tun_mtu, ifconfig_remote_netmask);
1248 1249
     }
1249 1250
     else
1250 1251
     {
... ...
@@ -1260,6 +1262,18 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
1260 1260
     argv_msg(M_INFO, &argv);
1261 1261
     openvpn_execve_check(&argv, es, S_FATAL, "NetBSD ifconfig failed");
1262 1262
 
1263
+    /* Add a network route for the local tun interface */
1264
+    if (!tun && tt->topology == TOP_SUBNET)
1265
+    {
1266
+        struct route_ipv4 r;
1267
+        CLEAR(r);
1268
+        r.flags = RT_DEFINED;
1269
+        r.network = tt->local & tt->remote_netmask;
1270
+        r.netmask = tt->remote_netmask;
1271
+        r.gateway = remote_end;
1272
+        add_route(&r, tt, 0, NULL, es);
1273
+    }
1274
+
1263 1275
 #elif defined(TARGET_DARWIN)
1264 1276
     /*
1265 1277
      * Darwin (i.e. Mac OS X) seems to exhibit similar behaviour to OpenBSD...