Browse code

windows: properly configure TAP driver when no IPv4 is configured

This patch ensures that the TAP driver on a windows host is still
configured, even though no IPv4 has been provided.

In this case the TAP driver ioctl will be invoked with a fake
0.0.0.0/0.0.0.0 IPv4 which will simply start the interface and
get it to a working state.

Trac: #208
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20180623183108.18684-1-a@unstable.cc>
URL: https://www.mail-archive.com/search?l=mid&q=20180623183108.18684-1-a@unstable.cc
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Antonio Quartulli authored on 2018/06/24 03:31:08
Showing 2 changed files
... ...
@@ -2642,7 +2642,11 @@ test_routes(const struct route_list *rl, const struct tuntap *tt)
2642 2642
         ret = true;
2643 2643
         adapter_up = true;
2644 2644
 
2645
-        if (rl)
2645
+        /* we do this test only if we have IPv4 routes to install, and if
2646
+         * the tun/tap interface has seen IPv4 ifconfig - because if we
2647
+         * have no IPv4, the check will always fail, failing tun init
2648
+         */
2649
+        if (rl && tt->did_ifconfig_setup)
2646 2650
         {
2647 2651
             struct route_ipv4 *r;
2648 2652
             for (r = rl->routes, len = 0; r; r = r->next, ++len)
... ...
@@ -5703,7 +5703,10 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
5703 5703
             msg(M_FATAL, "ERROR: --dev tun also requires --ifconfig");
5704 5704
         }
5705 5705
 
5706
-        if (tt->topology == TOP_SUBNET)
5706
+        /* send 0/0/0 to the TAP driver even if we have no IPv4 configured to
5707
+         * ensure it is somehow initialized.
5708
+         */
5709
+        if (!tt->did_ifconfig_setup || tt->topology == TOP_SUBNET)
5707 5710
         {
5708 5711
             in_addr_t ep[3];
5709 5712
             BOOL status;
... ...
@@ -5716,12 +5719,19 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
5716 5716
                                      ep, sizeof(ep),
5717 5717
                                      ep, sizeof(ep), &len, NULL);
5718 5718
 
5719
-            msg(status ? M_INFO : M_FATAL, "Set TAP-Windows TUN subnet mode network/local/netmask = %s/%s/%s [%s]",
5720
-                print_in_addr_t(ep[1], IA_NET_ORDER, &gc),
5721
-                print_in_addr_t(ep[0], IA_NET_ORDER, &gc),
5722
-                print_in_addr_t(ep[2], IA_NET_ORDER, &gc),
5723
-                status ? "SUCCEEDED" : "FAILED");
5724
-
5719
+            if (tt->did_ifconfig_setup)
5720
+            {
5721
+                msg(status ? M_INFO : M_FATAL, "Set TAP-Windows TUN subnet mode network/local/netmask = %s/%s/%s [%s]",
5722
+                    print_in_addr_t(ep[1], IA_NET_ORDER, &gc),
5723
+                    print_in_addr_t(ep[0], IA_NET_ORDER, &gc),
5724
+                    print_in_addr_t(ep[2], IA_NET_ORDER, &gc),
5725
+                    status ? "SUCCEEDED" : "FAILED");
5726
+            }
5727
+            else
5728
+            {
5729
+                msg(status ? M_INFO : M_FATAL, "Set TAP-Windows TUN with fake IPv4 [%s]",
5730
+                    status ? "SUCCEEDED" : "FAILED");
5731
+            }
5725 5732
         }
5726 5733
         else
5727 5734
         {