From patchwork Sun Aug 4 23:25:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 791 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id QDOiHH/2R13tZgAAIUCqbw for ; Mon, 05 Aug 2019 05:27:27 -0400 Received: from proxy6.mail.ord1d.rsapps.net ([172.30.191.6]) by director10.mail.ord1d.rsapps.net with LMTP id mIxuHH/2R12mVgAApN4f7A ; Mon, 05 Aug 2019 05:27:27 -0400 Received: from smtp7.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy6.mail.ord1d.rsapps.net with LMTP id EFdKHH/2R13XZgAAQyIf0w ; Mon, 05 Aug 2019 05:27:27 -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: smtp7.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: 3d185202-b763-11e9-8ff9-bc305bf04148-1-1 Received: from [216.105.38.7] ([216.105.38.7:33958] helo=lists.sourceforge.net) by smtp7.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 50/F7-05825-F76F74D5; Mon, 05 Aug 2019 05:27:27 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1huZFp-0008RL-1I; Mon, 05 Aug 2019 09:26:09 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1huZFn-0008RC-Ee for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:26:07 +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=WX+Ica3im9VMI6c0E7VWmoYvPRWScm57DyAItiEYJFo=; b=bYyLBHJ3aUa/jzJTt1TjpmUjNP 6EmOMx+NjBJxs/BaqH/spIEJKJ4S/1Okd905mIz8U7exCZ62nirp6LrHYvycoaRt+F4cWSaOu4ULx AiUv2rZimVe3PJpdIdfEtgPOdcyQIdbGVudLG8xW0BSiuYq7OQtAFPO1X8yKRrEeyAow=; 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=WX+Ica3im9VMI6c0E7VWmoYvPRWScm57DyAItiEYJFo=; b=eI0XdlmSCBDh4ipoJ1763nCnvL FFZ6tUvAv/XlmmkJ2m6p4ALpZxMmBYLxD7BdEKBZXcsq4mENlrxduXJGiyglelOJlATk7C6t7BGsC 5TKsnt46+x8/Nyr0HTWEOICeN39GoPD5J9KF9WyJ4AQ9VArKiRYWlDI2hEA1QOWawVJM=; 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 1huZFl-00BSdI-40 for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:26:07 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Mon, 5 Aug 2019 11:25:24 +0200 Message-Id: <20190805092529.9467-2-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: 1huZFl-00BSdI-40 Subject: [Openvpn-devel] [PATCH 1/6] sitnl: harden strncpy() by forcing arguments to have the same length 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 At the moment a strcpy() (without length check!) is performed between a string long IFNAMSIZ bytes and one of 16 bytes. This is ok right now because IFNAMSIZ is defined as 16, however this bit is not under our control and may change in he future without us being warned. For this reason, force both strings to use IFNAMSIZ as size and, since this constant may not exist on every platform, ensure it is always defined. Signed-off-by: Antonio Quartulli Acked-by: Gert Doering --- src/openvpn/networking_sitnl.c | 2 +- src/openvpn/route.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c index 4e29d8ba..ea730ec7 100644 --- a/src/openvpn/networking_sitnl.c +++ b/src/openvpn/networking_sitnl.c @@ -494,7 +494,7 @@ sitnl_route_best_gw(sa_family_t af_family, const inet_address_t *dst, /* save result in output variables */ memcpy(best_gw, &res.gw, res.addr_size); - strcpy(best_iface, res.iface); + strncpy(best_iface, res.iface, IFNAMSIZ); err: return ret; diff --git a/src/openvpn/route.h b/src/openvpn/route.h index 31d38e36..2e68091c 100644 --- a/src/openvpn/route.h +++ b/src/openvpn/route.h @@ -184,7 +184,11 @@ struct route_ipv6_gateway_info { #ifdef _WIN32 DWORD adapter_index; /* interface or ~0 if undefined */ #else - char iface[16]; /* interface name (null terminated), may be empty */ + /* non linux platform don't have this constant defined */ +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif + char iface[IFNAMSIZ]; /* interface name (null terminated), may be empty */ #endif /* gateway interface hardware address */ From patchwork Sun Aug 4 23:25:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 795 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director9.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id gK4WFbX2R10CEwAAIUCqbw for ; Mon, 05 Aug 2019 05:28:21 -0400 Received: from proxy3.mail.ord1d.rsapps.net ([172.30.191.6]) by director9.mail.ord1d.rsapps.net with LMTP id sLTqFLX2R10CUQAAalYnBA ; Mon, 05 Aug 2019 05:28:21 -0400 Received: from smtp40.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy3.mail.ord1d.rsapps.net with LMTP id 8GyTFLX2R13tbQAA7WKfLA ; Mon, 05 Aug 2019 05:28:21 -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: smtp40.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: 5cfeee8c-b763-11e9-9722-525400b3abc9-1-1 Received: from [216.105.38.7] ([216.105.38.7:41978] helo=lists.sourceforge.net) by smtp40.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 8D/68-05047-4B6F74D5; Mon, 05 Aug 2019 05:28:20 -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-00040S-RX; 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-0003zz-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=1Ol1C7T+GRLF+ml3OXV2QA1sKevrgVegivp0k0EpY8s=; b=B5hWcF1CocmZQSswXK+Nruf0nv JQECeLpvKyROB3Y9izM2UcDBVqq59ZzxYedKJF20UAwh6li6xwEOlh8aASDlPc13M12pAmJrcw/OF inG6YJXXLsFPhDL6MdqJGJhwy8fxJYOeuIwaNeO3saIcITOADF/S3+FD0RVALtn7YT5w=; 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=1Ol1C7T+GRLF+ml3OXV2QA1sKevrgVegivp0k0EpY8s=; b=ADSROCbfNSh4stQW1CnLmlfpH/ rqVJEYsEybp4jzYrQaIlDOogPJY9yXmJITjT9oXV96anBGYKp4SkELtFkG/wInfaK1ehAiaWTX5lo Yfhp93I3m0cprp7YTb0YINNjbG+URbsGGxgMWZeePXpRWiUnhcuQSDSC2kMJtGVenZkQ=; 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 1huZH5-00BSio-HM 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:25 +0200 Message-Id: <20190805092529.9467-3-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: 1huZH5-00BSio-HM Subject: [Openvpn-devel] [PATCH 2/6] networking/best_gw: remove useless prefixlen parameter 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 The prefixlen parameter is not used at all while retrieving a route therefore it can safely be removed. Signed-off-by: Antonio Quartulli Acked-by: Gert Doering --- src/openvpn/networking.h | 7 ++----- src/openvpn/networking_iproute2.c | 4 ++-- src/openvpn/networking_sitnl.c | 20 +++++++++----------- src/openvpn/route.c | 4 ++-- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/openvpn/networking.h b/src/openvpn/networking.h index add45edc..cf967116 100644 --- a/src/openvpn/networking.h +++ b/src/openvpn/networking.h @@ -241,15 +241,13 @@ int net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, * * @param ctx the implementation specific context * @param dst The destination to lookup - * @param prefixlen The length of the prefix of the destination * @param best_gw Location where the retrieved GW has to be stored * @param best_iface Location where the retrieved interface has to be stored * * @return 0 on success, a negative error code otherwise */ int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, - int prefixlen, in_addr_t *best_gw, - openvpn_net_iface_t *best_iface); + in_addr_t *best_gw, openvpn_net_iface_t *best_iface); /** * Retrieve the gateway and outgoing interface for the specified IPv6 @@ -257,14 +255,13 @@ int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, * * @param ctx the implementation specific context * @param dst The destination to lookup - * @param prefixlen The length of the prefix of the destination * @param best_gw Location where the retrieved GW has to be stored * @param best_iface Location where the retrieved interface has to be stored * * @return 0 on success, a negative error code otherwise */ int net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, - int prefixlen, struct in6_addr *best_gw, + struct in6_addr *best_gw, openvpn_net_iface_t *best_iface); #endif /* ENABLE_SITNL || ENABLE_IPROUTE */ diff --git a/src/openvpn/networking_iproute2.c b/src/openvpn/networking_iproute2.c index a5824306..5db9a78b 100644 --- a/src/openvpn/networking_iproute2.c +++ b/src/openvpn/networking_iproute2.c @@ -325,7 +325,7 @@ net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, - int prefixlen, in_addr_t *best_gw, char *best_iface) + in_addr_t *best_gw, char *best_iface) { best_iface[0] = '\0'; @@ -378,7 +378,7 @@ net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, * uses the sitnl implementation from networking_sitnl.c. * * int - * net_route_v6_best_gw(const struct in6_addr *dst, int prefixlen, + * net_route_v6_best_gw(const struct in6_addr *dst, * struct in6_addr *best_gw, char *best_iface) */ diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c index ea730ec7..21563905 100644 --- a/src/openvpn/networking_sitnl.c +++ b/src/openvpn/networking_sitnl.c @@ -451,7 +451,7 @@ sitnl_route_save(struct nlmsghdr *n, void *arg) static int sitnl_route_best_gw(sa_family_t af_family, const inet_address_t *dst, - int prefixlen, void *best_gw, char *best_iface) + void *best_gw, char *best_iface) { struct sitnl_route_req req; route_res_t res; @@ -468,7 +468,6 @@ sitnl_route_best_gw(sa_family_t af_family, const inet_address_t *dst, req.n.nlmsg_flags = NLM_F_REQUEST; req.r.rtm_family = af_family; - req.r.rtm_dst_len = prefixlen; switch (af_family) { @@ -503,7 +502,7 @@ err: /* used by iproute2 implementation too */ int net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, - int prefixlen, struct in6_addr *best_gw, char *best_iface) + struct in6_addr *best_gw, char *best_iface) { inet_address_t dst_v6 = {0}; char buf[INET6_ADDRSTRLEN]; @@ -514,11 +513,10 @@ net_route_v6_best_gw(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, dst_v6.ipv6 = *dst; } - msg(D_ROUTE, "%s query: dst %s/%d", __func__, - inet_ntop(AF_INET6, &dst_v6.ipv6, buf, sizeof(buf)), prefixlen); + msg(D_ROUTE, "%s query: dst %s", __func__, + inet_ntop(AF_INET6, &dst_v6.ipv6, buf, sizeof(buf))); - ret = sitnl_route_best_gw(AF_INET6, &dst_v6, prefixlen, best_gw, - best_iface); + ret = sitnl_route_best_gw(AF_INET6, &dst_v6, best_gw, best_iface); if (ret < 0) { return ret; @@ -544,7 +542,7 @@ net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx) int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, - int prefixlen, in_addr_t *best_gw, char *best_iface) + in_addr_t *best_gw, char *best_iface) { inet_address_t dst_v4 = {0}; char buf[INET_ADDRSTRLEN]; @@ -555,10 +553,10 @@ net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, dst_v4.ipv4 = htonl(*dst); } - msg(D_ROUTE, "%s query: dst %s/%d", __func__, - inet_ntop(AF_INET, &dst_v4.ipv4, buf, sizeof(buf)), prefixlen); + msg(D_ROUTE, "%s query: dst %s", __func__, + inet_ntop(AF_INET, &dst_v4.ipv4, buf, sizeof(buf))); - ret = sitnl_route_best_gw(AF_INET, &dst_v4, prefixlen, best_gw, best_iface); + ret = sitnl_route_best_gw(AF_INET, &dst_v4, best_gw, best_iface); if (ret < 0) { return ret; diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 1341b4d2..bf036689 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -3172,7 +3172,7 @@ get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) #ifndef TARGET_ANDROID /* get default gateway IP addr */ - if (net_route_v4_best_gw(ctx, NULL, 0, &rgi->gateway.addr, best_name) == 0) + if (net_route_v4_best_gw(ctx, NULL, &rgi->gateway.addr, best_name) == 0) { rgi->flags |= RGI_ADDR_DEFINED; if (!rgi->gateway.addr && best_name[0]) @@ -3330,7 +3330,7 @@ get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, CLEAR(*rgi6); - if (net_route_v6_best_gw(ctx, dest, 0, &rgi6->gateway.addr_ipv6, + if (net_route_v6_best_gw(ctx, dest, &rgi6->gateway.addr_ipv6, rgi6->iface) == 0) { if (!IN6_IS_ADDR_UNSPECIFIED(rgi6->gateway.addr_ipv6.s6_addr)) From patchwork Sun Aug 4 23:25:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 794 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.28.255.1]) by backend30.mail.ord1d.rsapps.net with LMTP id cEMcCLH2R13tZgAAIUCqbw for ; Mon, 05 Aug 2019 05:28:17 -0400 Received: from proxy3.mail.ord1c.rsapps.net ([172.28.255.1]) by director7.mail.ord1d.rsapps.net with LMTP id 4OKyB7H2R12UBAAAovjBpQ ; Mon, 05 Aug 2019 05:28:17 -0400 Received: from smtp34.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy3.mail.ord1c.rsapps.net with LMTP id 4L+jB7H2R120HQAANIxBXg ; Mon, 05 Aug 2019 05:28:17 -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: smtp34.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: 5aac94ea-b763-11e9-8147-545200247500-1-1 Received: from [216.105.38.7] ([216.105.38.7:41876] helo=lists.sourceforge.net) by smtp34.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 56/7C-29355-0B6F74D5; Mon, 05 Aug 2019 05:28:16 -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 1huZHB-00041t-VW; Mon, 05 Aug 2019 09:27:33 +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 1huZHA-00041R-LC for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:27:32 +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=Htf/b03B0/ox/MV8TLNeBHTHsPBl2B7YCIMruXE2wgk=; b=Bq3ElfYjomlMXuBr5bzXZRLTaz 2wCYLxBZ8qzrc+r+aWhXCQ+OUF8riYmr+dYJfDG3wY5gJ0yxTRqJWu6qFmjHyoJf/hzQrNvXYhFp6 AgN5bAUJgm9Aup9OfGROldvSKUG1lxJO+XM5woR0o+MfxedOn1XSdiBTSBN9UiOANIow=; 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=Htf/b03B0/ox/MV8TLNeBHTHsPBl2B7YCIMruXE2wgk=; b=jfkr/DxDKNt7UnR82yr3jfUfyV AL1MUKTl3+zAQuXukPibjqeX6eVI5j9ZwBwWpstX4TDdxajJN77WTQ7eqtG16IYjW7uc60LVi6bKN rk4wIiwlpMS1QLTlmel9wE/S4gLizBXlmYOUOnA3rpCXoc7wc+Z33drsb6QlJ2D5Tvjg=; Received: from s2.neomailbox.net ([5.148.176.60]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1huZH8-00B3W5-SX for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:27:32 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Mon, 5 Aug 2019 11:25:26 +0200 Message-Id: <20190805092529.9467-4-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: 1huZH8-00B3W5-SX Subject: [Openvpn-devel] [PATCH 3/6] networking: extend API for better memory management 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 Networking backend implementations may need to allocate dynamic resources that require an explicit free/release. Since these cleanup are perfomed not very often, and only at specific times, it makes sense to have the upper layer signal when it's the right time to do so, by means of a new API call. For this purpose two news APIs have been implemented: - net_ctx_free() to release all backend specific resources. Expected to be called at application cleanup time; - net_ctx_reset() to let backends release temporary resources (i.e. reset garbage collectors). To be invoked after routines that are expected to allocate memory (i.e. tun setup or shutdown). In this patch related implementations for iproute2 and sitnl are also provided. Signed-off-by: Antonio Quartulli --- src/openvpn/networking.h | 26 +++++++++++ src/openvpn/networking_iproute2.c | 74 ++++++++++++------------------- src/openvpn/networking_iproute2.h | 1 + src/openvpn/networking_sitnl.c | 12 +++++ src/openvpn/openvpn.c | 1 + src/openvpn/route.c | 8 ++++ src/openvpn/tun.c | 5 +++ 7 files changed, 82 insertions(+), 45 deletions(-) diff --git a/src/openvpn/networking.h b/src/openvpn/networking.h index cf967116..4075ed73 100644 --- a/src/openvpn/networking.h +++ b/src/openvpn/networking.h @@ -39,6 +39,18 @@ net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx) { return 0; } + +static inline void +net_ctx_reset(openvpn_net_ctx_t *ctx) +{ + (void)ctx; +} + +static inline void +net_ctx_free(openvpn_net_ctx_t *ctx) +{ + (void)ctx; +} #endif #if defined(ENABLE_SITNL) || defined(ENABLE_IPROUTE) @@ -53,6 +65,20 @@ net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx) */ int net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx); +/** + * Release resources allocated by the internal garbage collector + * + * @param ctx the implementation specific context + */ +void net_ctx_reset(openvpn_net_ctx_t *ctx); + +/** + * Release all resources allocated within the platform specific context object + * + * @param ctx the implementation specific context to release + */ +void net_ctx_free(openvpn_net_ctx_t *ctx); + /** * Bring interface up or down. * diff --git a/src/openvpn/networking_iproute2.c b/src/openvpn/networking_iproute2.c index 5db9a78b..f06af724 100644 --- a/src/openvpn/networking_iproute2.c +++ b/src/openvpn/networking_iproute2.c @@ -43,10 +43,23 @@ net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx) ctx->es = NULL; if (c) ctx->es = c->es; + ctx->gc = gc_new(); return 0; } +void +net_ctx_reset(openvpn_net_ctx_t *ctx) +{ + gc_reset(&ctx->gc); +} + +void +net_ctx_free(openvpn_net_ctx_t *ctx) +{ + gc_free(&ctx->gc); +} + int net_iface_up(openvpn_net_ctx_t *ctx, const char *iface, bool up) { @@ -82,17 +95,14 @@ net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface, { struct argv argv = argv_new(); - char *addr_str = (char *)print_in_addr_t(*addr, 0, NULL); - char *brd_str = (char *)print_in_addr_t(*broadcast, 0, NULL); + char *addr_str = (char *)print_in_addr_t(*addr, 0, &ctx->gc); + char *brd_str = (char *)print_in_addr_t(*broadcast, 0, &ctx->gc); argv_printf(&argv, "%s addr add dev %s %s/%d broadcast %s", iproute_path, iface, addr_str, prefixlen, brd_str); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip addr add failed"); - free(addr_str); - free(brd_str); - argv_reset(&argv); return 0; @@ -103,7 +113,7 @@ net_addr_v6_add(openvpn_net_ctx_t *ctx, const char *iface, const struct in6_addr *addr, int prefixlen) { struct argv argv = argv_new(); - char *addr_str = (char *)print_in6_addr(*addr, 0, NULL); + char *addr_str = (char *)print_in6_addr(*addr, 0, &ctx->gc); argv_printf(&argv, "%s -6 addr add %s/%d dev %s", iproute_path, addr_str, prefixlen, iface); @@ -111,8 +121,6 @@ net_addr_v6_add(openvpn_net_ctx_t *ctx, const char *iface, openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip -6 addr add failed"); - free(addr_str); - argv_reset(&argv); return 0; @@ -123,7 +131,7 @@ net_addr_v4_del(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *addr, int prefixlen) { struct argv argv = argv_new(); - char *addr_str = (char *)print_in_addr_t(*addr, 0, NULL); + char *addr_str = (char *)print_in_addr_t(*addr, 0, &ctx->gc); argv_printf(&argv, "%s addr del dev %s %s/%d", iproute_path, iface, addr_str, prefixlen); @@ -131,8 +139,6 @@ net_addr_v4_del(openvpn_net_ctx_t *ctx, const char *iface, argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, 0, "Linux ip addr del failed"); - free(addr_str); - argv_reset(&argv); return 0; @@ -143,15 +149,13 @@ net_addr_v6_del(openvpn_net_ctx_t *ctx, const char *iface, const struct in6_addr *addr, int prefixlen) { struct argv argv = argv_new(); - char *addr_str = (char *)print_in6_addr(*addr, 0, NULL); + char *addr_str = (char *)print_in6_addr(*addr, 0, &ctx->gc); argv_printf(&argv, "%s -6 addr del %s/%d dev %s", iproute_path, addr_str, prefixlen, iface); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, 0, "Linux ip -6 addr del failed"); - free(addr_str); - argv_reset(&argv); return 0; @@ -162,17 +166,14 @@ net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local, const in_addr_t *remote) { struct argv argv = argv_new(); - char *local_str = (char *)print_in_addr_t(*local, 0, NULL); - char *remote_str = (char *)print_in_addr_t(*remote, 0, NULL); + char *local_str = (char *)print_in_addr_t(*local, 0, &ctx->gc); + char *remote_str = (char *)print_in_addr_t(*remote, 0, &ctx->gc); argv_printf(&argv, "%s addr add dev %s local %s peer %s", iproute_path, iface, local_str, remote_str); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, S_FATAL, "Linux ip addr add failed"); - free(local_str); - free(remote_str); - argv_reset(&argv); return 0; @@ -183,17 +184,14 @@ net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local, const in_addr_t *remote) { struct argv argv = argv_new(); - char *local_str = (char *)print_in_addr_t(*local, 0, NULL); - char *remote_str = (char *)print_in_addr_t(*remote, 0, NULL); + char *local_str = (char *)print_in_addr_t(*local, 0, &ctx->gc); + char *remote_str = (char *)print_in_addr_t(*remote, 0, &ctx->gc); argv_printf(&argv, "%s addr del dev %s local %s peer %s", iproute_path, iface, local_str, remote_str); argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, ctx->es, 0, "Linux ip addr del failed"); - free(local_str); - free(remote_str); - argv_reset(&argv); return 0; @@ -205,7 +203,7 @@ net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, int metric) { struct argv argv = argv_new(); - char *dst_str = (char *)print_in_addr_t(*dst, 0, NULL); + char *dst_str = (char *)print_in_addr_t(*dst, 0, &ctx->gc); argv_printf(&argv, "%s route add %s/%d", iproute_path, dst_str, prefixlen); @@ -217,18 +215,14 @@ net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, if (gw) { - char *gw_str = (char *)print_in_addr_t(*gw, 0, NULL); + char *gw_str = (char *)print_in_addr_t(*gw, 0, &ctx->gc); argv_printf_cat(&argv, "via %s", gw_str); - - free(gw_str); } argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, ctx->es, 0, "ERROR: Linux route add command failed"); - free(dst_str); - argv_reset(&argv); return 0; @@ -240,18 +234,16 @@ net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, uint32_t table, int metric) { struct argv argv = argv_new(); - char *dst_str = (char *)print_in6_addr(*dst, 0, NULL); + char *dst_str = (char *)print_in6_addr(*dst, 0, &ctx->gc); argv_printf(&argv, "%s -6 route add %s/%d dev %s", iproute_path, dst_str, prefixlen, iface); if (gw) { - char *gw_str = (char *)print_in6_addr(*gw, 0, NULL); + char *gw_str = (char *)print_in6_addr(*gw, 0, &ctx->gc); argv_printf_cat(&argv, "via %s", gw_str); - - free(gw_str); } if (metric > 0) @@ -260,8 +252,6 @@ net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, ctx->es, 0, "ERROR: Linux route -6 add command failed"); - free(dst_str); - argv_reset(&argv); return 0; @@ -273,7 +263,7 @@ net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, int metric) { struct argv argv = argv_new(); - char *dst_str = (char *)print_in_addr_t(*dst, 0, NULL); + char *dst_str = (char *)print_in_addr_t(*dst, 0, &ctx->gc); argv_printf(&argv, "%s route del %s/%d", iproute_path, dst_str, prefixlen); @@ -283,8 +273,6 @@ net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, ctx->es, 0, "ERROR: Linux route delete command failed"); - free(dst_str); - argv_reset(&argv); return 0; @@ -296,18 +284,16 @@ net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, uint32_t table, int metric) { struct argv argv = argv_new(); - char *dst_str = (char *)print_in6_addr(*dst, 0, NULL); + char *dst_str = (char *)print_in6_addr(*dst, 0, &ctx->gc); argv_printf(&argv, "%s -6 route del %s/%d dev %s", iproute_path, dst_str, prefixlen, iface); if (gw) { - char *gw_str = (char *)print_in6_addr(*gw, 0, NULL); + char *gw_str = (char *)print_in6_addr(*gw, 0, &ctx->gc); argv_printf_cat(&argv, "via %s", gw_str); - - free(gw_str); } if (metric > 0) @@ -316,8 +302,6 @@ net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, ctx->es, 0, "ERROR: Linux route -6 del command failed"); - free(dst_str); - argv_reset(&argv); return 0; diff --git a/src/openvpn/networking_iproute2.h b/src/openvpn/networking_iproute2.h index 47b50a9f..24c605db 100644 --- a/src/openvpn/networking_iproute2.h +++ b/src/openvpn/networking_iproute2.h @@ -29,6 +29,7 @@ typedef char openvpn_net_iface_t; struct openvpn_net_ctx { struct env_set *es; + struct gc_arena gc; }; typedef struct openvpn_net_ctx openvpn_net_ctx_t; diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c index 21563905..976ecd28 100644 --- a/src/openvpn/networking_sitnl.c +++ b/src/openvpn/networking_sitnl.c @@ -540,6 +540,18 @@ net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx) return 0; } +void +net_ctx_reset(openvpn_net_ctx_t *ctx) +{ + (void)ctx; +} + +void +net_ctx_free(openvpn_net_ctx_t *ctx) +{ + (void)ctx; +} + int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, in_addr_t *best_gw, char *best_iface) diff --git a/src/openvpn/openvpn.c b/src/openvpn/openvpn.c index fb02b3de..a58d5075 100644 --- a/src/openvpn/openvpn.c +++ b/src/openvpn/openvpn.c @@ -332,6 +332,7 @@ openvpn_main(int argc, char *argv[]) env_set_destroy(c.es); uninit_options(&c.options); gc_reset(&c.gc); + net_ctx_free(&c.net_ctx); } while (c.sig->signal_received == SIGHUP); } diff --git a/src/openvpn/route.c b/src/openvpn/route.c index bf036689..2d53c459 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -1826,6 +1826,8 @@ done: } argv_reset(&argv); gc_free(&gc); + /* release resources potentially allocated during route setup */ + net_ctx_reset(ctx); } @@ -2130,6 +2132,8 @@ done: } argv_reset(&argv); gc_free(&gc); + /* release resources potentially allocated during route setup */ + net_ctx_reset(ctx); } static void @@ -2322,6 +2326,8 @@ done: r->flags &= ~RT_ADDED; argv_reset(&argv); gc_free(&gc); + /* release resources potentially allocated during route cleanup */ + net_ctx_reset(ctx); } void @@ -2548,6 +2554,8 @@ delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt, argv_reset(&argv); gc_free(&gc); + /* release resources potentially allocated during route cleanup */ + net_ctx_reset(ctx); } /* diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 8f8f7c6c..e66e69bf 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -1435,6 +1435,9 @@ do_ifconfig(struct tuntap *tt, const char *ifname, int tun_mtu, { do_ifconfig_ipv6(tt, ifname, tun_mtu, es, ctx); } + + /* release resources potentially allocated during interface setup */ + net_ctx_free(ctx); } static void @@ -2027,6 +2030,8 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) } gc_free(&gc); + /* release resources potentially allocated during undo */ + net_ctx_reset(ctx); } close_tun_generic(tt); 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); } From patchwork Sun Aug 4 23:25:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 797 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director9.mail.ord1d.rsapps.net ([172.28.255.1]) by backend30.mail.ord1d.rsapps.net with LMTP id oJFfMsf2R120WQAAIUCqbw for ; Mon, 05 Aug 2019 05:28:39 -0400 Received: from proxy2.mail.ord1c.rsapps.net ([172.28.255.1]) by director9.mail.ord1d.rsapps.net with LMTP id mNAyMsf2R10BUQAAalYnBA ; Mon, 05 Aug 2019 05:28:39 -0400 Received: from smtp11.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy2.mail.ord1c.rsapps.net with LMTP id IC2VMcf2R13WCAAA311kuQ ; Mon, 05 Aug 2019 05:28:39 -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: smtp11.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: 6719aa74-b763-11e9-980d-bc305beffa54-1-1 Received: from [216.105.38.7] ([216.105.38.7:46140] helo=lists.sourceforge.net) by smtp11.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 21/17-25345-5C6F74D5; Mon, 05 Aug 2019 05:28:37 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1huZHB-0000gB-BP; Mon, 05 Aug 2019 09:27:33 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1huZHA-0000g3-2y for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:27:32 +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=TqogQfxSvnM4ZFUCEUtxzaJ5UbsruIi9poTNgaVzZyU=; b=Dlhx1dtKgpVx2o3ahZ+AwQxQPv ICvWBRpmgTHb6GOX96raaWYPPMQ5gk5XM9+9EwiRtLH4xQIlqmFFVc8VxRO2obPL+7du7S4TNAgkl 0a6//wqmVcgEysM+8WgzLNOlcDUJoHNplgFxULIRtmaSF/Z5ZMZ7jXipUM/rguIDcQ9c=; 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=TqogQfxSvnM4ZFUCEUtxzaJ5UbsruIi9poTNgaVzZyU=; b=l9Np8JJBERyxKOSnI8jbYsmhn2 1SMfrJz43WVOi3/61XbmRGEiIKU76TMDvGoYvyB1uICq38ZiWiHUJHLKJD8PmUegAGZAQX398Of8v vjPNZjdJZurKPuajd+0A24X9oj4/dyk7tPV4Js4jS/pyO63WyzEWXxSvj+fdtJKeeTdI=; 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 1huZH8-00BSiz-Hi for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:27:32 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Mon, 5 Aug 2019 11:25:28 +0200 Message-Id: <20190805092529.9467-6-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_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: 1huZH8-00BSiz-Hi Subject: [Openvpn-devel] [PATCH 5/6] networking_sitnl.c: uncrustify file 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 , Antonio Quartulli Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox Give this file a run under uncrustify to fix a few style glitches here and there. Signed-off-by: Antonio Quartulli Acked-by: Gert Doering --- src/openvpn/networking_sitnl.c | 62 +++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c index 976ecd28..e5c48932 100644 --- a/src/openvpn/networking_sitnl.c +++ b/src/openvpn/networking_sitnl.c @@ -45,7 +45,7 @@ #define SITNL_ADDATTR(_msg, _max_size, _attr, _data, _size) \ { \ - if (sitnl_addattr(_msg, _max_size, _attr, _data, _size) < 0)\ + if (sitnl_addattr(_msg, _max_size, _attr, _data, _size) < 0) \ { \ goto err; \ } \ @@ -335,16 +335,16 @@ sitnl_send(struct nlmsghdr *payload, pid_t peer, unsigned int groups, } /* if (((int)nladdr.nl_pid != peer) || (h->nlmsg_pid != nladdr.nl_pid) - || (h->nlmsg_seq != seq)) - { - rcv_len -= NLMSG_ALIGN(len); - h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); - msg(M_DEBUG, "%s: skipping unrelated message. nl_pid:%d (peer:%d) nl_msg_pid:%d nl_seq:%d seq:%d", - __func__, (int)nladdr.nl_pid, peer, h->nlmsg_pid, - h->nlmsg_seq, seq); - continue; - } -*/ + * || (h->nlmsg_seq != seq)) + * { + * rcv_len -= NLMSG_ALIGN(len); + * h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); + * msg(M_DEBUG, "%s: skipping unrelated message. nl_pid:%d (peer:%d) nl_msg_pid:%d nl_seq:%d seq:%d", + * __func__, (int)nladdr.nl_pid, peer, h->nlmsg_pid, + * h->nlmsg_seq, seq); + * continue; + * } + */ if (h->nlmsg_type == NLMSG_ERROR) { err = (struct nlmsgerr *)NLMSG_DATA(h); @@ -359,7 +359,9 @@ sitnl_send(struct nlmsghdr *payload, pid_t peer, unsigned int groups, { ret = 0; if (cb) + { ret = cb(h, arg_cb); + } } else { @@ -427,9 +429,11 @@ sitnl_route_save(struct nlmsghdr *n, void *arg) case RTA_OIF: ifindex = *(unsigned int *)RTA_DATA(rta); break; + /* route prefix */ case RTA_DST: break; + /* GW for the route */ case RTA_GATEWAY: memcpy(&res->gw, RTA_DATA(rta), res->addr_size); @@ -475,9 +479,11 @@ sitnl_route_best_gw(sa_family_t af_family, const inet_address_t *dst, res.addr_size = sizeof(in_addr_t); req.n.nlmsg_flags |= NLM_F_DUMP; break; + case AF_INET6: res.addr_size = sizeof(struct in6_addr); break; + default: /* unsupported */ return -EINVAL; @@ -598,7 +604,8 @@ net_iface_up(openvpn_net_ctx_t *ctx, const char *iface, bool up) } ifindex = if_nametoindex(iface); - if (ifindex == 0) { + if (ifindex == 0) + { msg(M_WARN, "%s: rtnl: cannot get ifindex for %s: %s", __func__, iface, strerror(errno)); return -ENOENT; @@ -612,9 +619,13 @@ net_iface_up(openvpn_net_ctx_t *ctx, const char *iface, bool up) req.i.ifi_index = ifindex; req.i.ifi_change |= IFF_UP; if (up) + { req.i.ifi_flags |= IFF_UP; + } else + { req.i.ifi_flags &= ~IFF_UP; + } msg(M_INFO, "%s: set %s %s", __func__, iface, up ? "up" : "down"); @@ -631,7 +642,8 @@ net_iface_mtu_set(openvpn_net_ctx_t *ctx, const char *iface, CLEAR(req); ifindex = if_nametoindex(iface); - if (ifindex == 0) { + if (ifindex == 0) + { msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __func__, iface); return -1; @@ -676,9 +688,11 @@ sitnl_addr_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_family, case AF_INET: size = sizeof(struct in_addr); break; + case AF_INET6: size = sizeof(struct in6_addr); break; + default: msg(M_WARN, "%s: rtnl: unknown address family %d", __func__, af_family); @@ -723,10 +737,12 @@ sitnl_addr_ptp_add(sa_family_t af_family, const char *iface, { int ifindex; - switch (af_family) { + switch (af_family) + { case AF_INET: case AF_INET6: break; + default: return -EINVAL; } @@ -755,10 +771,12 @@ sitnl_addr_ptp_del(sa_family_t af_family, const char *iface, { int ifindex; - switch (af_family) { + switch (af_family) + { case AF_INET: case AF_INET6: break; + default: return -EINVAL; } @@ -796,9 +814,11 @@ sitnl_route_set(int cmd, uint32_t flags, int ifindex, sa_family_t af_family, case AF_INET: size = sizeof(in_addr_t); break; + case AF_INET6: size = sizeof(struct in6_addr); break; + default: return -EINVAL; } @@ -859,12 +879,14 @@ sitnl_addr_add(sa_family_t af_family, const char *iface, { int ifindex; - switch (af_family) { + switch (af_family) + { case AF_INET: case AF_INET6: break; + default: - return -EINVAL;; + return -EINVAL; } if (!iface) @@ -891,12 +913,14 @@ sitnl_addr_del(sa_family_t af_family, const char *iface, inet_address_t *addr, { int ifindex; - switch (af_family) { + switch (af_family) + { case AF_INET: case AF_INET6: break; + default: - return -EINVAL;; + return -EINVAL; } if (!iface) From patchwork Sun Aug 4 23:25:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 793 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director12.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id gF85AKr2R13tZgAAIUCqbw for ; Mon, 05 Aug 2019 05:28:10 -0400 Received: from proxy15.mail.ord1d.rsapps.net ([172.30.191.6]) by director12.mail.ord1d.rsapps.net with LMTP id KOcJAKr2R12jPwAAIasKDg ; Mon, 05 Aug 2019 05:28:10 -0400 Received: from smtp8.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy15.mail.ord1d.rsapps.net with LMTP id uEhzO6n2R10iRQAAAY1PeQ ; Mon, 05 Aug 2019 05:28:10 -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: smtp8.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: 565a452c-b763-11e9-8f9d-782bcb03304b-1-1 Received: from [216.105.38.7] ([216.105.38.7:34278] helo=lists.sourceforge.net) by smtp8.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 71/BD-31452-9A6F74D5; Mon, 05 Aug 2019 05:28:09 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1huZHB-00006B-9X; Mon, 05 Aug 2019 09:27:33 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1huZHA-000063-Mv for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:27:32 +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=7jqR1HwdQZlS33FltKAg5Cycw56ExUVqIOQjTxhvmNQ=; b=CK17f4H6GPTqkHw1B87VBOOO6m GMS8bX1i8LY3AjRohVSH3+Ft3jQUwS8ifhju7reM+l0wltVqyV2lkIf3YCCccmymZKxior17HBm4H 4awPg4gg4Hl8POlRsJqhj1MbYhG+NL0yFAzeBsYvxlONCh3GcX+GaYX0wKQfDmWE8CNs=; 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=7jqR1HwdQZlS33FltKAg5Cycw56ExUVqIOQjTxhvmNQ=; b=TzKmBBsvk4ZjwRXOo6qtewkbFS tqZdgH4MGnMetX6vBez4fXyQGFXr6p+ccb4JAzufh9Fguz64KwmG8hUlJN2LHOM4qzxziO5r45IbT 8DNtgjdjjID+hItr/KUWJuIwccJLq/6UFjqrElEURaWrlftSAf2yxKCXvuY3n89Zt3Q4=; Received: from s2.neomailbox.net ([5.148.176.60]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1huZH9-00B3WD-7u for openvpn-devel@lists.sourceforge.net; Mon, 05 Aug 2019 09:27:32 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Mon, 5 Aug 2019 11:25:29 +0200 Message-Id: <20190805092529.9467-7-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: 1huZH9-00B3WD-7u Subject: [Openvpn-devel] [PATCH 6/6] route.c: simplify ifdef logic 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 , Antonio Quartulli Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox With the introduction of the new networking API layer on linux, some ifdefs can be pruned or simplified. While at it move some variable to improve readability. Signed-off-by: Antonio Quartulli Acked-by: Gert Doering --- src/openvpn/route.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 2d53c459..3ad87e26 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -1554,13 +1554,10 @@ add_route(struct route_ipv4 *r, struct argv argv = argv_new(); #if !defined(TARGET_LINUX) const char *network; -#if !defined(ENABLE_IPROUTE) && !defined(TARGET_AIX) +#if !defined(TARGET_AIX) const char *netmask; #endif const char *gateway; -#else - const char *iface; - int metric; #endif bool status = false; int is_local_route; @@ -1574,7 +1571,7 @@ add_route(struct route_ipv4 *r, #if !defined(TARGET_LINUX) network = print_in_addr_t(r->network, 0, &gc); -#if !defined(ENABLE_IPROUTE) && !defined(TARGET_AIX) +#if !defined(TARGET_AIX) netmask = print_in_addr_t(r->netmask, 0, &gc); #endif gateway = print_in_addr_t(r->gateway, 0, &gc); @@ -1587,13 +1584,14 @@ add_route(struct route_ipv4 *r, } #if defined(TARGET_LINUX) - iface = NULL; + const char *iface = NULL; + int metric = -1; + if (is_on_link(is_local_route, flags, rgi)) { iface = rgi->iface; } - metric = -1; if (r->flags & RT_METRIC_DEFINED) { metric = r->metric; @@ -2148,10 +2146,10 @@ delete_route(struct route_ipv4 *r, struct argv argv = argv_new(); #if !defined(TARGET_LINUX) const char *network; -#if !defined(ENABLE_IPROUTE) && !defined(TARGET_AIX) +#if !defined(TARGET_AIX) const char *netmask; #endif -#if !defined(TARGET_LINUX) && !defined(TARGET_ANDROID) +#if !defined(TARGET_ANDROID) const char *gateway; #endif #else @@ -2168,10 +2166,10 @@ delete_route(struct route_ipv4 *r, #if !defined(TARGET_LINUX) network = print_in_addr_t(r->network, 0, &gc); -#if !defined(ENABLE_IPROUTE) && !defined(TARGET_AIX) +#if !defined(TARGET_AIX) netmask = print_in_addr_t(r->netmask, 0, &gc); #endif -#if !defined(TARGET_LINUX) && !defined(TARGET_ANDROID) +#if !defined(TARGET_ANDROID) gateway = print_in_addr_t(r->gateway, 0, &gc); #endif #endif