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;
102 msg_size = data_len +
sizeof (*mbp);
149 .gc_mark_timestamp = 0,
153 n = write (scm->
socket_fd, &msgbuf, sizeof (msgbuf));
154 if (n <
sizeof (msgbuf))
161 if (n < scm->socket_tx_nbytes)
204 char ctl[CMSG_SPACE (
sizeof (
int) * n_fds)
205 + CMSG_SPACE (
sizeof (
struct ucred))];
206 struct msghdr mh = { 0 };
209 struct ucred *cr = 0;
210 struct cmsghdr *cmsg;
211 pid_t pid __attribute__ ((unused));
212 uid_t uid __attribute__ ((unused));
213 gid_t gid __attribute__ ((unused));
216 iov[0].iov_base = msgbuf;
220 mh.msg_control = ctl;
221 mh.msg_controllen =
sizeof (ctl);
229 size = recvmsg (socket_fd, &mh, MSG_DONTWAIT);
232 size = recvmsg (socket_fd, &mh, 0);
241 cmsg = CMSG_FIRSTHDR (&mh);
244 if (cmsg->cmsg_level == SOL_SOCKET)
246 if (cmsg->cmsg_type == SCM_CREDENTIALS)
248 cr = (
struct ucred *) CMSG_DATA (cmsg);
253 else if (cmsg->cmsg_type == SCM_RIGHTS)
258 cmsg = CMSG_NXTHDR (&mh, cmsg);
297 clib_warning (
"WARNING: segment map returned %d", retval);
305 new_name =
format (0,
"%v[shm]%c", scm->
name, 0);
315 (
char *) new_name, 32
334 #define foreach_sock_client_api_msg \ 335 _(SOCKCLNT_CREATE_REPLY, sockclnt_create_reply) \ 336 _(SOCK_INIT_SHM_REPLY, sock_init_shm_reply) \ 348 vl_msg_api_set_handlers(VL_API_##N, #n, \ 349 vl_api_##n##_t_handler, \ 351 vl_api_##n##_t_endian, \ 352 vl_api_##n##_t_print, \ 353 sizeof(vl_api_##n##_t), 1); 360 u32 socket_buffer_size)
372 if (socket_path == 0 || client_name == 0)
376 sock->config = socket_path;
397 mp->_vl_msg_id = htons (VL_API_SOCKCLNT_CREATE);
398 strncpy ((
char *) mp->
name, client_name, sizeof (mp->
name) - 1);
399 mp->
name[
sizeof (mp->
name) - 1] = 0;
427 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_SOCK_INIT_SHM);
433 for (i = 0; i <
vec_len (config); i++)
435 cfg = (
u64 *) & config[i];
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
#define CLIB_SOCKET_F_NON_BLOCKING_CONNECT
int vl_socket_client_init_shm(vl_api_shm_elem_config_t *config, int want_pthread)
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)
#define clib_memcpy_fast(a, b, c)
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)
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
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)
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)
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)
int vl_client_connect_to_vlib_no_rx_pthread_no_map(const char *svm_name, const char *client_name, int rx_queue_size)
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 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
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