From patchwork Sun Aug 4 23:25:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 796 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id MEjgEMD2R13QZgAAIUCqbw for ; Mon, 05 Aug 2019 05:28:32 -0400 Received: from proxy5.mail.ord1d.rsapps.net ([172.30.191.6]) by director11.mail.ord1d.rsapps.net with LMTP id 8PuoEMD2R138XwAAvGGmqA ; Mon, 05 Aug 2019 05:28:32 -0400 Received: from smtp23.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy5.mail.ord1d.rsapps.net with LMTP id EHZ4EMD2R11FIAAA8Zzt7w ; Mon, 05 Aug 2019 05:28:32 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp23.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=unstable.cc X-Suspicious-Flag: YES X-Classification-ID: 63d175a4-b763-11e9-b817-b8ca3a678528-1-1 Received: from [216.105.38.7] ([216.105.38.7:42274] helo=lists.sourceforge.net) by smtp23.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 0B/A2-24272-FB6F74D5; Mon, 05 Aug 2019 05:28:32 -0400 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1huZH8-00040K-Oy; Mon, 05 Aug 2019 09:27:30 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1huZH7-0003zy-Ow for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:27:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Psp9DXv0vo8PKkmI6YpfWmwJ7oy968qpI+VgELdrKFQ=; b=GfJcNwLnEQSaKzFC6u5OnoHmmE YlU1qfPPQQuBJtpnVnhloRIIJsFk7LBncC/cvguQdZDZKIrcVDE2ow1ojnnBydlhHETyF1XheX3uE 3mbyPxz3XnRcDi5BaOxB6RlXcXVzl1gtvvSTDoPPcmanPyHW+KVbMiJ7a7aHEFrPBEo0=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Psp9DXv0vo8PKkmI6YpfWmwJ7oy968qpI+VgELdrKFQ=; b=cKsKsMQ74xPfKam6Wq6SOy/y3B JJVrYvbvRO6Cz3G5Nvb6mQ0f81uPTwaTrCyD/llTyEbr/CAs9aBB3S8uqw4YefkD5wt9AbXku2+sB Qz329Z5gv42iLKAONoGwROIDlNq1FqHm0IQ+oKVs5ufAgSiABoHYW/sLeI339c7GRCqo=; Received: from s2.neomailbox.net ([5.148.176.60]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1huZH6-00BSiq-4I for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:27:29 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Mon, 5 Aug 2019 11:25:27 +0200 Message-Id: <20190805092529.9467-5-a@unstable.cc> In-Reply-To: <20190805092529.9467-1-a@unstable.cc> References: <20190805092529.9467-1-a@unstable.cc> MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [5.148.176.60 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1huZH6-00BSiq-4I Subject: [Openvpn-devel] [PATCH 4/6] tun.c: undo_ifconfig_ipv4/6 remove useless gc argument X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Antonio Quartulli Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Antonio Quartulli 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 --- src/openvpn/tun.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index e66e69bf..bda4df95 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -1950,9 +1950,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); @@ -1974,7 +1973,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); @@ -1986,9 +1985,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, @@ -1996,7 +1994,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(); @@ -2007,6 +2006,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 */ } @@ -2017,19 +2017,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); }