22 #include <sys/socket.h> 39 #define vl_print(handle, ...) clib_warning (__VA_ARGS__) 48 u32 vl (
void *p) __attribute__ ((weak));
60 socket_client_ctx =
ctx;
67 socket_client_ctx = old_ctx;
74 int n, current_rx_index;
116 msg_size = data_len +
sizeof (*mbp);
180 .gc_mark_timestamp = 0,
184 n = write (scm->
socket_fd, &msgbuf, sizeof (msgbuf));
185 if (n <
sizeof (msgbuf))
192 if (n < scm->socket_tx_nbytes)
268 char ctl[CMSG_SPACE (
sizeof (
int) * n_fds)
269 + CMSG_SPACE (
sizeof (
struct ucred))];
270 struct msghdr mh = { 0 };
273 struct ucred *cr = 0;
274 struct cmsghdr *cmsg;
275 pid_t
pid __attribute__ ((unused));
276 uid_t uid __attribute__ ((unused));
277 gid_t gid __attribute__ ((unused));
283 iov[0].iov_base = msgbuf;
287 mh.msg_control = ctl;
288 mh.msg_controllen =
sizeof (ctl);
296 size = recvmsg (socket_fd, &mh, MSG_DONTWAIT);
299 size = recvmsg (socket_fd, &mh, 0);
308 cmsg = CMSG_FIRSTHDR (&mh);
311 if (cmsg->cmsg_level == SOL_SOCKET)
313 if (cmsg->cmsg_type == SCM_CREDENTIALS)
315 cr = (
struct ucred *) CMSG_DATA (cmsg);
320 else if (cmsg->cmsg_type == SCM_RIGHTS)
325 cmsg = CMSG_NXTHDR (&mh, cmsg);
339 int fds[],
int n_fds,
u32 wait)
384 clib_warning (
"WARNING: segment map returned %d", retval);
392 new_name =
format (0,
"%v[shm]%c", scm->
name, 0);
402 (
char *) new_name, 32
421 #define foreach_sock_client_api_msg \ 422 _(SOCKCLNT_CREATE_REPLY, sockclnt_create_reply) \ 423 _(SOCK_INIT_SHM_REPLY, sock_init_shm_reply) \ 435 vl_msg_api_set_handlers(VL_API_##N, #n, \ 436 vl_api_##n##_t_handler, \ 438 vl_api_##n##_t_endian, \ 439 vl_api_##n##_t_print, \ 440 sizeof(vl_api_##n##_t), 1); 447 char *socket_path,
char *client_name,
448 u32 socket_buffer_size)
459 if (socket_path == 0 || client_name == 0)
463 sock->config = socket_path;
484 mp->_vl_msg_id = htons (VL_API_SOCKCLNT_CREATE);
485 strncpy ((
char *) mp->
name, client_name, sizeof (mp->
name) - 1);
486 mp->
name[
sizeof (mp->
name) - 1] = 0;
502 u32 socket_buffer_size)
505 client_name, socket_buffer_size);
510 char *client_name,
u32 socket_buffer_size)
517 client_name, socket_buffer_size);
536 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_SOCK_INIT_SHM);
542 for (i = 0; i <
vec_len (config); i++)
544 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)
int vl_socket_client_read2(socket_client_main_t *scm, int wait)
int vl_socket_client_connect_internal(socket_client_main_t *scm, char *socket_path, char *client_name, u32 socket_buffer_size)
static void noop_handler(void *notused)
#define clib_memcpy_fast(a, b, c)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
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
static int vl_socket_client_read_internal(socket_client_main_t *scm, int wait)
int control_pings_outstanding
clib_error_t * vl_socket_client_recv_fd_msg2(socket_client_main_t *scm, int fds[], int n_fds, u32 wait)
void vl_socket_client_enable_disable(int enable)
int vl_socket_client_connect2(socket_client_main_t *scm, char *socket_path, char *client_name, u32 socket_buffer_size)
int vl_socket_client_write2(socket_client_main_t *scm)
void vl_socket_client_enable_disable2(socket_client_main_t *scm, 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)
static int vl_socket_client_write_internal(socket_client_main_t *scm)
static socket_client_main_t * vl_socket_client_ctx_push(socket_client_main_t *ctx)
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.
int vl_socket_client_init_shm_internal(socket_client_main_t *scm, vl_api_shm_elem_config_t *config, int want_pthread)
void vl_socket_client_disconnect2(socket_client_main_t *scm)
static void vl_api_sockclnt_create_reply_t_handler(vl_api_sockclnt_create_reply_t *mp)
clib_error_t * vl_sock_api_recv_fd_msg2(socket_client_main_t *scm, int socket_fd, int fds[], int n_fds, u32 wait)
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.
int vl_socket_client_init_shm2(socket_client_main_t *scm, vl_api_shm_elem_config_t *config, int want_pthread)
__thread socket_client_main_t * socket_client_ctx
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
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
static clib_error_t * vl_sock_api_recv_fd_msg_internal(socket_client_main_t *scm, int fds[], int n_fds, u32 wait)
#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)
static api_main_t * vlibapi_get_main(void)
void * vl_socket_client_msg_alloc2(socket_client_main_t *scm, int nbytes)
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.
static void vl_socket_client_ctx_pop(socket_client_main_t *old_ctx)
#define foreach_sock_client_api_msg