Browse code

tun: always pass a valid tt pointer

This patch is a small "logic restyle" which basically moves the
check for "tt != NULL" outside of the various close_tun()
implementations and replaces it with an ASSERT.

This way the check is done only once and the function can rely
on the assumption that "tt" is always valid.

This change is mainly to improve the code style inside close_tun()
implementations by removing one level of indentation.

No functional change is present.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>

Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20180613122824.4207-3-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg17045.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Antonio Quartulli authored on 2018/06/13 21:28:23
Showing 2 changed files
... ...
@@ -1847,8 +1847,11 @@ static void
1847 1847
 do_close_tun_simple(struct context *c)
1848 1848
 {
1849 1849
     msg(D_CLOSE, "Closing TUN/TAP interface");
1850
-    close_tun(c->c1.tuntap);
1851
-    c->c1.tuntap = NULL;
1850
+    if (c->c1.tuntap)
1851
+    {
1852
+        close_tun(c->c1.tuntap);
1853
+        c->c1.tuntap = NULL;
1854
+    }
1852 1855
     c->c1.tuntap_owned = false;
1853 1856
 #if P2MP
1854 1857
     CLEAR(c->c1.pulled_options_digest_save);
... ...
@@ -1900,11 +1900,10 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
1900 1900
 void
1901 1901
 close_tun(struct tuntap *tt)
1902 1902
 {
1903
-    if (tt)
1904
-    {
1905
-        close_tun_generic(tt);
1906
-        free(tt);
1907
-    }
1903
+    ASSERT(tt);
1904
+
1905
+    close_tun_generic(tt);
1906
+    free(tt);
1908 1907
 }
1909 1908
 
1910 1909
 int
... ...
@@ -2103,77 +2102,76 @@ tuncfg(const char *dev, const char *dev_type, const char *dev_node, int persist_
2103 2103
 void
2104 2104
 close_tun(struct tuntap *tt)
2105 2105
 {
2106
-    if (tt)
2106
+    ASSERT(tt);
2107
+
2108
+    if (tt->type != DEV_TYPE_NULL && tt->did_ifconfig)
2107 2109
     {
2108
-        if (tt->type != DEV_TYPE_NULL && tt->did_ifconfig)
2109
-        {
2110
-            struct argv argv = argv_new();
2111
-            struct gc_arena gc = gc_new();
2110
+        struct argv argv = argv_new();
2111
+        struct gc_arena gc = gc_new();
2112 2112
 
2113 2113
 #ifdef ENABLE_IPROUTE
2114
-            if (is_tun_p2p(tt))
2115
-            {
2116
-                argv_printf(&argv,
2117
-                            "%s addr del dev %s local %s peer %s",
2118
-                            iproute_path,
2119
-                            tt->actual_name,
2120
-                            print_in_addr_t(tt->local, 0, &gc),
2121
-                            print_in_addr_t(tt->remote_netmask, 0, &gc)
2122
-                            );
2123
-            }
2124
-            else
2125
-            {
2126
-                argv_printf(&argv,
2127
-                            "%s addr del dev %s %s/%d",
2128
-                            iproute_path,
2129
-                            tt->actual_name,
2130
-                            print_in_addr_t(tt->local, 0, &gc),
2131
-                            netmask_to_netbits2(tt->remote_netmask)
2132
-                            );
2133
-            }
2134
-#else  /* ifdef ENABLE_IPROUTE */
2114
+        if (is_tun_p2p(tt))
2115
+        {
2135 2116
             argv_printf(&argv,
2136
-                        "%s %s 0.0.0.0",
2137
-                        IFCONFIG_PATH,
2138
-                        tt->actual_name
2139
-                        );
2117
+                        "%s addr del dev %s local %s peer %s",
2118
+                        iproute_path,
2119
+                        tt->actual_name,
2120
+                        print_in_addr_t(tt->local, 0, &gc),
2121
+                        print_in_addr_t(tt->remote_netmask, 0, &gc)
2122
+                       );
2123
+        }
2124
+        else
2125
+        {
2126
+            argv_printf(&argv,
2127
+                        "%s addr del dev %s %s/%d",
2128
+                        iproute_path,
2129
+                        tt->actual_name,
2130
+                        print_in_addr_t(tt->local, 0, &gc),
2131
+                        netmask_to_netbits2(tt->remote_netmask)
2132
+                       );
2133
+        }
2134
+#else  /* ifdef ENABLE_IPROUTE */
2135
+        argv_printf(&argv,
2136
+                    "%s %s 0.0.0.0",
2137
+                    IFCONFIG_PATH,
2138
+                    tt->actual_name
2139
+                   );
2140 2140
 #endif /* ifdef ENABLE_IPROUTE */
2141 2141
 
2142
-            argv_msg(M_INFO, &argv);
2143
-            openvpn_execve_check(&argv, NULL, 0, "Linux ip addr del failed");
2142
+        argv_msg(M_INFO, &argv);
2143
+        openvpn_execve_check(&argv, NULL, 0, "Linux ip addr del failed");
2144 2144
 
2145
-            if (tt->did_ifconfig_ipv6_setup)
2146
-            {
2147
-                const char *ifconfig_ipv6_local = print_in6_addr(tt->local_ipv6, 0, &gc);
2145
+        if (tt->did_ifconfig_ipv6_setup)
2146
+        {
2147
+            const char *ifconfig_ipv6_local = print_in6_addr(tt->local_ipv6, 0, &gc);
2148 2148
 
2149 2149
 #ifdef ENABLE_IPROUTE
2150
-                argv_printf(&argv, "%s -6 addr del %s/%d dev %s",
2151
-                            iproute_path,
2152
-                            ifconfig_ipv6_local,
2153
-                            tt->netbits_ipv6,
2154
-                            tt->actual_name
2155
-                            );
2156
-                argv_msg(M_INFO, &argv);
2157
-                openvpn_execve_check(&argv, NULL, 0, "Linux ip -6 addr del failed");
2150
+            argv_printf(&argv, "%s -6 addr del %s/%d dev %s",
2151
+                        iproute_path,
2152
+                        ifconfig_ipv6_local,
2153
+                        tt->netbits_ipv6,
2154
+                        tt->actual_name
2155
+                       );
2156
+            argv_msg(M_INFO, &argv);
2157
+            openvpn_execve_check(&argv, NULL, 0, "Linux ip -6 addr del failed");
2158 2158
 #else  /* ifdef ENABLE_IPROUTE */
2159
-                argv_printf(&argv,
2160
-                            "%s %s del %s/%d",
2161
-                            IFCONFIG_PATH,
2162
-                            tt->actual_name,
2163
-                            ifconfig_ipv6_local,
2164
-                            tt->netbits_ipv6
2165
-                            );
2166
-                argv_msg(M_INFO, &argv);
2167
-                openvpn_execve_check(&argv, NULL, 0, "Linux ifconfig inet6 del failed");
2159
+            argv_printf(&argv,
2160
+                        "%s %s del %s/%d",
2161
+                        IFCONFIG_PATH,
2162
+                        tt->actual_name,
2163
+                        ifconfig_ipv6_local,
2164
+                        tt->netbits_ipv6
2165
+                       );
2166
+            argv_msg(M_INFO, &argv);
2167
+            openvpn_execve_check(&argv, NULL, 0, "Linux ifconfig inet6 del failed");
2168 2168
 #endif
2169
-            }
2170
-
2171
-            argv_reset(&argv);
2172
-            gc_free(&gc);
2173 2169
         }
2174
-        close_tun_generic(tt);
2175
-        free(tt);
2170
+
2171
+        argv_reset(&argv);
2172
+        gc_free(&gc);
2176 2173
     }
2174
+    close_tun_generic(tt);
2175
+    free(tt);
2177 2176
 }
2178 2177
 
2179 2178
 int
... ...
@@ -2431,57 +2429,54 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
2431 2431
 static void
2432 2432
 solaris_close_tun(struct tuntap *tt)
2433 2433
 {
2434
-    if (tt)
2434
+    /* IPv6 interfaces need to be 'manually' de-configured */
2435
+    if (tt->did_ifconfig_ipv6_setup)
2435 2436
     {
2436
-        /* IPv6 interfaces need to be 'manually' de-configured */
2437
-        if (tt->did_ifconfig_ipv6_setup)
2437
+        struct argv argv = argv_new();
2438
+        argv_printf( &argv, "%s %s inet6 unplumb",
2439
+                     IFCONFIG_PATH, tt->actual_name );
2440
+        argv_msg(M_INFO, &argv);
2441
+        openvpn_execve_check(&argv, NULL, 0, "Solaris ifconfig inet6 unplumb failed");
2442
+        argv_reset(&argv);
2443
+    }
2444
+
2445
+    if (tt->ip_fd >= 0)
2446
+    {
2447
+        struct lifreq ifr;
2448
+        CLEAR(ifr);
2449
+        strncpynt(ifr.lifr_name, tt->actual_name, sizeof(ifr.lifr_name));
2450
+
2451
+        if (ioctl(tt->ip_fd, SIOCGLIFFLAGS, &ifr) < 0)
2438 2452
         {
2439
-            struct argv argv = argv_new();
2440
-            argv_printf( &argv, "%s %s inet6 unplumb",
2441
-                         IFCONFIG_PATH, tt->actual_name );
2442
-            argv_msg(M_INFO, &argv);
2443
-            openvpn_execve_check(&argv, NULL, 0, "Solaris ifconfig inet6 unplumb failed");
2444
-            argv_reset(&argv);
2453
+            msg(M_WARN | M_ERRNO, "Can't get iface flags");
2445 2454
         }
2446 2455
 
2447
-        if (tt->ip_fd >= 0)
2456
+        if (ioctl(tt->ip_fd, SIOCGLIFMUXID, &ifr) < 0)
2448 2457
         {
2449
-            struct lifreq ifr;
2450
-            CLEAR(ifr);
2451
-            strncpynt(ifr.lifr_name, tt->actual_name, sizeof(ifr.lifr_name));
2452
-
2453
-            if (ioctl(tt->ip_fd, SIOCGLIFFLAGS, &ifr) < 0)
2454
-            {
2455
-                msg(M_WARN | M_ERRNO, "Can't get iface flags");
2456
-            }
2457
-
2458
-            if (ioctl(tt->ip_fd, SIOCGLIFMUXID, &ifr) < 0)
2459
-            {
2460
-                msg(M_WARN | M_ERRNO, "Can't get multiplexor id");
2461
-            }
2462
-
2463
-            if (tt->type == DEV_TYPE_TAP)
2464
-            {
2465
-                if (ioctl(tt->ip_fd, I_PUNLINK, ifr.lifr_arp_muxid) < 0)
2466
-                {
2467
-                    msg(M_WARN | M_ERRNO, "Can't unlink interface(arp)");
2468
-                }
2469
-            }
2458
+            msg(M_WARN | M_ERRNO, "Can't get multiplexor id");
2459
+        }
2470 2460
 
2471
-            if (ioctl(tt->ip_fd, I_PUNLINK, ifr.lifr_ip_muxid) < 0)
2461
+        if (tt->type == DEV_TYPE_TAP)
2462
+        {
2463
+            if (ioctl(tt->ip_fd, I_PUNLINK, ifr.lifr_arp_muxid) < 0)
2472 2464
             {
2473
-                msg(M_WARN | M_ERRNO, "Can't unlink interface(ip)");
2465
+                msg(M_WARN | M_ERRNO, "Can't unlink interface(arp)");
2474 2466
             }
2475
-
2476
-            close(tt->ip_fd);
2477
-            tt->ip_fd = -1;
2478 2467
         }
2479 2468
 
2480
-        if (tt->fd >= 0)
2469
+        if (ioctl(tt->ip_fd, I_PUNLINK, ifr.lifr_ip_muxid) < 0)
2481 2470
         {
2482
-            close(tt->fd);
2483
-            tt->fd = -1;
2471
+            msg(M_WARN | M_ERRNO, "Can't unlink interface(ip)");
2484 2472
         }
2473
+
2474
+        close(tt->ip_fd);
2475
+        tt->ip_fd = -1;
2476
+    }
2477
+
2478
+    if (tt->fd >= 0)
2479
+    {
2480
+        close(tt->fd);
2481
+        tt->fd = -1;
2485 2482
     }
2486 2483
 }
2487 2484
 
... ...
@@ -2491,18 +2486,17 @@ solaris_close_tun(struct tuntap *tt)
2491 2491
 void
2492 2492
 close_tun(struct tuntap *tt)
2493 2493
 {
2494
-    if (tt)
2495
-    {
2496
-        solaris_close_tun(tt);
2494
+    ASSERT(tt);
2497 2495
 
2498
-        if (tt->actual_name)
2499
-        {
2500
-            free(tt->actual_name);
2501
-        }
2496
+    solaris_close_tun(tt);
2502 2497
 
2503
-        clear_tuntap(tt);
2504
-        free(tt);
2498
+    if (tt->actual_name)
2499
+    {
2500
+        free(tt->actual_name);
2505 2501
     }
2502
+
2503
+    clear_tuntap(tt);
2504
+    free(tt);
2506 2505
 }
2507 2506
 
2508 2507
 static void
... ...
@@ -2591,31 +2585,32 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
2591 2591
 void
2592 2592
 close_tun(struct tuntap *tt)
2593 2593
 {
2594
+    ASSERT(tt);
2595
+
2594 2596
     /* only *TAP* devices need destroying, tun devices auto-self-destruct
2595 2597
      */
2596
-    if (tt && (tt->type == DEV_TYPE_TUN || tt->persistent_if ) )
2598
+    if (tt->type == DEV_TYPE_TUN || tt->persistent_if)
2597 2599
     {
2598 2600
         close_tun_generic(tt);
2599 2601
         free(tt);
2602
+        return;
2600 2603
     }
2601
-    else if (tt)
2602
-    {
2603
-        struct argv argv = argv_new();
2604 2604
 
2605
-        /* setup command, close tun dev (clears tt->actual_name!), run command
2606
-         */
2605
+    struct argv argv = argv_new();
2607 2606
 
2608
-        argv_printf(&argv, "%s %s destroy",
2609
-                    IFCONFIG_PATH, tt->actual_name);
2607
+    /* setup command, close tun dev (clears tt->actual_name!), run command
2608
+    */
2610 2609
 
2611
-        close_tun_generic(tt);
2610
+    argv_printf(&argv, "%s %s destroy",
2611
+                IFCONFIG_PATH, tt->actual_name);
2612 2612
 
2613
-        argv_msg(M_INFO, &argv);
2614
-        openvpn_execve_check(&argv, NULL, 0, "OpenBSD 'destroy tun interface' failed (non-critical)");
2613
+    close_tun_generic(tt);
2615 2614
 
2616
-        free(tt);
2617
-        argv_reset(&argv);
2618
-    }
2615
+    argv_msg(M_INFO, &argv);
2616
+    openvpn_execve_check(&argv, NULL, 0, "OpenBSD 'destroy tun interface' failed (non-critical)");
2617
+
2618
+    free(tt);
2619
+    argv_reset(&argv);
2619 2620
 }
2620 2621
 
2621 2622
 int
... ...
@@ -2676,31 +2671,32 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
2676 2676
 void
2677 2677
 close_tun(struct tuntap *tt)
2678 2678
 {
2679
+    ASSERT(tt);
2680
+
2679 2681
     /* only tun devices need destroying, tap devices auto-self-destruct
2680 2682
      */
2681
-    if (tt && ( tt->type != DEV_TYPE_TUN || tt->persistent_if ) )
2683
+    if (tt->type != DEV_TYPE_TUN || tt->persistent_if)
2682 2684
     {
2683 2685
         close_tun_generic(tt);
2684 2686
         free(tt);
2687
+        return;
2685 2688
     }
2686
-    else if (tt)
2687
-    {
2688
-        struct argv argv = argv_new();
2689 2689
 
2690
-        /* setup command, close tun dev (clears tt->actual_name!), run command
2691
-         */
2690
+    struct argv argv = argv_new();
2692 2691
 
2693
-        argv_printf(&argv, "%s %s destroy",
2694
-                    IFCONFIG_PATH, tt->actual_name);
2692
+    /* setup command, close tun dev (clears tt->actual_name!), run command
2693
+    */
2695 2694
 
2696
-        close_tun_generic(tt);
2695
+    argv_printf(&argv, "%s %s destroy",
2696
+                IFCONFIG_PATH, tt->actual_name);
2697 2697
 
2698
-        argv_msg(M_INFO, &argv);
2699
-        openvpn_execve_check(&argv, NULL, 0, "NetBSD 'destroy tun interface' failed (non-critical)");
2698
+    close_tun_generic(tt);
2700 2699
 
2701
-        free(tt);
2702
-        argv_reset(&argv);
2703
-    }
2700
+    argv_msg(M_INFO, &argv);
2701
+    openvpn_execve_check(&argv, NULL, 0, "NetBSD 'destroy tun interface' failed (non-critical)");
2702
+
2703
+    free(tt);
2704
+    argv_reset(&argv);
2704 2705
 }
2705 2706
 
2706 2707
 static inline int
... ...
@@ -2816,29 +2812,32 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
2816 2816
 void
2817 2817
 close_tun(struct tuntap *tt)
2818 2818
 {
2819
-    if (tt && tt->persistent_if)        /* keep pre-existing if around */
2819
+    ASSERT(tt);
2820
+
2821
+    if (tt->persistent_if)        /* keep pre-existing if around */
2820 2822
     {
2821 2823
         close_tun_generic(tt);
2822 2824
         free(tt);
2825
+        return;
2823 2826
     }
2824
-    else if (tt)                        /* close and destroy */
2825
-    {
2826
-        struct argv argv = argv_new();
2827 2827
 
2828
-        /* setup command, close tun dev (clears tt->actual_name!), run command
2829
-         */
2828
+    /* close and destroy */
2829
+    struct argv argv = argv_new();
2830 2830
 
2831
-        argv_printf(&argv, "%s %s destroy",
2832
-                    IFCONFIG_PATH, tt->actual_name);
2831
+    /* setup command, close tun dev (clears tt->actual_name!), run command
2832
+    */
2833 2833
 
2834
-        close_tun_generic(tt);
2834
+    argv_printf(&argv, "%s %s destroy",
2835
+                IFCONFIG_PATH, tt->actual_name);
2835 2836
 
2836
-        argv_msg(M_INFO, &argv);
2837
-        openvpn_execve_check(&argv, NULL, 0, "FreeBSD 'destroy tun interface' failed (non-critical)");
2837
+    close_tun_generic(tt);
2838 2838
 
2839
-        free(tt);
2840
-        argv_reset(&argv);
2841
-    }
2839
+    argv_msg(M_INFO, &argv);
2840
+    openvpn_execve_check(&argv, NULL, 0,
2841
+                         "FreeBSD 'destroy tun interface' failed (non-critical)");
2842
+
2843
+    free(tt);
2844
+    argv_reset(&argv);
2842 2845
 }
2843 2846
 
2844 2847
 int
... ...
@@ -2929,11 +2928,10 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
2929 2929
 void
2930 2930
 close_tun(struct tuntap *tt)
2931 2931
 {
2932
-    if (tt)
2933
-    {
2934
-        close_tun_generic(tt);
2935
-        free(tt);
2936
-    }
2932
+    ASSERT(tt);
2933
+
2934
+    close_tun_generic(tt);
2935
+    free(tt);
2937 2936
 }
2938 2937
 
2939 2938
 int
... ...
@@ -3186,27 +3184,26 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
3186 3186
 void
3187 3187
 close_tun(struct tuntap *tt)
3188 3188
 {
3189
-    if (tt)
3190
-    {
3191
-        struct gc_arena gc = gc_new();
3192
-        struct argv argv = argv_new();
3189
+    ASSERT(tt);
3193 3190
 
3194
-        if (tt->did_ifconfig_ipv6_setup)
3195
-        {
3196
-            const char *ifconfig_ipv6_local =
3197
-                print_in6_addr(tt->local_ipv6, 0, &gc);
3191
+    struct gc_arena gc = gc_new();
3192
+    struct argv argv = argv_new();
3198 3193
 
3199
-            argv_printf(&argv, "%s delete -inet6 %s",
3200
-                        ROUTE_PATH, ifconfig_ipv6_local );
3201
-            argv_msg(M_INFO, &argv);
3202
-            openvpn_execve_check(&argv, NULL, 0, "MacOS X 'remove inet6 route' failed (non-critical)");
3203
-        }
3194
+    if (tt->did_ifconfig_ipv6_setup)
3195
+    {
3196
+        const char *ifconfig_ipv6_local =
3197
+            print_in6_addr(tt->local_ipv6, 0, &gc);
3204 3198
 
3205
-        close_tun_generic(tt);
3206
-        free(tt);
3207
-        argv_reset(&argv);
3208
-        gc_free(&gc);
3199
+        argv_printf(&argv, "%s delete -inet6 %s",
3200
+                    ROUTE_PATH, ifconfig_ipv6_local );
3201
+        argv_msg(M_INFO, &argv);
3202
+        openvpn_execve_check(&argv, NULL, 0, "MacOS X 'remove inet6 route' failed (non-critical)");
3209 3203
     }
3204
+
3205
+    close_tun_generic(tt);
3206
+    free(tt);
3207
+    argv_reset(&argv);
3208
+    gc_free(&gc);
3210 3209
 }
3211 3210
 
3212 3211
 int
... ...
@@ -3335,14 +3332,11 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
3335 3335
 void
3336 3336
 close_tun(struct tuntap *tt)
3337 3337
 {
3338
+    ASSERT(tt);
3339
+
3338 3340
     struct argv argv = argv_new();
3339 3341
     struct env_set *es = env_set_create(NULL);
3340 3342
 
3341
-    if (!tt)
3342
-    {
3343
-        return;
3344
-    }
3345
-
3346 3343
     /* persistent devices need IP address unconfig, others need destroyal
3347 3344
      */
3348 3345
     if (tt->persistent_if)
... ...
@@ -6181,104 +6175,103 @@ tun_show_debug(struct tuntap *tt)
6181 6181
 void
6182 6182
 close_tun(struct tuntap *tt)
6183 6183
 {
6184
+    ASSERT(tt);
6185
+
6184 6186
     struct gc_arena gc = gc_new();
6185 6187
 
6186
-    if (tt)
6188
+    if (tt->did_ifconfig_ipv6_setup)
6187 6189
     {
6188
-        if (tt->did_ifconfig_ipv6_setup)
6189
-        {
6190
-            /* remove route pointing to interface */
6191
-            delete_route_connected_v6_net(tt, NULL);
6190
+        /* remove route pointing to interface */
6191
+        delete_route_connected_v6_net(tt, NULL);
6192 6192
 
6193
-            if (tt->options.msg_channel)
6193
+        if (tt->options.msg_channel)
6194
+        {
6195
+            do_address_service(false, AF_INET6, tt);
6196
+            if (tt->options.dns6_len > 0)
6194 6197
             {
6195
-                do_address_service(false, AF_INET6, tt);
6196
-                if (tt->options.dns6_len > 0)
6197
-                {
6198
-                    do_dns6_service(false, tt);
6199
-                }
6198
+                do_dns6_service(false, tt);
6200 6199
             }
6201
-            else
6202
-            {
6203
-                const char *ifconfig_ipv6_local;
6204
-                struct argv argv = argv_new();
6200
+        }
6201
+        else
6202
+        {
6203
+            const char *ifconfig_ipv6_local;
6204
+            struct argv argv = argv_new();
6205 6205
 
6206
-                /* "store=active" is needed in Windows 8(.1) to delete the
6207
-                 * address we added (pointed out by Cedric Tabary).
6208
-                 */
6206
+            /* "store=active" is needed in Windows 8(.1) to delete the
6207
+             * address we added (pointed out by Cedric Tabary).
6208
+             */
6209
+
6210
+            /* netsh interface ipv6 delete address \"%s\" %s */
6211
+            ifconfig_ipv6_local = print_in6_addr(tt->local_ipv6, 0,  &gc);
6212
+            argv_printf(&argv,
6213
+                        "%s%sc interface ipv6 delete address %s %s store=active",
6214
+                        get_win_sys_path(),
6215
+                        NETSH_PATH_SUFFIX,
6216
+                        tt->actual_name,
6217
+                        ifconfig_ipv6_local);
6209 6218
 
6210
-                /* netsh interface ipv6 delete address \"%s\" %s */
6211
-                ifconfig_ipv6_local = print_in6_addr(tt->local_ipv6, 0,  &gc);
6219
+            netsh_command(&argv, 1, M_WARN);
6220
+
6221
+            /* delete ipv6 dns servers if any were set */
6222
+            if (tt->options.dns6_len > 0)
6223
+            {
6212 6224
                 argv_printf(&argv,
6213
-                            "%s%sc interface ipv6 delete address %s %s store=active",
6225
+                            "%s%sc interface ipv6 delete dns %s all",
6214 6226
                             get_win_sys_path(),
6215 6227
                             NETSH_PATH_SUFFIX,
6216
-                            tt->actual_name,
6217
-                            ifconfig_ipv6_local);
6218
-
6228
+                            tt->actual_name);
6219 6229
                 netsh_command(&argv, 1, M_WARN);
6220
-
6221
-                /* delete ipv6 dns servers if any were set */
6222
-                if (tt->options.dns6_len > 0)
6223
-                {
6224
-                    argv_printf(&argv,
6225
-                                "%s%sc interface ipv6 delete dns %s all",
6226
-                                get_win_sys_path(),
6227
-                                NETSH_PATH_SUFFIX,
6228
-                                tt->actual_name);
6229
-                    netsh_command(&argv, 1, M_WARN);
6230
-                }
6231
-                argv_reset(&argv);
6232 6230
             }
6231
+            argv_reset(&argv);
6233 6232
         }
6233
+    }
6234 6234
 #if 1
6235
-        if (tt->ipapi_context_defined)
6235
+    if (tt->ipapi_context_defined)
6236
+    {
6237
+        DWORD status;
6238
+        if ((status = DeleteIPAddress(tt->ipapi_context)) != NO_ERROR)
6236 6239
         {
6237
-            DWORD status;
6238
-            if ((status = DeleteIPAddress(tt->ipapi_context)) != NO_ERROR)
6239
-            {
6240
-                msg(M_WARN, "Warning: DeleteIPAddress[%u] failed on TAP-Windows adapter, status=%u : %s",
6241
-                    (unsigned int)tt->ipapi_context,
6242
-                    (unsigned int)status,
6243
-                    strerror_win32(status, &gc));
6244
-            }
6240
+            msg(M_WARN, "Warning: DeleteIPAddress[%u] failed on TAP-Windows adapter, status=%u : %s",
6241
+                (unsigned int)tt->ipapi_context,
6242
+                (unsigned int)status,
6243
+                strerror_win32(status, &gc));
6245 6244
         }
6245
+    }
6246 6246
 #endif
6247 6247
 
6248
-        dhcp_release(tt);
6248
+    dhcp_release(tt);
6249 6249
 
6250
-        if (tt->hand != NULL)
6250
+    if (tt->hand != NULL)
6251
+    {
6252
+        dmsg(D_WIN32_IO_LOW, "Attempting CancelIO on TAP-Windows adapter");
6253
+        if (!CancelIo(tt->hand))
6251 6254
         {
6252
-            dmsg(D_WIN32_IO_LOW, "Attempting CancelIO on TAP-Windows adapter");
6253
-            if (!CancelIo(tt->hand))
6254
-            {
6255
-                msg(M_WARN | M_ERRNO, "Warning: CancelIO failed on TAP-Windows adapter");
6256
-            }
6255
+            msg(M_WARN | M_ERRNO, "Warning: CancelIO failed on TAP-Windows adapter");
6257 6256
         }
6257
+    }
6258 6258
 
6259
-        dmsg(D_WIN32_IO_LOW, "Attempting close of overlapped read event on TAP-Windows adapter");
6260
-        overlapped_io_close(&tt->reads);
6261
-
6262
-        dmsg(D_WIN32_IO_LOW, "Attempting close of overlapped write event on TAP-Windows adapter");
6263
-        overlapped_io_close(&tt->writes);
6259
+    dmsg(D_WIN32_IO_LOW, "Attempting close of overlapped read event on TAP-Windows adapter");
6260
+    overlapped_io_close(&tt->reads);
6264 6261
 
6265
-        if (tt->hand != NULL)
6266
-        {
6267
-            dmsg(D_WIN32_IO_LOW, "Attempting CloseHandle on TAP-Windows adapter");
6268
-            if (!CloseHandle(tt->hand))
6269
-            {
6270
-                msg(M_WARN | M_ERRNO, "Warning: CloseHandle failed on TAP-Windows adapter");
6271
-            }
6272
-        }
6262
+    dmsg(D_WIN32_IO_LOW, "Attempting close of overlapped write event on TAP-Windows adapter");
6263
+    overlapped_io_close(&tt->writes);
6273 6264
 
6274
-        if (tt->actual_name)
6265
+    if (tt->hand != NULL)
6266
+    {
6267
+        dmsg(D_WIN32_IO_LOW, "Attempting CloseHandle on TAP-Windows adapter");
6268
+        if (!CloseHandle(tt->hand))
6275 6269
         {
6276
-            free(tt->actual_name);
6270
+            msg(M_WARN | M_ERRNO, "Warning: CloseHandle failed on TAP-Windows adapter");
6277 6271
         }
6272
+    }
6278 6273
 
6279
-        clear_tuntap(tt);
6280
-        free(tt);
6274
+    if (tt->actual_name)
6275
+    {
6276
+        free(tt->actual_name);
6281 6277
     }
6278
+
6279
+    clear_tuntap(tt);
6280
+    free(tt);
6282 6281
     gc_free(&gc);
6283 6282
 }
6284 6283
 
... ...
@@ -6357,11 +6350,10 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
6357 6357
 void
6358 6358
 close_tun(struct tuntap *tt)
6359 6359
 {
6360
-    if (tt)
6361
-    {
6362
-        close_tun_generic(tt);
6363
-        free(tt);
6364
-    }
6360
+    ASSERT(tt);
6361
+
6362
+    close_tun_generic(tt);
6363
+    free(tt);
6365 6364
 }
6366 6365
 
6367 6366
 int