22 #include <sys/socket.h> 39 #define vl_print(handle, ...) clib_warning (__VA_ARGS__) 47 u32 vl (
void *p) __attribute__ ((weak));
59 int n, current_rx_index;
129 .gc_mark_timestamp = 0,
133 n = write (scm->
socket_fd, &msgbuf, sizeof (msgbuf));
134 if (n <
sizeof (msgbuf))
141 if (n < scm->socket_tx_nbytes)
184 char ctl[CMSG_SPACE (
sizeof (
int)) + CMSG_SPACE (
sizeof (
struct ucred))];
185 struct msghdr mh = { 0 };
188 struct ucred *cr = 0;
189 struct cmsghdr *cmsg;
190 pid_t pid __attribute__ ((unused));
191 uid_t uid __attribute__ ((unused));
192 gid_t gid __attribute__ ((unused));
195 iov[0].iov_base = msgbuf;
199 mh.msg_control = ctl;
200 mh.msg_controllen =
sizeof (ctl);
202 memset (ctl, 0,
sizeof (ctl));
208 size = recvmsg (socket_fd, &mh, MSG_DONTWAIT);
211 size = recvmsg (socket_fd, &mh, 0);
220 cmsg = CMSG_FIRSTHDR (&mh);
223 if (cmsg->cmsg_level == SOL_SOCKET)
225 if (cmsg->cmsg_type == SCM_CREDENTIALS)
227 cr = (
struct ucred *) CMSG_DATA (cmsg);
232 else if (cmsg->cmsg_type == SCM_RIGHTS)
234 clib_memcpy (my_fd, CMSG_DATA (cmsg),
sizeof (
int));
237 cmsg = CMSG_NXTHDR (&mh, cmsg);
270 memset (memfd, 0,
sizeof (*memfd));
276 clib_warning (
"WARNING: segment map returned %d", retval);
284 new_name =
format (0,
"%v[shm]%c", scm->
name, 0);
300 #define foreach_sock_client_api_msg \ 301 _(SOCKCLNT_CREATE_REPLY, sockclnt_create_reply) \ 302 _(SOCK_INIT_SHM_REPLY, sock_init_shm_reply) \ 314 vl_msg_api_set_handlers(VL_API_##N, #n, \ 315 vl_api_##n##_t_handler, \ 317 vl_api_##n##_t_endian, \ 318 vl_api_##n##_t_print, \ 319 sizeof(vl_api_##n##_t), 1); 326 u32 socket_buffer_size)
338 if (socket_path == 0 || client_name == 0)
342 sock->config = socket_path;
363 mp->_vl_msg_id = htons (VL_API_SOCKCLNT_CREATE);
364 strncpy ((
char *) mp->
name, client_name, sizeof (mp->
name) - 1);
365 mp->
name[
sizeof (mp->
name) - 1] = 0;
387 memset (mp, 0,
sizeof (*mp));
388 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_SOCK_INIT_SHM);
394 for (i = 0; i <
vec_len (config); i++)
396 cfg = (
u64 *) & config[i];
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
clib_error_t * vl_socket_client_recv_fd_msg(int *fd_to_recv, u32 wait)
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)
clib_error_t * vl_sock_api_recv_fd_msg(int socket_fd, int *my_fd, u32 wait)
#define SOCKET_CLIENT_DEFAULT_BUFFER_SIZE
void * vl_socket_client_msg_alloc(int nbytes)
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...)
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
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)
#define clib_unix_warning(format, args...)
void ssvm_delete_memfd(ssvm_private_t *memfd)
int vl_socket_client_write(void)
int ssvm_slave_init_memfd(ssvm_private_t *memfd)
Initialize memfd segment slave.
#define foreach_sock_client_api_msg