20 #include <sys/types.h> 21 #include <sys/socket.h> 22 #include <netinet/in.h> 23 #include <sys/ioctl.h> 39 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 69 if (reg->registration_type == REGISTRATION_TYPE_SOCKET_SERVER) {
70 f = pool_elt_at_index (fm->file_pool, reg->clib_file_index);
71 vlib_cli_output (vm,
"%16s %8d",
72 reg->name, f->file_descriptor);
81 u16 msg_id = ntohs (*(
u16 *) elem);
102 (
u8 *) mb, sizeof (*mb));
110 output_length =
sizeof (*mb) + ntohl (mb->
data_len);
125 clib_warning (
"main pool index %d already free", pool_index);
164 u8 *data_for_process;
176 if (n <= 0 && errno != EAGAIN)
243 data_for_process = (
u8 *)
vec_dup (msg_buffer);
244 _vec_len (data_for_process) = (msg_len +
sizeof (
msgbuf_t));
248 a->
data = data_for_process;
253 if (n > (msg_len +
sizeof (*mbp)))
254 vec_delete (msg_buffer, msg_len +
sizeof (*mbp), 0);
256 _vec_len (msg_buffer) = 0;
271 u8 * buffer,
uword buffer_bytes)
288 u8 * buffer,
uword buffer_bytes)
359 memset (rp, 0,
sizeof (*rp));
364 template.file_descriptor = fd;
414 rp->_vl_msg_id = htons (VL_API_SOCKCLNT_CREATE_REPLY);
437 rp->_vl_msg_id = htons (VL_API_SOCKCLNT_DELETE_REPLY);
456 struct msghdr mh = { 0 };
458 char ctl[CMSG_SPACE (
sizeof (
int))];
462 iov[0].iov_base = msg;
463 iov[0].iov_len = strlen (msg);
467 struct cmsghdr *cmsg;
468 memset (&ctl, 0,
sizeof (ctl));
469 mh.msg_control = ctl;
470 mh.msg_controllen =
sizeof (ctl);
471 cmsg = CMSG_FIRSTHDR (&mh);
472 cmsg->cmsg_len = CMSG_LEN (
sizeof (
int));
473 cmsg->cmsg_level = SOL_SOCKET;
474 cmsg->cmsg_type = SCM_RIGHTS;
475 memcpy (CMSG_DATA (cmsg), &fd_to_share,
sizeof (
int));
477 rv = sendmsg (socket_fd, &mh, 0);
513 memset (memfd, 0,
sizeof (*memfd));
531 memset (a, 0,
sizeof (*a));
559 rmp->_vl_msg_id = htons (VL_API_MEMFD_SEGMENT_CREATE_REPLY);
580 #define foreach_vlib_api_msg \ 581 _(SOCKCLNT_CREATE, sockclnt_create) \ 582 _(SOCKCLNT_DELETE, sockclnt_delete) \ 583 _(MEMFD_SEGMENT_CREATE, memfd_segment_create) 601 #define _(N,n) do { \ 602 c->id = VL_API_##N; \ 604 c->handler = vl_api_##n##_t_handler; \ 605 c->cleanup = vl_noop_handler; \ 606 c->endian = vl_api_##n##_t_endian; \ 607 c->print = vl_api_##n##_t_print; \ 608 c->size = sizeof(vl_api_##n##_t); \ 611 c->message_bounce = 0; \ 612 vl_msg_api_config(c);} while (0); 622 if (strncmp (sock->config,
"/run", 4) == 0)
624 u8 *tmp =
format (0,
"%s", sock->config);
626 while (i && tmp[--i] !=
'/')
643 memset (rp, 0,
sizeof (*rp));
649 template.file_descriptor = sock->fd;
669 clib_file_del (fm, fm->file_pool + rp->clib_file_index);
670 index = rp->vl_api_registration_pool_index;
671 vl_free_socket_registration_index (index);
690 else if (
unformat (input,
"default"))
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
volatile int ** vl_api_queue_cursizes
vl_api_registration_t * regp
u64 api_pvt_heap_size
size of the api private mheap
void dump_socket_clients(vlib_main_t *vm, api_main_t *am)
static void clib_file_del(clib_file_main_t *um, clib_file_t *f)
static clib_error_t * socksvr_config(vlib_main_t *vm, unformat_input_t *input)
vl_api_registration_t * registration_pool
sll srl srl sll sra u16x4 i
struct msgbuf_ msgbuf_t
Message header structure.
void vl_socket_add_pending_output_no_flush(clib_file_t *uf, vl_api_registration_t *rp, u8 *buffer, uword buffer_bytes)
static clib_error_t * socket_exit(vlib_main_t *vm)
void vl_init_shmem(svm_region_t *vlib_rp, int is_vlib, int is_private_region)
void vl_socket_add_pending_output(clib_file_t *uf, vl_api_registration_t *rp, u8 *buffer, uword buffer_bytes)
vl_socket_args_for_process_t * process_args
Message configuration definition.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
clib_error_t * clib_socket_init(clib_socket_t *s)
u8 data[0]
actual message begins here
#define pool_is_free(P, E)
Use free bitmap to query whether given element is free.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
trace_cfg_t * api_trace_cfg
Current trace configuration.
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
#define CLIB_SOCKET_F_IS_SERVER
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
u32 clib_file_index
Socket only: file index.
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static clib_error_t * socksvr_bogus_write(clib_file_t *uf)
#define VLIB_INIT_FUNCTION(x)
void vl_free_socket_registration_index(u32 pool_index)
#define clib_error_return(e, args...)
clib_file_main_t file_main
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
void vl_socket_api_send(vl_api_registration_t *rp, u8 *elem)
#define SOCKET_READ_EVENT
void * vl_msg_api_alloc(int nbytes)
int memfd_master_init(memfd_private_t *memfd, u32 master_index)
vl_registration_type_t registration_type
type
static clib_error_t * socksvr_accept_ready(clib_file_t *uf)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
clib_error_t * clib_socket_accept(clib_socket_t *server, clib_socket_t *client)
#define clib_error_return_unix(e, args...)
void vl_msg_api_free(void *)
#define pool_put(P, E)
Free an object E in pool P.
vlib_node_registration_t memclnt_node
(constructor) VLIB_REGISTER_NODE (memclnt_node)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
svm_region_t ** vlib_private_rps
Vector of all mapped shared-VM segments.
#define VLIB_CONFIG_FUNCTION(x, n,...)
void socksvr_file_add(clib_file_main_t *fm, int fd)
void(* file_update)(clib_file_t *file, clib_file_update_type_t update_type)
void svm_region_init_mapped_region(svm_map_region_args_t *a, svm_region_t *rp)
void vl_msg_api_socket_handler(void *the_msg)
static clib_error_t * send_fd_msg(int socket_fd, int fd_to_share)
API main structure, used by both vpp and binary API clients.
socket_main_t socket_main
An API client registration, only in vpp/vlib.
memfd_shared_header_t * sh
void vl_api_socket_process_msg(clib_file_t *uf, vl_api_registration_t *rp, i8 *input_v)
void vl_api_sockclnt_create_t_handler(vl_api_sockclnt_create_t *mp)
clib_socket_t socksvr_listen_socket
#define vec_free(V)
Free vector's memory (no header).
#define foreach_vlib_api_msg
#define VLIB_MAIN_LOOP_EXIT_FUNCTION(x)
#define clib_warning(format, args...)
clib_error_t * vlibsocket_init(vlib_main_t *vm)
#define clib_memcpy(a, b, c)
u8 * output_vector
Socket only: output vecto.
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
int * additional_fds_to_close
clib_error_t * vl_socket_write_ready(clib_file_t *uf)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
static uword clib_file_add(clib_file_main_t *um, clib_file_t *template)
u32 data_len
message length not including header
Message header structure.
#define vec_append(v1, v2)
Append v2 after v1.
struct _socket_t clib_socket_t
#define UNIX_FILE_DATA_AVAILABLE_TO_WRITE
i8 * unprocessed_input
Socket only: pending input.
clib_error_t * vl_socket_read_ready(clib_file_t *uf)
vl_api_registration_t * current_rp
#define CLIB_SOCKET_F_SEQPACKET
static void socket_del_pending_output(clib_file_t *uf, vl_api_registration_t *rp, uword n_bytes)
static vlib_main_t * vlib_get_main(void)
clib_error_t * vl_socket_error_ready(clib_file_t *uf)
clib_error_t * vlib_unix_recursive_mkdir(char *path)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define clib_unix_warning(format, args...)
u32 vl_api_registration_pool_index
Index in VLIB's brain (not shared memory).
void vl_api_memfd_segment_create_t_handler(vl_api_memfd_segment_create_t *mp)
clib_error_t * socksvr_api_init(vlib_main_t *vm)
vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
#define CLIB_SOCKET_F_ALLOW_GROUP_WRITE
Shared memory connection.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
void vl_msg_api_send(vl_api_registration_t *rp, u8 *elem)
void vl_api_sockclnt_delete_t_handler(vl_api_sockclnt_delete_t *mp)
static uword pool_elts(void *v)
Number of active elements in a pool.