net_ctx_free(ctx);
}
+static void
+undo_ifconfig_ipv4(struct tuntap *tt, openvpn_net_ctx_t *ctx)
+{
+#if defined(TARGET_LINUX)
+ int netbits = netmask_to_netbits2(tt->remote_netmask);
+
+ if (is_tun_p2p(tt))
+ {
+ if (net_addr_ptp_v4_del(ctx, tt->actual_name, &tt->local,
+ &tt->remote_netmask) < 0)
+ {
+ msg(M_WARN, "Linux can't del IP from iface %s",
+ tt->actual_name);
+ }
+ }
+ else
+ {
+ if (net_addr_v4_del(ctx, tt->actual_name, &tt->local, netbits) < 0)
+ {
+ msg(M_WARN, "Linux can't del IP from iface %s",
+ tt->actual_name);
+ }
+ }
+#elif !defined(_WIN32) /* if !defined(TARGET_LINUX) && !defined(_WIN32) */
+ struct argv argv = argv_new();
+
+ argv_printf(&argv, "%s %s 0.0.0.0", IFCONFIG_PATH, tt->actual_name);
+
+ argv_msg(M_INFO, &argv);
+ openvpn_execve_check(&argv, NULL, 0, "Generic ip addr del failed");
+
+ argv_free(&argv);
+#endif /* if defined(TARGET_LINUX) */
+ /* Empty for _WIN32. */
+}
+
+static void
+undo_ifconfig_ipv6(struct tuntap *tt, openvpn_net_ctx_t *ctx)
+{
+#if defined(TARGET_LINUX)
+ if (net_addr_v6_del(ctx, tt->actual_name, &tt->local_ipv6,
+ tt->netbits_ipv6) < 0)
+ {
+ msg(M_WARN, "Linux can't del IPv6 from iface %s", tt->actual_name);
+ }
+#elif !defined(_WIN32) /* if !defined(TARGET_LINUX) && !defined(_WIN32) */
+ struct gc_arena gc = gc_new();
+ const char *ifconfig_ipv6_local = print_in6_addr(tt->local_ipv6, 0, &gc);
+ struct argv argv = argv_new();
+
+ argv_printf(&argv, "%s %s del %s/%d", IFCONFIG_PATH, tt->actual_name,
+ ifconfig_ipv6_local, tt->netbits_ipv6);
+
+ argv_msg(M_INFO, &argv);
+ openvpn_execve_check(&argv, NULL, 0, "Generic ip -6 addr del failed");
+
+ argv_free(&argv);
+ gc_free(&gc);
+#endif /* if defined(TARGET_LINUX) */
+ /* Empty for _WIN32. */
+}
+
+void
+undo_ifconfig(struct tuntap *tt, openvpn_net_ctx_t *ctx)
+{
+ if (tt->type != DEV_TYPE_NULL)
+ {
+ if (tt->did_ifconfig_setup)
+ {
+ undo_ifconfig_ipv4(tt, ctx);
+ }
+
+ if (tt->did_ifconfig_ipv6_setup)
+ {
+ undo_ifconfig_ipv6(tt, ctx);
+ }
+
+ /* release resources potentially allocated during undo */
+ net_ctx_reset(ctx);
+ }
+}
+
static void
clear_tuntap(struct tuntap *tuntap)
{
#endif /* ENABLE_FEATURE_TUN_PERSIST */
-static void
-undo_ifconfig_ipv4(struct tuntap *tt, openvpn_net_ctx_t *ctx)
-{
-#if defined(TARGET_LINUX)
- int netbits = netmask_to_netbits2(tt->remote_netmask);
-
- if (is_tun_p2p(tt))
- {
- if (net_addr_ptp_v4_del(ctx, tt->actual_name, &tt->local,
- &tt->remote_netmask) < 0)
- {
- msg(M_WARN, "Linux can't del IP from iface %s",
- tt->actual_name);
- }
- }
- else
- {
- if (net_addr_v4_del(ctx, tt->actual_name, &tt->local, netbits) < 0)
- {
- msg(M_WARN, "Linux can't del IP from iface %s",
- tt->actual_name);
- }
- }
-#else /* ifndef TARGET_LINUX */
- struct argv argv = argv_new();
-
- argv_printf(&argv, "%s %s 0.0.0.0", IFCONFIG_PATH, tt->actual_name);
-
- argv_msg(M_INFO, &argv);
- openvpn_execve_check(&argv, NULL, 0, "Generic ip addr del failed");
-
- argv_free(&argv);
-#endif /* ifdef TARGET_LINUX */
-}
-
-static void
-undo_ifconfig_ipv6(struct tuntap *tt, openvpn_net_ctx_t *ctx)
-{
-#if defined(TARGET_LINUX)
- if (net_addr_v6_del(ctx, tt->actual_name, &tt->local_ipv6,
- tt->netbits_ipv6) < 0)
- {
- msg(M_WARN, "Linux can't del IPv6 from iface %s", tt->actual_name);
- }
-#else /* ifndef TARGET_LINUX */
- struct gc_arena gc = gc_new();
- const char *ifconfig_ipv6_local = print_in6_addr(tt->local_ipv6, 0, gc);
- struct argv argv = argv_new();
-
- argv_printf(&argv, "%s %s del %s/%d", IFCONFIG_PATH, tt->actual_name,
- ifconfig_ipv6_local, tt->netbits_ipv6);
-
- argv_msg(M_INFO, &argv);
- openvpn_execve_check(&argv, NULL, 0, "Linux ip -6 addr del failed");
-
- argv_free(&argv);
- gc_free(&gc);
-#endif /* ifdef TARGET_LINUX */
-}
-
void
close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
{
ASSERT(tt);
- if (tt->type != DEV_TYPE_NULL)
- {
- if (tt->did_ifconfig_setup)
- {
- undo_ifconfig_ipv4(tt, ctx);
- }
-
- if (tt->did_ifconfig_ipv6_setup)
- {
- undo_ifconfig_ipv6(tt, ctx);
- }
-
- /* release resources potentially allocated during undo */
- net_ctx_reset(ctx);
- }
-
#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
if (tun_dco_enabled(tt))
{