From patchwork Tue Jul 12 12:09:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 2584 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 uA/NOFvxzWJgNgAAIUCqbw (envelope-from ) for ; Tue, 12 Jul 2022 18:10:35 -0400 Received: from proxy3.mail.ord1d.rsapps.net ([172.30.191.6]) by director12.mail.ord1d.rsapps.net with LMTP id gB7TOFvxzWLcTQAAIasKDg (envelope-from ) for ; Tue, 12 Jul 2022 18:10:35 -0400 Received: from smtp8.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy3.mail.ord1d.rsapps.net with LMTPS id 6BF4OFvxzWLVGgAA7WKfLA (envelope-from ) for ; Tue, 12 Jul 2022 18:10:35 -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.ord1d.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: 740328a4-022f-11ed-9ce4-5254001e5a60-1-1 Received: from [216.105.38.7] ([216.105.38.7:48894] helo=lists.sourceforge.net) by smtp8.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id E6/D1-02350-B51FDC26; Tue, 12 Jul 2022 18:10:35 -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.94.2) (envelope-from ) id 1oBO4U-0007xQ-Ex; Tue, 12 Jul 2022 22:09:33 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oBO4T-0007xG-2M for openvpn-devel@lists.sourceforge.net; Tue, 12 Jul 2022 22:09:31 +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: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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=5vs+Yto2ktjZSil14ytR+4AN9PZnUyGzUwvde0iaKF8=; b=dlW23ogwYocunrhb0DY7J7+bqD Yl2mXagmC78OxBhmtY10Fn96uKmTaiyMmo9T6QeAHRI5mdRhAAYla+2YxVf0ngYxmmTTx4y7IVyKJ QSmKNp372XId+UIPJxY+2qT3sFLn6vzb3U7kbW4afDep87wouTVrpVkAVAEtyX+0OMGg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version: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:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=5vs+Yto2ktjZSil14ytR+4AN9PZnUyGzUwvde0iaKF8=; b=d XVanfTjfFbeAjfrD89lOAbMmbQFDN7ZosDHkVPZprPdNpQ2PZYlOmW88l5cIU0BrizN0KTOwi5Tyz xoXlUQ06WnDbg5KeiVsaZxSQVrezw2YabY6uhXZYQRJk8FIW1S5xWRzjjEBlzHdc1qyPIUEiQWB1Y U3AzfC0dY1lS9KK4=; Received: from [5.148.176.60] (helo=s2.neomailbox.net) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1oBO4P-0003h8-US for openvpn-devel@lists.sourceforge.net; Tue, 12 Jul 2022 22:09:31 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Wed, 13 Jul 2022 00:09:17 +0200 Message-Id: <20220712220917.4114-1-a@unstable.cc> MIME-Version: 1.0 X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: if_nametoindex() sets errno to the related error code in case of failure. For this reason the caller function should rather propagate this value instead of coming up with its own. Right now instead we have: * return -1 * return -ENOENT * return errno (positive value!!) Content analysis details: (1.3 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1oBO4P-0003h8-US Subject: [Openvpn-devel] [PATCH] networking_sitnl: standardize returned error when no ifindex can be retrieved 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 if_nametoindex() sets errno to the related error code in case of failure. For this reason the caller function should rather propagate this value instead of coming up with its own. Right now instead we have: * return -1 * return -ENOENT * return errno (positive value!!) Make all code behave the same and always return -errno in case of failure. Most common error will still be -ENODEV, when no device with the provided name could be found. Signed-off-by: Antonio Quartulli --- src/openvpn/networking_sitnl.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c index b2f3ac72..29b7d8c2 100644 --- a/src/openvpn/networking_sitnl.c +++ b/src/openvpn/networking_sitnl.c @@ -660,7 +660,7 @@ net_iface_up(openvpn_net_ctx_t *ctx, const char *iface, bool up) { msg(M_WARN, "%s: rtnl: cannot get ifindex for %s: %s", __func__, iface, strerror(errno)); - return -ENOENT; + return -errno; } req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.i)); @@ -698,7 +698,7 @@ net_iface_mtu_set(openvpn_net_ctx_t *ctx, const char *iface, { msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __func__, iface); - return -1; + return -errno; } req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.i)); @@ -731,7 +731,7 @@ net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, { msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __func__, iface); - return -1; + return -errno; } req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.i)); @@ -839,7 +839,7 @@ sitnl_addr_ptp_add(sa_family_t af_family, const char *iface, { msg(M_WARN, "%s: cannot get ifindex for %s: %s", __func__, np(iface), strerror(errno)); - return -ENOENT; + return -errno; } return sitnl_addr_set(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, ifindex, @@ -872,7 +872,7 @@ sitnl_addr_ptp_del(sa_family_t af_family, const char *iface, if (ifindex == 0) { msg(M_WARN | M_ERRNO, "%s: cannot get ifindex for %s", __func__, iface); - return -ENOENT; + return -errno; } return sitnl_addr_set(RTM_DELADDR, 0, ifindex, af_family, local, NULL, 0); @@ -979,7 +979,7 @@ sitnl_addr_add(sa_family_t af_family, const char *iface, { msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __func__, iface); - return -ENOENT; + return -errno; } return sitnl_addr_set(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, ifindex, @@ -1013,7 +1013,7 @@ sitnl_addr_del(sa_family_t af_family, const char *iface, inet_address_t *addr, { msg(M_WARN | M_ERRNO, "%s: rtnl: cannot get ifindex for %s", __func__, iface); - return -ENOENT; + return -errno; } return sitnl_addr_set(RTM_DELADDR, 0, ifindex, af_family, addr, NULL, @@ -1163,7 +1163,7 @@ sitnl_route_add(const char *iface, sa_family_t af_family, const void *dst, { msg(M_WARN | M_ERRNO, "%s: rtnl: can't get ifindex for %s", __func__, iface); - return -ENOENT; + return -errno; } } @@ -1256,7 +1256,7 @@ sitnl_route_del(const char *iface, sa_family_t af_family, inet_address_t *dst, { msg(M_WARN | M_ERRNO, "%s: rtnl: can't get ifindex for %s", __func__, iface); - return -ENOENT; + return -errno; } } @@ -1483,7 +1483,7 @@ net_iface_del(openvpn_net_ctx_t *ctx, const char *iface) if (!ifindex) { - return errno; + return -errno; } req.n.nlmsg_len = NLMSG_LENGTH(sizeof(req.i));