22 #include <sys/socket.h> 39 #define vl_print(handle, ...) clib_warning (__VA_ARGS__) 47 u32 vl (
void *p) __attribute__ ((weak));
59 u32 data_len = 0, msg_size;
60 int n, current_rx_index;
99 msg_size = data_len +
sizeof (*mbp);
106 if (n < 0 && errno != EAGAIN)
143 .gc_mark_timestamp = 0,
147 n = write (scm->
socket_fd, &msgbuf, sizeof (msgbuf));
148 if (n <
sizeof (msgbuf))
155 if (n < scm->socket_tx_nbytes)
198 char ctl[CMSG_SPACE (
sizeof (
int) * n_fds)
199 + CMSG_SPACE (
sizeof (
struct ucred))];
200 struct msghdr mh = { 0 };
203 struct ucred *cr = 0;
204 struct cmsghdr *cmsg;
205 pid_t pid __attribute__ ((unused));
206 uid_t uid __attribute__ ((unused));
207 gid_t gid __attribute__ ((unused));
210 iov[0].iov_base = msgbuf;
214 mh.msg_control = ctl;
215 mh.msg_controllen =
sizeof (ctl);
217 memset (ctl, 0,
sizeof (ctl));
223 size = recvmsg (socket_fd, &mh, MSG_DONTWAIT);
226 size = recvmsg (socket_fd, &mh, 0);
235 cmsg = CMSG_FIRSTHDR (&mh);
238 if (cmsg->cmsg_level == SOL_SOCKET)
240 if (cmsg->cmsg_type == SCM_CREDENTIALS)
242 cr = (
struct ucred *) CMSG_DATA (cmsg);
247 else if (cmsg->cmsg_type == SCM_RIGHTS)
249 clib_memcpy (fds, CMSG_DATA (cmsg),
sizeof (
int) * n_fds);
252 cmsg = CMSG_NXTHDR (&mh, cmsg);
285 memset (memfd, 0,
sizeof (*memfd));
291 clib_warning (
"WARNING: segment map returned %d", retval);
299 new_name =
format (0,
"%v[shm]%c", scm->
name, 0);
318 #define foreach_sock_client_api_msg \ 319 _(SOCKCLNT_CREATE_REPLY, sockclnt_create_reply) \ 320 _(SOCK_INIT_SHM_REPLY, sock_init_shm_reply) \ 332 vl_msg_api_set_handlers(VL_API_##N, #n, \ 333 vl_api_##n##_t_handler, \ 335 vl_api_##n##_t_endian, \ 336 vl_api_##n##_t_print, \ 337 sizeof(vl_api_##n##_t), 1); 344 u32 socket_buffer_size)
356 if (socket_path == 0 || client_name == 0)
360 sock->config = socket_path;
381 mp->_vl_msg_id = htons (VL_API_SOCKCLNT_CREATE);
382 strncpy ((
char *) mp->
name, client_name, sizeof (mp->
name) - 1);
383 mp->
name[
sizeof (mp->
name) - 1] = 0;
407 memset (mp, 0,
sizeof (*mp));
408 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_SOCK_INIT_SHM);
414 for (i = 0; i <
vec_len (config); i++)
416 cfg = (
u64 *) & config[i];
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
void vl_msg_api_socket_handler(void *the_msg)
u8 vl_mem_client_is_connected(void)
ssvm_private_t memfd_segment
int vl_client_connect_to_vlib_no_map(const char *svm_name, const char *client_name, int rx_queue_size)
int vl_socket_client_read(int wait)
static void noop_handler(void *notused)
static f64 clib_time_now(clib_time_t *c)
clib_error_t * clib_socket_init(clib_socket_t *s)
int vl_socket_client_connect(char *socket_path, char *client_name, u32 socket_buffer_size)
svm_queue_t * q
message allocated in this shmem ring
u8 data[0]
actual message begins here
int control_pings_outstanding
void vl_socket_client_enable_disable(int enable)
static void vl_api_sock_init_shm_reply_t_handler(vl_api_sock_init_shm_reply_t *mp)
#define SOCKET_CLIENT_DEFAULT_BUFFER_SIZE
void * vl_socket_client_msg_alloc(int nbytes)
memset(h->entries, 0, sizeof(h->entries[0])*entries)
svm_region_t * vlib_rp
Current binary api segment descriptor.
#define clib_error_return(e, args...)
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
static void vl_api_sockclnt_create_reply_t_handler(vl_api_sockclnt_create_reply_t *mp)
int vl_socket_client_init_shm(vl_api_shm_elem_config_t *config)
void vl_sock_client_install_message_handlers(void)
#define clib_error_return_unix(e, args...)
clib_error_t * vl_sock_api_recv_fd_msg(int socket_fd, int fds[], int n_fds, u32 wait)
void clib_time_init(clib_time_t *c)
API main structure, used by both vpp and binary API clients.
socket_client_main_t socket_client_main
clib_error_t * vl_socket_client_recv_fd_msg(int fds[], int n_fds, u32 wait)
void vl_socket_client_disconnect(void)
clib_socket_t client_socket
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
#define clib_memcpy(a, b, c)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
u32 data_len
message length not including header
Message header structure.
#define CLIB_SOCKET_F_IS_CLIENT
#define clib_error_report(e)
struct _socket_t clib_socket_t
#define CLIB_SOCKET_F_SEQPACKET
void vl_client_install_client_message_handlers(void)
void vl_client_disconnect_from_vlib_no_unmap(void)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 client_index
Client index allocated by VPP.
#define clib_unix_warning(format, args...)
void ssvm_delete_memfd(ssvm_private_t *memfd)
int vl_socket_client_write(void)
int socket_enable
Can temporarily disable the connection but still can keep it around...
int ssvm_slave_init_memfd(ssvm_private_t *memfd)
Initialize memfd segment slave.
#define foreach_sock_client_api_msg