summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/socket.h
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2017-09-11 16:52:11 +0200
committerDave Barach <openvpp@barachs.net>2017-09-14 11:31:05 +0000
commitf49921f73f4e1f0b67823be445aafeb9ff2333a6 (patch)
tree4770cf05eb5102f4934804db191f5327ad815505 /src/vppinfra/socket.h
parentdaf5162f10b386f004a04466fdea12f792b0c98b (diff)
clib_socket: add sendmsg / recvmsg with ancillary data support
Change-Id: Ie18580e05ec12291e7026f21ad874e088a712c8e Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/socket.h')
-rw-r--r--src/vppinfra/socket.h49
1 files changed, 40 insertions, 9 deletions
diff --git a/src/vppinfra/socket.h b/src/vppinfra/socket.h
index 75037208d5d..4f9e9509342 100644
--- a/src/vppinfra/socket.h
+++ b/src/vppinfra/socket.h
@@ -55,13 +55,14 @@ typedef struct _socket_t
char *config;
u32 flags;
-#define SOCKET_IS_SERVER (1 << 0)
-#define SOCKET_IS_CLIENT (0 << 0)
-#define SOCKET_NON_BLOCKING_CONNECT (1 << 1)
-#define SOCKET_ALLOW_GROUP_WRITE (1 << 2)
+#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)
- /* Read returned end-of-file. */
-#define SOCKET_RX_END_OF_FILE (1 << 2)
/* Transmit buffer. Holds data waiting to be written. */
u8 *tx_buffer;
@@ -72,10 +73,19 @@ typedef struct _socket_t
/* Peer socket we are connected to. */
struct sockaddr_in peer;
+ /* Credentials, populated if CLIB_SOCKET_F_PASSCRED is set */
+ pid_t pid;
+ uid_t uid;
+ gid_t gid;
+
clib_error_t *(*write_func) (struct _socket_t * sock);
clib_error_t *(*read_func) (struct _socket_t * sock, int min_bytes);
clib_error_t *(*close_func) (struct _socket_t * sock);
- void *private_data;
+ clib_error_t *(*recvmsg_func) (struct _socket_t * s, void *msg, int msglen,
+ int fds[], int num_fds);
+ clib_error_t *(*sendmsg_func) (struct _socket_t * s, void *msg, int msglen,
+ int fds[], int num_fds);
+ uword private_data;
} clib_socket_t;
/* socket config format is host:port.
@@ -89,7 +99,7 @@ clib_error_t *clib_socket_accept (clib_socket_t * server,
always_inline uword
clib_socket_is_server (clib_socket_t * sock)
{
- return (sock->flags & SOCKET_IS_SERVER) != 0;
+ return (sock->flags & CLIB_SOCKET_F_IS_SERVER) != 0;
}
always_inline uword
@@ -98,10 +108,17 @@ clib_socket_is_client (clib_socket_t * s)
return !clib_socket_is_server (s);
}
+always_inline uword
+clib_socket_is_connected (clib_socket_t * sock)
+{
+ return sock->fd > 0;
+}
+
+
always_inline int
clib_socket_rx_end_of_file (clib_socket_t * s)
{
- return s->flags & SOCKET_RX_END_OF_FILE;
+ return s->flags & CLIB_SOCKET_F_RX_END_OF_FILE;
}
always_inline void *
@@ -130,6 +147,20 @@ clib_socket_rx (clib_socket_t * s, int n_bytes)
return s->read_func (s, n_bytes);
}
+always_inline clib_error_t *
+clib_socket_sendmsg (clib_socket_t * s, void *msg, int msglen,
+ int fds[], int num_fds)
+{
+ return s->sendmsg_func (s, msg, msglen, fds, num_fds);
+}
+
+always_inline clib_error_t *
+clib_socket_recvmsg (clib_socket_t * s, void *msg, int msglen,
+ int fds[], int num_fds)
+{
+ return s->recvmsg_func (s, msg, msglen, fds, num_fds);
+}
+
always_inline void
clib_socket_free (clib_socket_t * s)
{