]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Move is_proto function to the socket.h header
authorArne Schwabe <arne@rfc2549.org>
Thu, 1 Apr 2021 13:13:32 +0000 (15:13 +0200)
committerGert Doering <gert@greenie.muc.de>
Thu, 1 Apr 2021 13:57:40 +0000 (15:57 +0200)
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 <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20210401131337.3684-10-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21950.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/socket.c
src/openvpn/socket.h

index 0d9b793cd6d342125a836229f4aa680ba8928f16..6fed4b66027f8a188655d64019f60f054e6a2885 100644 (file)
@@ -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)
 {
index 4099f6ea5e287833da68c7a10941af1e042ff929..d58fda4d33be235ec396cd29377ce27bb52c6961 100644 (file)
@@ -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);