From patchwork Tue Jul 12 12:16:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 2586 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director8.mail.ord1d.rsapps.net ([172.27.255.52]) by backend30.mail.ord1d.rsapps.net with LMTP id 0CjMJgDzzWIBQAAAIUCqbw (envelope-from ) for ; Tue, 12 Jul 2022 18:17:36 -0400 Received: from proxy2.mail.iad3a.rsapps.net ([172.27.255.52]) by director8.mail.ord1d.rsapps.net with LMTP id wDbYJgDzzWJlRgAAfY0hYg (envelope-from ) for ; Tue, 12 Jul 2022 18:17:36 -0400 Received: from smtp37.gate.iad3a ([172.27.255.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy2.mail.iad3a.rsapps.net with LMTPS id iNBlHgDzzWLVRQAABcWvHw (envelope-from ) for ; Tue, 12 Jul 2022 18:17:36 -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: smtp37.gate.iad3a.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: 6e39959c-0230-11ed-a661-525400dc5f6a-1-1 Received: from [216.105.38.7] ([216.105.38.7:43964] helo=lists.sourceforge.net) by smtp37.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 6E/FC-04169-FF2FDC26; Tue, 12 Jul 2022 18:17:35 -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.94.2) (envelope-from ) id 1oBOBJ-0006uJ-Rt; Tue, 12 Jul 2022 22:16:37 +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.94.2) (envelope-from ) id 1oBOBI-0006uD-Oc for openvpn-devel@lists.sourceforge.net; Tue, 12 Jul 2022 22:16:36 +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=8qzs/r/wU8gPNrJ9V5bHjtAYdfZ1HnN7B0XmFc7+aYE=; b=b3e08bjbYcGlRwxvxL3SuwYp3+ jCkWz/fH86wH42iwUHF0YSAwy9neNfQhRbYdpJFHpsK9SEEHhIxw8T4lza1cVzmrQS1ZslsVtbED5 7hJiR+maZjhWSz/kwE9TZZxr0CWW2CJvGLb3VPFDLVJHUCm2+Z9T3BlauiKaS6o7F7SY=; 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=8qzs/r/wU8gPNrJ9V5bHjtAYdfZ1HnN7B0XmFc7+aYE=; b=mpcnRKE2EhNf4AyqC04Ylz+/5y lPmeBOY+mfWdUo6hJIx51XhqS+qyA/T5xM98Z/lBpirbseYC8oG+lj5whgqGYo4rV0vL+zYlBXa+E z3bX4LvtHWzXunv3hsYp9C4cCXZKtZ0SigvSHiiaLZ47X9kNHzyZ8nOGuzVWL3Y8mYRo=; Received: from s2.neomailbox.net ([5.148.176.60]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1oBOBG-00F82C-Pi for openvpn-devel@lists.sourceforge.net; Tue, 12 Jul 2022 22:16:36 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Wed, 13 Jul 2022 00:16:55 +0200 Message-Id: <20220712221655.19333-1-a@unstable.cc> In-Reply-To: <20220624083809.23487-8-a@unstable.cc> References: MIME-Version: 1.0 X-Spam-Report: Spam detection software, running on the system "util-spamd-1.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: This helper encloses the (simple) logic used by OpenVPN to determine if the name passed to --dev has to be considered a fixed interface name or just a pattern. Having a helper is useful because when this logic is required elsewhere, we can just re-use this logic without duplicating the code (which may mean introducing bugs if a future logic change should not [...] Content analysis details: (0.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1oBOBG-00F82C-Pi Subject: [Openvpn-devel] [PATCH pre-07/25] tun: create tun_name_is_fixed helper 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 This helper encloses the (simple) logic used by OpenVPN to determine if the name passed to --dev has to be considered a fixed interface name or just a pattern. Having a helper is useful because when this logic is required elsewhere, we can just re-use this logic without duplicating the code (which may mean introducing bugs if a future logic change should not update all spots). The logic is actually fairly simple: check if the name contains a number (i.e. tun0). If so, consider the name a fixed device name. While at it make has_digit() accept a signed argument because strings are normally signed (also isdigit() accepts a signed argument). Signed-off-by: Antonio Quartulli Acked-by: Gert Doering --- src/openvpn/buffer.h | 4 ++-- src/openvpn/tun.c | 7 ++++++- src/openvpn/tun.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index 231f1b0d..fece6336 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -356,9 +356,9 @@ strncpynt(char *dest, const char *src, size_t maxlen) /* return true if string contains at least one numerical digit */ static inline bool -has_digit(const unsigned char *src) +has_digit(const char *src) { - unsigned char c; + char c; while ((c = *src++)) { if (isdigit(c)) diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index f17db280..108090d0 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -1718,6 +1718,11 @@ read_tun_header(struct tuntap *tt, uint8_t *buf, int len) } #endif /* if defined (TARGET_OPENBSD) || (defined(TARGET_DARWIN) && HAVE_NET_IF_UTUN_H) */ +bool +tun_name_is_fixed(const char *dev) +{ + return has_digit(dev); +} #if !defined(_WIN32) static void @@ -1772,7 +1777,7 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node, else #endif - if (dynamic && !has_digit((unsigned char *)dev)) + if (dynamic && !tun_name_is_fixed(dev)) { int i; for (i = 0; i < 256; ++i) diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index cf02bf43..8ec8f51f 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -694,5 +694,6 @@ tun_set(struct tuntap *tt, } const char *tun_stat(const struct tuntap *tt, unsigned int rwflags, struct gc_arena *gc); +bool tun_name_is_fixed(const char *dev); #endif /* TUN_H */