From patchwork Fri Aug 19 08:24:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 2703 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director8.mail.ord1d.rsapps.net ([172.28.255.1]) by backend30.mail.ord1d.rsapps.net with LMTP id gB99Lsva/2KYOgAAIUCqbw (envelope-from ) for ; Fri, 19 Aug 2022 14:47:39 -0400 Received: from proxy7.mail.ord1c.rsapps.net ([172.28.255.1]) by director8.mail.ord1d.rsapps.net with LMTP id kHJMLsva/2IBLgAAfY0hYg (envelope-from ) for ; Fri, 19 Aug 2022 14:47:39 -0400 Received: from smtp7.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy7.mail.ord1c.rsapps.net with LMTPS id MKOLLcva/2IzfwAAknS3pQ (envelope-from ) for ; Fri, 19 Aug 2022 14:47: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: 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=greenie.muc.de X-Suspicious-Flag: YES X-Classification-ID: 658bb15a-1fef-11ed-9348-bc305bf04148-1-1 Received: from [216.105.38.7] ([216.105.38.7:45000] 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 F4/81-11089-ACADFF26; Fri, 19 Aug 2022 14:47:38 -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.95) (envelope-from ) id 1oP70y-0007a9-Vv; Fri, 19 Aug 2022 18:46:40 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oP70x-0007a2-CE for openvpn-devel@lists.sourceforge.net; Fri, 19 Aug 2022 18:46:39 +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=fQnogTLv7q8tWT06I7dKWFLDOlJC8hfzWdwv3aZ4N9A=; b=W+PeEEAgo3uo4PPtTcBgcofTGJ /k1JoOZcmXrJp5Z1U2zZ6PUJwulTdHHUgeHXxQsaznMy6xrEE3psIdGSbw15yM732i7uMpjpUZ5So TyXSQntOUnfFm9Ap2j7j/3e0UmRUKQwp9CRI5zoDHwpSywbpb5+9Dc3gHLToc2ACcSKU=; 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=fQnogTLv7q8tWT06I7dKWFLDOlJC8hfzWdwv3aZ4N9A=; b=B 3GvPmoh7jg56WNuxh4f2IAD9o20G8NwciJBZOhc9AVH/AdEQ4uBcynJuYr9D+eoSHe5hUma6MVjsk OEiKF5e5s4PfK/paWB/vbxGeCvz7DHX1AFFs0AB0zFtsZnePsSCysFkx9gCTAEvKC4DMGcTxFi0t7 307xOGnam0NvtIGM=; Received: from vmail1.greenie.net ([195.30.8.66]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1oP70t-0006nj-Hr for openvpn-devel@lists.sourceforge.net; Fri, 19 Aug 2022 18:46:39 +0000 Received: from fbsd14.ov.greenie.net (fbsd14.ov.greenie.net [IPv6:2001:608:0:814:0:0:fb00:14]) by vmail1.greenie.net (8.17.1/8.16.1) with ESMTPS id 27JIOdEo045798 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=FAIL); Fri, 19 Aug 2022 20:24:39 +0200 (CEST) Received: from fbsd14.ov.greenie.net (localhost [127.0.0.1]) by fbsd14.ov.greenie.net (8.16.1/8.16.1) with ESMTPS id 27JIOdZh071540 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 19 Aug 2022 20:24:39 +0200 (CEST) (envelope-from gert@fbsd14.ov.greenie.net) Received: (from gert@localhost) by fbsd14.ov.greenie.net (8.16.1/8.16.1/Submit) id 27JIOdg3071539; Fri, 19 Aug 2022 20:24:39 +0200 (CEST) (envelope-from gert) From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Fri, 19 Aug 2022 20:24:39 +0200 Message-Id: <20220819182439.71531-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.4 (vmail1.greenie.net [IPv6:2001:608:1:995a:20c:29ff:feb8:10eb]); Fri, 19 Aug 2022 20:24:39 +0200 (CEST) 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: During review/update phase, FreeBSD/DCO's ability to find the first free tun interface on "--dev tun" got broken, due to two issues: - create_interface() called msg(M_ERR|...), which is a fatal error and aborts OpenVPN, so "no retry with 'tun1' after 'tun0' failed" Content analysis details: (-2.1 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [195.30.8.66 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1oP70t-0006nj-Hr Subject: [Openvpn-devel] [PATCH] FreeBSD-DCO: repair device iteration to find first free interface. 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 During review/update phase, FreeBSD/DCO's ability to find the first free tun interface on "--dev tun" got broken, due to two issues: - create_interface() called msg(M_ERR|...), which is a fatal error and aborts OpenVPN, so "no retry with 'tun1' after 'tun0' failed" Change to M_WARN|M_ERRNO (= warning level, add strerror(errno), return). - open_tun_dco_generic() expects "-errno" as return value of open_tun_dco(), and breaks the loop on -EPERM. create_interface() was returning "-1" instead (ioctl() error signalling), which happens to be "-EPERM" on FreeBSD. Change create_interface() to return -errno. While at it, remove logging of errors from dco_freebsd.c::open_tun_dco() (because all errors from create_interface() would be already logged there), reducing open_tun_dco() to just a wrapper around create_interface(). Signed-off-by: Gert Doering Acked-by: Kristof Provost --- src/openvpn/dco_freebsd.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index 06b4d6a9..c6da6ce3 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -178,7 +178,8 @@ create_interface(struct tuntap *tt, const char *dev) ret = ioctl(tt->dco.fd, SIOCIFCREATE2, &ifr); if (ret) { - msg(M_ERR | M_ERRNO, "Failed to create interface %s", ifr.ifr_name); + ret = -errno; + msg(M_WARN|M_ERRNO, "Failed to create interface %s (SIOCIFCREATE2)", ifr.ifr_name); return ret; } @@ -194,9 +195,10 @@ create_interface(struct tuntap *tt, const char *dev) ret = ioctl(tt->dco.fd, SIOCSIFNAME, &ifr); if (ret) { + ret = -errno; /* Delete the created interface again. */ (void)ioctl(tt->dco.fd, SIOCIFDESTROY, &ifr); - msg(M_ERR | M_ERRNO, "Failed to create interface %s", ifr.ifr_data); + msg(M_WARN|M_ERRNO, "Failed to create interface %s (SIOCSIFNAME)", ifr.ifr_data); return ret; } @@ -229,16 +231,7 @@ remove_interface(struct tuntap *tt) int open_tun_dco(struct tuntap *tt, openvpn_net_ctx_t *ctx, const char *dev) { - int ret; - - ret = create_interface(tt, dev); - - if (ret < 0) - { - msg(M_ERR, "Failed to create interface"); - } - - return ret; + return create_interface(tt, dev); } void