From patchwork Mon Aug 2 05:26:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 1904 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director15.mail.ord1d.rsapps.net ([172.28.255.1]) by backend30.mail.ord1d.rsapps.net with LMTP id OEGRMeEOCGElFAAAIUCqbw (envelope-from ) for ; Mon, 02 Aug 2021 11:27:29 -0400 Received: from proxy6.mail.ord1c.rsapps.net ([172.28.255.1]) by director15.mail.ord1d.rsapps.net with LMTP id oM5GMeEOCGGPFgAAIcMcQg (envelope-from ) for ; Mon, 02 Aug 2021 11:27:29 -0400 Received: from smtp5.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy6.mail.ord1c.rsapps.net with LMTPS id 4NP3MOEOCGFkcgAA9sKXow (envelope-from ) for ; Mon, 02 Aug 2021 11:27:29 -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: smtp5.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=greenie.muc.de X-Suspicious-Flag: YES X-Classification-ID: 2587f7b0-f3a6-11eb-93fc-a4badb0b200d-1-1 Received: from [216.105.38.7] ([216.105.38.7:53906] helo=lists.sourceforge.net) by smtp5.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 06/10-01092-0EE08016; Mon, 02 Aug 2021 11:27:29 -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 1mAZpw-0006XS-3T; Mon, 02 Aug 2021 15:26:40 +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 1mAZpu-0006X4-0z for openvpn-devel@lists.sourceforge.net; Mon, 02 Aug 2021 15:26:38 +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:To:From:Sender:Reply-To:Cc: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=6EwTeqiduKXSDlQ7y5A8B9uAFOh27It34XMmDdGPuFw=; b=dC8BCDPM0DpzCtZN0YmTjbuCFm oP2NXdwrYi1tdrXao7/xEiyrK0aGM3U0yJL3gQL1v92Oegu88u3kmzP2pg4wlJkCfFufXYgb0Mxw7 /XCQYN12ApbmPS25qH/04hF2utzvKYavI57H1QtNumkPbAVHD6AlcTdV/go//ytC+Buc=; 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:To:From:Sender:Reply-To:Cc: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=6EwTeqiduKXSDlQ7y5A8B9uAFOh27It34XMmDdGPuFw=; b=fFpllyF0dMucFBcJQhFTxbT2ae ljDdhPZWB0wU1s9iH7gItUWDfuqLNWoW/y3zE+K3W5/1v956QRkNeDXQge93RX9KpbPpzqyDRxWpk 1b64lwmnbWw0btiAvrvOgFNI0QeqXkPYkuXevhrIbEfMD2aI5NDkhppilNxYvsKuSGf4=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) id 1mAZpn-0005Dq-Re for openvpn-devel@lists.sourceforge.net; Mon, 02 Aug 2021 15:26:37 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.15.2/8.14.9) with ESMTP id 172FQLhT030807 for ; Mon, 2 Aug 2021 17:26:21 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.15.2/8.14.9/Submit) id 172FQLLx030806 for openvpn-devel@lists.sourceforge.net; Mon, 2 Aug 2021 17:26:21 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Mon, 2 Aug 2021 17:26:19 +0200 Message-Id: <20210802152619.30754-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210727143741.29039-1-gert@greenie.muc.de> References: <20210727143741.29039-1-gert@greenie.muc.de> MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1mAZpn-0005Dq-Re Subject: [Openvpn-devel] [PATCH v2] Use more C99 initialization in add_route/add_route_ipv6(). 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: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox This gets rid of a few #ifdef and also removes the need for commit a11bea18b1c93 (argv is only initialized after the early exit check on RT_DEFINED). v2: use gc_new(), group gc and argv init in both add_route*() functions Signed-off-by: Gert Doering Acked-by: Antonio Quartulli --- src/openvpn/route.c | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/src/openvpn/route.c b/src/openvpn/route.c index e429e8c0..2905e432 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -1570,32 +1570,23 @@ add_route(struct route_ipv4 *r, const struct env_set *es, openvpn_net_ctx_t *ctx) { - struct gc_arena gc; - struct argv argv = argv_new(); -#if !defined(TARGET_LINUX) - const char *network; -#if !defined(TARGET_AIX) - const char *netmask; -#endif - const char *gateway; -#endif bool status = false; int is_local_route; if (!(r->flags & RT_DEFINED)) { - argv_free(&argv); return; } - gc_init(&gc); + struct argv argv = argv_new(); + struct gc_arena gc = gc_new(); #if !defined(TARGET_LINUX) - network = print_in_addr_t(r->network, 0, &gc); + const char *network = print_in_addr_t(r->network, 0, &gc); #if !defined(TARGET_AIX) - netmask = print_in_addr_t(r->netmask, 0, &gc); + const char *netmask = print_in_addr_t(r->netmask, 0, &gc); #endif - gateway = print_in_addr_t(r->gateway, 0, &gc); + const char *gateway = print_in_addr_t(r->gateway, 0, &gc); #endif is_local_route = local_route(r->network, r->netmask, r->gateway, rgi); @@ -1878,24 +1869,18 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx) { - struct gc_arena gc; - struct argv argv = argv_new(); - - const char *network; - const char *gateway; bool status = false; const char *device = tt->actual_name; -#if defined(TARGET_LINUX) - int metric; -#endif bool gateway_needed = false; if (!(r6->flags & RT_DEFINED) ) { - argv_free(&argv); return; } + struct argv argv = argv_new(); + struct gc_arena gc = gc_new(); + #ifndef _WIN32 if (r6->iface != NULL) /* vpn server special route */ { @@ -1907,12 +1892,9 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, } #endif - gc_init(&gc); - route_ipv6_clear_host_bits(r6); - - network = print_in6_addr( r6->network, 0, &gc); - gateway = print_in6_addr( r6->gateway, 0, &gc); + const char *network = print_in6_addr( r6->network, 0, &gc); + const char *gateway = print_in6_addr( r6->gateway, 0, &gc); #if defined(TARGET_DARWIN) \ || defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \ @@ -1963,7 +1945,7 @@ add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, } #if defined(TARGET_LINUX) - metric = -1; + int metric = -1; if ((r6->flags & RT_METRIC_DEFINED) && (r6->metric > 0)) { metric = r6->metric;