From: Antonio Quartulli Date: Mon, 5 Aug 2019 09:25:27 +0000 (+0200) Subject: tun.c: undo_ifconfig_ipv4/6 remove useless gc argument X-Git-Tag: v2.5_beta1~285 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e64d9c47d580427ed5e3d176dbcb7aa2ea55c4ba;p=thirdparty%2Fopenvpn.git tun.c: undo_ifconfig_ipv4/6 remove useless gc argument With the new networking APIs, each implementation handles garbage collection internally and therefore does not require a gc object to be provided by the outer layer. However, there are a few cases where a garbage collector is still required. In close_tun() move the declaration and cleanup of gc to the area where it is used and simplify the surrounding code a bit. While at it, fix a typo in a nearby ifdef comment. Signed-off-by: Antonio Quartulli Acked-by: Gert Doering Message-Id: <20190805092529.9467-5-a@unstable.cc> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18726.html Signed-off-by: Gert Doering --- diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 0ee6c11b1..0591df656 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -1938,9 +1938,8 @@ tuncfg(const char *dev, const char *dev_type, const char *dev_node, #endif /* ENABLE_FEATURE_TUN_PERSIST */ -void -undo_ifconfig_ipv4(struct tuntap *tt, struct gc_arena *gc, - openvpn_net_ctx_t *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); @@ -1962,7 +1961,7 @@ undo_ifconfig_ipv4(struct tuntap *tt, struct gc_arena *gc, tt->actual_name); } } -#else /* ifdef TARGET_LINUX */ +#else /* ifndef TARGET_LINUX */ struct argv argv = argv_new(); argv_printf(&argv, "%s %s 0.0.0.0", IFCONFIG_PATH, tt->actual_name); @@ -1974,9 +1973,8 @@ undo_ifconfig_ipv4(struct tuntap *tt, struct gc_arena *gc, #endif /* ifdef TARGET_LINUX */ } -void -undo_ifconfig_ipv6(struct tuntap *tt, struct gc_arena *gc, - openvpn_net_ctx_t *ctx) +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, @@ -1984,7 +1982,8 @@ undo_ifconfig_ipv6(struct tuntap *tt, struct gc_arena *gc, { msg(M_WARN, "Linux can't del IPv6 from iface %s", tt->actual_name); } -#else /* ifdef TARGET_LINUX */ +#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(); @@ -1995,6 +1994,7 @@ undo_ifconfig_ipv6(struct tuntap *tt, struct gc_arena *gc, openvpn_execve_check(&argv, NULL, 0, "Linux ip -6 addr del failed"); argv_reset(&argv); + gc_free(&gc); #endif /* ifdef TARGET_LINUX */ } @@ -2005,19 +2005,16 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) if (tt->type != DEV_TYPE_NULL) { - struct gc_arena gc = gc_new(); - if (tt->did_ifconfig_setup) { - undo_ifconfig_ipv4(tt, &gc, ctx); + undo_ifconfig_ipv4(tt, ctx); } if (tt->did_ifconfig_ipv6_setup) { - undo_ifconfig_ipv6(tt, &gc, ctx); + undo_ifconfig_ipv6(tt, ctx); } - gc_free(&gc); /* release resources potentially allocated during undo */ net_ctx_reset(ctx); }