From patchwork Thu Apr 1 02:13:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1695 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 MNYWC0LHZWByDAAAIUCqbw (envelope-from ) for ; Thu, 01 Apr 2021 09:14:42 -0400 Received: from proxy6.mail.ord1d.rsapps.net ([172.30.191.6]) by director12.mail.ord1d.rsapps.net with LMTP id IKXuCkLHZWCFJwAAIasKDg (envelope-from ) for ; Thu, 01 Apr 2021 09:14:42 -0400 Received: from smtp27.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy6.mail.ord1d.rsapps.net with LMTPS id EAH0CULHZWBpQgAAQyIf0w (envelope-from ) for ; Thu, 01 Apr 2021 09:14:42 -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: smtp27.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=rfc2549.org X-Suspicious-Flag: YES X-Classification-ID: 37c60ba8-92ec-11eb-bf95-5254003773d7-1-1 Received: from [216.105.38.7] ([216.105.38.7:60290] helo=lists.sourceforge.net) by smtp27.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 48/C8-22125-147C5606; Thu, 01 Apr 2021 09:14:41 -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 1lRx8y-0001Bg-9k; Thu, 01 Apr 2021 13:13:52 +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 1lRx8w-0001BK-Of for openvpn-devel@lists.sourceforge.net; Thu, 01 Apr 2021 13:13:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:To: From:Sender:Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: 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=iSQkXvEmdFxAYO82UsdWFIjKfj6OSRRxRB1zBYbPCpk=; b=OUorVwO04U3gS7nv9VaDFKfjjb 704O9eGV1ius41UUUdviXfXiZ8elJtsnJYYm/OzKR9q/cKGVMCXuIuUYFDaSZZIr4a3HbN1Cb4G4Z Z0KFcBCaSyTLOLDBpIVt+acOX+6lpyZIpd1k/IaEInNNu3Tmy03kgYsTDsbkmDIFvPak=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc :MIME-Version:Content-Type:Content-Transfer-Encoding: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=iSQkXvEmdFxAYO82UsdWFIjKfj6OSRRxRB1zBYbPCpk=; b=jYr/NgERwP01vJ+r6eZNmORVTw TYKCGqxtsqPivyc8zS33hQVPfh2UNiagBDRmiP27fnPtHM3pUuNyKtIlJn8Y/Sq1o6jO1MnDVEbvZ gyBJsUYgyrtOpvxJ9IP1OqYZKnPxB6PtBa9csdQXJq9isK4TnNByYTNRYCFN3CBaOMV8=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1lRx8s-0036ak-It for openvpn-devel@lists.sourceforge.net; Thu, 01 Apr 2021 13:13:50 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.94 (FreeBSD)) (envelope-from ) id 1lRx8k-000J8I-C3 for openvpn-devel@lists.sourceforge.net; Thu, 01 Apr 2021 15:13:38 +0200 Received: (nullmailer pid 3757 invoked by uid 10006); Thu, 01 Apr 2021 13:13:38 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Thu, 1 Apr 2021 15:13:32 +0200 Message-Id: <20210401131337.3684-10-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210401131337.3684-1-arne@rfc2549.org> References: <20210401131337.3684-1-arne@rfc2549.org> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: rfc2549.org] 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-Headers-End: 1lRx8s-0036ak-It Subject: [Openvpn-devel] [PATCH 09/14] Move is_proto function to the socket.h header 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: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox These functions are small enough to be inlined and also avoids dependency on socket.c from unit_tests using those functions. Signed-off-by: Arne Schwabe Acked-by: Gert Doering --- src/openvpn/socket.c | 36 ------------------------------- src/openvpn/socket.h | 50 +++++++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 48 deletions(-) diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 0d9b793cd..6fed4b660 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -3101,42 +3101,6 @@ static const struct proto_names proto_names[] = { {"tcp6", "TCPv6", AF_INET6, PROTO_TCP}, }; -bool -proto_is_net(int proto) -{ - if (proto < 0 || proto >= PROTO_N) - { - ASSERT(0); - } - return proto != PROTO_NONE; -} - -bool -proto_is_dgram(int proto) -{ - return proto_is_udp(proto); -} - -bool -proto_is_udp(int proto) -{ - if (proto < 0 || proto >= PROTO_N) - { - ASSERT(0); - } - return proto == PROTO_UDP; -} - -bool -proto_is_tcp(int proto) -{ - if (proto < 0 || proto >= PROTO_N) - { - ASSERT(0); - } - return proto == PROTO_TCP_CLIENT || proto == PROTO_TCP_SERVER; -} - int ascii2proto(const char *proto_name) { diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h index 4099f6ea5..d58fda4d3 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -474,18 +474,6 @@ socket_descriptor_t socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const bool nowait); -/* - * proto related - */ -bool proto_is_net(int proto); - -bool proto_is_dgram(int proto); - -bool proto_is_udp(int proto); - -bool proto_is_tcp(int proto); - - #if UNIX_SOCK_SUPPORT socket_descriptor_t create_socket_unix(void); @@ -572,6 +560,44 @@ enum proto_num { PROTO_N }; +static inline bool +proto_is_net(int proto) +{ + ASSERT(proto >= 0 && proto < PROTO_N); + return proto != PROTO_NONE; +} + +/** + * @brief Returns if the protocol being used is UDP + */ +static inline bool +proto_is_udp(int proto) +{ + ASSERT(proto >= 0 && proto < PROTO_N); + return proto == PROTO_UDP; +} + +/** + * @brief Return if the protocol is datagram (UDP) + * + */ +static inline bool +proto_is_dgram(int proto) +{ + return proto_is_udp(proto); +} + +/** + * @brief returns if the proto is a TCP variant (tcp-server, tcp-client or tcp) + */ +static inline bool +proto_is_tcp(int proto) +{ + ASSERT(proto >= 0 && proto < PROTO_N); + return proto == PROTO_TCP_CLIENT || proto == PROTO_TCP_SERVER; +} + + int ascii2proto(const char *proto_name); sa_family_t ascii2af(const char *proto_name);