summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/socket.h
diff options
context:
space:
mode:
authorDamjan Marion <dmarion@me.com>2023-01-30 11:48:38 +0100
committerOle Tr�an <otroan@employees.org>2023-02-06 10:17:40 +0000
commit085757bb4930511928daa97f972cdca021e7a813 (patch)
tree5edf076e28156d9834fa37029028f2f5c5f568b9 /src/vppinfra/socket.h
parent0df06b6e95b6a3261c8e9c261c7a4a661d6ea25a (diff)
vppinfra: refactor clib_socket_init, add linux netns support
Type: improvement Change-Id: Ida2d044bccf0bc8914b4fe7d383f827400fa6a52 Signed-off-by: Damjan Marion <dmarion@me.com>
Diffstat (limited to 'src/vppinfra/socket.h')
-rw-r--r--src/vppinfra/socket.h49
1 files changed, 38 insertions, 11 deletions
diff --git a/src/vppinfra/socket.h b/src/vppinfra/socket.h
index fa5ef1efced..132e89f2871 100644
--- a/src/vppinfra/socket.h
+++ b/src/vppinfra/socket.h
@@ -46,6 +46,16 @@
#include <vppinfra/error.h>
#include <vppinfra/format.h>
+typedef enum
+{
+ CLIB_SOCKET_TYPE_UNKNOWN = 0,
+ CLIB_SOCKET_TYPE_INET,
+ CLIB_SOCKET_TYPE_UNIX,
+#if CLIB_LINUX
+ CLIB_SOCKET_TYPE_LINUX_ABSTRACT,
+#endif
+} clib_socket_type_t;
+
typedef struct _socket_t
{
/* File descriptor. */
@@ -54,15 +64,21 @@ typedef struct _socket_t
/* Config string for socket HOST:PORT or just HOST. */
char *config;
- u32 flags;
-#define CLIB_SOCKET_F_IS_SERVER (1 << 0)
-#define CLIB_SOCKET_F_IS_CLIENT (0 << 0)
-#define CLIB_SOCKET_F_RX_END_OF_FILE (1 << 2)
-#define CLIB_SOCKET_F_NON_BLOCKING_CONNECT (1 << 3)
-#define CLIB_SOCKET_F_ALLOW_GROUP_WRITE (1 << 4)
-#define CLIB_SOCKET_F_SEQPACKET (1 << 5)
-#define CLIB_SOCKET_F_PASSCRED (1 << 6)
-#define CLIB_SOCKET_F_BLOCKING (1 << 7)
+ union
+ {
+ struct
+ {
+ u32 is_server : 1;
+ u32 rx_end_of_file : 1;
+ u32 non_blocking_connect : 1;
+ u32 allow_group_write : 1;
+ u32 is_seqpacket : 1;
+ u32 passcred : 1;
+ u32 is_blocking : 1;
+ u32 local_only : 1;
+ };
+ u32 flags;
+ };
/* Transmit buffer. Holds data waiting to be written. */
u8 *tx_buffer;
@@ -85,9 +101,18 @@ typedef struct _socket_t
int fds[], int num_fds);
clib_error_t *(*sendmsg_func) (struct _socket_t * s, void *msg, int msglen,
int fds[], int num_fds);
+ clib_socket_type_t type;
uword private_data;
} clib_socket_t;
+#define CLIB_SOCKET_FLAG(f) (((clib_socket_t){ .f = 1 }).flags)
+#define CLIB_SOCKET_F_IS_CLIENT 0
+#define CLIB_SOCKET_F_IS_SERVER CLIB_SOCKET_FLAG (is_server)
+#define CLIB_SOCKET_F_ALLOW_GROUP_WRITE CLIB_SOCKET_FLAG (allow_group_write)
+#define CLIB_SOCKET_F_SEQPACKET CLIB_SOCKET_FLAG (is_seqpacket)
+#define CLIB_SOCKET_F_PASSCRED CLIB_SOCKET_FLAG (passcred)
+#define CLIB_SOCKET_F_BLOCKING CLIB_SOCKET_FLAG (is_blocking)
+
/* socket config format is host:port.
Unspecified port causes a free one to be chosen starting
from IPPORT_USERRESERVED (5000). */
@@ -98,10 +123,12 @@ clib_error_t *clib_socket_init_netns (clib_socket_t *socket, u8 *namespace);
clib_error_t *clib_socket_accept (clib_socket_t * server,
clib_socket_t * client);
+int clib_socket_prefix_is_valid (char *s);
+
always_inline uword
clib_socket_is_server (clib_socket_t * sock)
{
- return (sock->flags & CLIB_SOCKET_F_IS_SERVER) != 0;
+ return sock->is_server;
}
always_inline uword
@@ -120,7 +147,7 @@ clib_socket_is_connected (clib_socket_t * sock)
always_inline int
clib_socket_rx_end_of_file (clib_socket_t * s)
{
- return s->flags & CLIB_SOCKET_F_RX_END_OF_FILE;
+ return s->rx_end_of_file;
}
always_inline void *