|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <sys/ioctl.h>
38 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
50 #define SOCK_API_REG_HANDLE_BIT (1<<31)
131 if (msg_id >=
vec_len (
am->api_trace_cfg))
160 output_length =
sizeof (*mb) + ntohl (mb->data_len);
177 clib_warning (
"main pool index %d already free", pool_index);
269 u8 *data_for_process;
331 if (msgbuf_len >
vec_len (msg_buffer))
355 data_for_process = (
u8 *)
vec_dup (msg_buffer);
356 _vec_len (data_for_process) = msgbuf_len;
359 a->reg_index = reg_index;
360 a->data = data_for_process;
365 if (
vec_len (msg_buffer) > msgbuf_len)
370 _vec_len (msg_buffer) = 0;
372 while (
vec_len (msg_buffer) > 0);
396 size_t bytes_to_send, remaining_bytes = total_bytes;
398 while (remaining_bytes > 0)
400 bytes_to_send = remaining_bytes > 4096 ? 4096 : remaining_bytes;
414 remaining_bytes -= bytes_to_send;
449 template.file_descriptor = fd;
450 template.description =
format (0,
"socksrv");
502 u32 size =
sizeof (*rp) + (nmsg *
sizeof (vl_api_message_table_entry_t));
504 rp->_vl_msg_id = htons (VL_API_SOCKCLNT_CREATE_REPLY);
508 rp->
count = htons (nmsg);
513 rp->message_table[i].index = htons(hp->value[0]);
514 (void) strncpy_s((char *)rp->message_table[i].name,
539 rp->_vl_msg_id = htons (VL_API_SOCKCLNT_DELETE_REPLY);
561 struct msghdr mh = { 0 };
563 char ctl[CMSG_SPACE (
sizeof (
int) * n_fds)];
564 struct cmsghdr *cmsg;
568 iov[0].iov_base = msg;
569 iov[0].iov_len = strlen (msg);
574 mh.msg_control = ctl;
575 mh.msg_controllen =
sizeof (ctl);
576 cmsg = CMSG_FIRSTHDR (&mh);
577 cmsg->cmsg_len = CMSG_LEN (
sizeof (
int) * n_fds);
578 cmsg->cmsg_level = SOL_SOCKET;
579 cmsg->cmsg_type = SCM_RIGHTS;
582 while ((
rv = sendmsg (socket_fd, &mh, 0)) < 0 && errno == EAGAIN)
600 config[0].
size = 256;
601 config[0].
count = 32;
604 config[1].
size = 1024;
605 config[1].
count = 16;
608 config[2].
size = 4096;
612 config[3].
size = 256;
613 config[3].
count = 32;
616 config[4].
size = 1024;
617 config[4].
count = 16;
620 config[5].
size = 4096;
624 config[6].
count = 128;
659 int rv, tries = 1000;
701 a->pvt_heap_size =
am->api_pvt_heap_size;
728 rmp->_vl_msg_id = htons (VL_API_SOCK_INIT_SHM_REPLY);
768 #define foreach_vlib_api_msg \
769 _(SOCKCLNT_CREATE, sockclnt_create, 1) \
770 _(SOCKCLNT_DELETE, sockclnt_delete, 1) \
771 _(SOCK_INIT_SHM, sock_init_shm, 1)
788 vl_msg_api_set_handlers(VL_API_##N, #n, \
789 vl_api_##n##_t_handler, \
791 vl_api_##n##_t_endian, \
792 vl_api_##n##_t_print, \
793 sizeof(vl_api_##n##_t), t);
812 template.file_descriptor = sock->fd;
813 template.description =
format (0,
"socksvr %s", sock->config);
854 else if (
unformat (input,
"default"))
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define CLIB_SOCKET_F_IS_SERVER
vl_socket_args_for_process_t * process_args
volatile int ** vl_api_queue_cursizes
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
struct msgbuf_ msgbuf_t
Message header structure.
static u32 socket_api_registration_handle_to_index(u32 reg_index)
clib_file_main_t file_main
static u32 vl_api_registration_file_index(vl_api_registration_t *reg)
static clib_error_t * clib_file_write(clib_file_t *f)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
void vl_socket_process_api_msg(vl_api_registration_t *rp, i8 *input_v)
#define SOCK_API_REG_HANDLE_BIT
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
@ REGISTRATION_TYPE_SOCKET_LISTEN
Socket listener
void vl_msg_api_socket_handler(void *the_msg)
#define clib_error_return(e, args...)
int ssvm_server_init_memfd(ssvm_private_t *memfd)
Initialize memfd segment server.
#define vec_append(v1, v2)
Append v2 after v1.
vl_registration_type_t registration_type
type
#define pool_put(P, E)
Free an object E in pool P.
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
#define vec_delete(V, N, M)
Delete N elements starting at element M.
vl_api_registration_t * vl_socket_api_client_handle_to_registration(u32 handle)
static clib_error_t * socksvr_accept_ready(clib_file_t *uf)
ssvm_shared_header_t * sh
void * vl_msg_api_alloc_zero(int nbytes)
clib_error_t * vl_socket_read_ready(clib_file_t *uf)
static u32 sock_api_registration_handle(vl_api_registration_t *regp)
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
vl_api_registration_t * current_rp
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
static void unix_save_error(unix_main_t *um, clib_error_t *error)
#define clib_unix_warning(format, args...)
static void socket_cleanup_pending_remove_registration_cb(u32 *preg_index)
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
#define VLIB_CONFIG_FUNCTION(x, n,...)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
void svm_region_init_mapped_region(svm_map_region_args_t *a, svm_region_t *rp)
#define pool_foreach(VAR, POOL)
Iterate through pool.
socket_main_t socket_main
static clib_error_t * socksvr_bogus_write(clib_file_t *uf)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define UNIX_FILE_DATA_AVAILABLE_TO_WRITE
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
int is_being_removed_reg_index(u32 reg_index)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
void vl_socket_api_send(vl_api_registration_t *rp, u8 *elem)
int * additional_fds_to_close
void vl_api_force_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
An API client registration, only in vpp/vlib.
void vl_api_sockclnt_create_t_handler(vl_api_sockclnt_create_t *mp)
void clib_mem_destroy_heap(clib_mem_heap_t *heap)
void vl_api_sock_init_shm_t_handler(vl_api_sock_init_shm_t *mp)
u8 data[0]
actual message begins here
static char * vlib_unix_get_runtime_dir(void)
clib_socket_t socksvr_listen_socket
u32 clib_file_index
Socket only: file index.
void vlibsocket_reference()
static api_main_t * vlibapi_get_main(void)
sll srl srl sll sra u16x4 i
void vl_sock_api_dump_clients(vlib_main_t *vm, api_main_t *am)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
clib_error_t * vl_socket_error_ready(clib_file_t *uf)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
void vl_init_shmem(svm_region_t *vlib_rp, vl_api_shm_elem_config_t *config, int is_vlib, int is_private_region)
#define ALWAYS_ASSERT(truth)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
vl_api_shm_elem_config_t * vl_api_make_shm_config(vl_api_sock_init_shm_t *mp)
clib_error_t * vl_sock_api_init(vlib_main_t *vm)
void vl_api_sockclnt_delete_t_handler(vl_api_sockclnt_delete_t *mp)
API main structure, used by both vpp and binary API clients.
static uword hash_elts(void *v)
clib_error_t * vl_sock_api_send_fd_msg(int socket_fd, int fds[], int n_fds)
#define vec_free(V)
Free vector's memory (no header).
void vl_msg_api_free(void *)
static clib_file_t * vl_api_registration_file(vl_api_registration_t *reg)
description fragment has unexpected format
__clib_export clib_error_t * clib_socket_init(clib_socket_t *s)
static void clib_file_del(clib_file_main_t *um, clib_file_t *f)
static void vl_socket_request_remove_reg_index(u32 reg_index)
void vl_socket_free_registration_index(u32 pool_index)
#define CLIB_MEM_UNPOISON(a, s)
#define CLIB_SOCKET_F_ALLOW_GROUP_WRITE
void socksvr_file_add(clib_file_main_t *fm, int fd)
static vl_api_registration_t * vl_socket_get_registration(u32 reg_index)
@ UNIX_FILE_UPDATE_MODIFY
#define clib_error_return_unix(e, args...)
static uword pool_elts(void *v)
Number of active elements in a pool.
clib_error_t * vl_socket_write_ready(clib_file_t *uf)
static uword clib_file_add(clib_file_main_t *um, clib_file_t *template)
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V,...
Message header structure.
static clib_error_t * socket_exit(vlib_main_t *vm)
u8 * output_vector
Socket only: output vector.
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static vlib_main_t * vlib_get_main(void)
u8 vl_socket_api_registration_handle_is_valid(u32 reg_handle)
void vl_api_call_reaper_functions(u32 client_index)
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
static void vl_api_registration_del_file(vl_api_registration_t *reg)
#define clib_warning(format, args...)
#define foreach_vlib_api_msg
@ REGISTRATION_TYPE_SHMEM
Shared memory connection.
i8 * unprocessed_input
Socket only: pending input.
#define VLIB_MAIN_LOOP_EXIT_FUNCTION(x)
struct _socket_t clib_socket_t
vlib_node_registration_t vl_api_clnt_node
(constructor) VLIB_REGISTER_NODE (vl_api_clnt_node)
@ REGISTRATION_TYPE_SOCKET_SERVER
Socket server.
vl_api_registration_t * registration_pool
#define API_SOCKET_FILENAME
__clib_export clib_error_t * clib_socket_accept(clib_socket_t *server, clib_socket_t *client)
u32 vl_api_registration_pool_index
Index in VLIB's brain (not shared memory).
void * vl_msg_api_alloc(int nbytes)
static clib_error_t * socksvr_config(vlib_main_t *vm, unformat_input_t *input)