|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
19 #include <sys/socket.h>
20 #include <sys/types.h>
26 #include <sys/ioctl.h>
29 #include <sys/prctl.h>
41 struct msghdr mh = { 0 };
43 char ctl[CMSG_SPACE (
sizeof (
int))];
46 iov[0].iov_base = (
void *) msg;
54 memset (&ctl, 0,
sizeof (ctl));
56 mh.msg_controllen =
sizeof (ctl);
57 cmsg = CMSG_FIRSTHDR (&mh);
58 cmsg->cmsg_len = CMSG_LEN (
sizeof (
int));
59 cmsg->cmsg_level = SOL_SOCKET;
60 cmsg->cmsg_type = SCM_RIGHTS;
61 memcpy (CMSG_DATA (cmsg), &afd,
sizeof (
int));
63 rv = sendmsg (fd, &mh, 0);
66 DBG (
"Message type %u sent", msg->
type);
80 memset (&e->
msg, 0, sizeof (e->
msg));
85 if (
c->msg_queue == NULL)
92 while (cur->
next != NULL)
132 memset (&e->
msg, 0, sizeof (e->
msg));
138 i->id =
c->args.interface_id;
139 i->mode =
c->args.mode;
142 if (strlen ((
char *)
c->args.secret) > 0)
143 strncpy ((
char *)
i->secret, (
char *)
c->args.secret, sizeof (
i->secret));
146 if (
c->msg_queue == NULL)
153 while (cur->
next != NULL)
174 memset (&e->
msg, 0, sizeof (e->
msg));
179 ar->
index = region_index;
183 if (
c->msg_queue == NULL)
190 while (cur->
next != NULL)
209 memset (&e->
msg, 0, sizeof (e->
msg));
217 mq = &
c->rx_queues[
index];
219 mq = &
c->tx_queues[
index];
230 if (
c->msg_queue == NULL)
237 while (cur->
next != NULL)
256 memset (&e->
msg, 0, sizeof (e->
msg));
261 strlcpy ((
char *)
cm->if_name, (
char *)
c->args.interface_name,
262 sizeof (
cm->if_name));
265 if (
c->msg_queue == NULL)
272 while (cur->
next != NULL)
291 memset (&e->
msg, 0, sizeof (e->
msg));
296 strlcpy ((
char *)
cm->if_name, (
char *)
c->args.interface_name,
297 sizeof (
cm->if_name));
300 if (
c->msg_queue == NULL)
307 while (cur->
next != NULL)
327 uint16_t l = strlen ((
char *) err_string);
328 if (l >
sizeof (d->
string) - 1)
330 DBG (
"Disconnect string too long. Sending the first %d characters.",
346 DBG (
"incompatible protocol version");
350 c->run_args.num_s2m_rings =
memif_min (
h->max_s2m_ring + 1,
351 c->args.num_s2m_rings);
352 c->run_args.num_m2s_rings =
memif_min (
h->max_m2s_ring + 1,
353 c->args.num_m2s_rings);
354 c->run_args.log2_ring_size =
memif_min (
h->max_log2_ring_size,
355 c->args.log2_ring_size);
356 c->run_args.buffer_size =
c->args.buffer_size;
357 strlcpy ((
char *)
c->remote_name, (
char *)
h->name, sizeof (
c->remote_name));
371 uint8_t err_string[96];
372 memset (err_string, 0,
sizeof (
char) * 96);
377 DBG (
"MEMIF_VER_ERR");
386 DBG (
"MEMIF_ID_ERR");
394 if (!(
c->args.is_master))
396 DBG (
"MEMIF_SLAVE_ERR");
404 DBG (
"MEMIF_CONN_ERR");
412 if (
i->mode !=
c->args.mode)
414 DBG (
"MEMIF_MODE_ERR");
420 strlcpy ((
char *)
c->remote_name, (
char *)
i->name, sizeof (
c->remote_name));
422 if (strlen ((
char *)
c->args.secret) > 0)
425 if (strlen ((
char *)
i->secret) > 0)
427 if (strlen ((
char *)
c->args.secret) != strlen ((
char *)
i->secret))
429 DBG (
"MEMIF_SECRET_ERR");
430 strncpy ((
char *) err_string,
435 r = strncmp ((
char *)
i->secret, (
char *)
c->args.secret,
436 strlen ((
char *)
c->args.secret));
439 DBG (
"MEMIF_SECRET_ERR");
440 strncpy ((
char *) err_string,
448 DBG (
"MEMIF_NOSECRET_ERR");
449 strncpy ((
char *) err_string,
500 c->regions[ar->
index].fd = fd;
502 c->regions[ar->
index].addr = NULL;
506 c->regions[ar->
index].is_external = 1;
532 if (ar->
index >=
c->args.num_s2m_rings)
538 (++
c->rx_queues_num));
543 c->rx_queues[ar->
index].int_fd = fd;
547 c->run_args.num_s2m_rings++;
553 if (ar->
index >=
c->args.num_m2s_rings)
559 (++
c->tx_queues_num));
564 c->tx_queues[ar->
index].int_fd = fd;
568 c->run_args.num_m2s_rings++;
587 strlcpy ((
char *)
c->remote_if_name, (
char *)
cm->if_name,
588 sizeof (
c->remote_if_name));
591 if (
c->on_interrupt != NULL)
593 for (
i = 0;
i <
c->run_args.num_m2s_rings;
i++)
595 elt.key =
c->rx_queues[
i].int_fd;
606 c->on_connect ((
void *)
c,
c->private_ctx);
623 strncpy ((
char *)
c->remote_if_name, (
char *)
cm->if_name,
624 sizeof (
c->remote_if_name));
627 if (
c->on_interrupt != NULL)
629 for (
i = 0;
i <
c->run_args.num_s2m_rings;
i++)
636 c->on_connect ((
void *)
c,
c->private_ctx);
646 memset (
c->remote_disconnect_string, 0,
647 sizeof (
c->remote_disconnect_string));
648 strncpy ((
char *)
c->remote_disconnect_string, (
char *) d->
string,
649 sizeof (
c->remote_disconnect_string));
652 DBG (
"disconnect received: %s, mode: %d",
653 c->remote_disconnect_string,
c->args.mode);
660 char ctl[CMSG_SPACE (
sizeof (
int)) +
661 CMSG_SPACE (
sizeof (
struct ucred))] = { 0 };
662 struct msghdr mh = { 0 };
673 iov[0].iov_base = (
void *) &msg;
677 mh.msg_control = ctl;
678 mh.msg_controllen =
sizeof (ctl);
680 DBG (
"recvmsg fd %d", ifd);
681 size = recvmsg (ifd, &mh, 0);
690 struct cmsghdr *cmsg;
692 cmsg = CMSG_FIRSTHDR (&mh);
695 if (cmsg->cmsg_level == SOL_SOCKET)
697 if (cmsg->cmsg_type == SCM_CREDENTIALS)
701 else if (cmsg->cmsg_type == SCM_RIGHTS)
703 int *fdp = (
int *) CMSG_DATA (cmsg);
707 cmsg = CMSG_NXTHDR (&mh, cmsg);
710 DBG (
"Message type %u received", msg.type);
728 for (
i = 0;
i <
c->regions_num;
i++)
733 for (
i = 0;
i <
c->run_args.num_s2m_rings;
i++)
740 for (
i = 0;
i <
c->run_args.num_m2s_rings;
i++)
816 DBG (
"connection fd error");
817 strncpy ((
char *)
c->remote_disconnect_string,
"connection fd error", 19);
852 c->msg_queue =
c->msg_queue->next;
868 struct sockaddr_un client;
872 DBG (
"accept called");
874 addr_len =
sizeof (client);
876 accept (ms->
fd, (
struct sockaddr *) &client, (socklen_t *) & addr_len);
882 DBG (
"accept fd %d", ms->
fd);
883 DBG (
"conn fd %d", conn_fd);
887 elt.data_struct = ms;
@ MEMIF_MSG_TYPE_DISCONNECT
int memif_connect1(memif_connection_t *c)
memif_region_offset_t offset
#define MEMIF_FD_EVENT_WRITE
memif_msg_add_ring_t add_ring
uint16_t pending_list_len
memif_region_size_t region_size
uint8_t app_name[MEMIF_NAME_LEN]
#define MEMIF_CONNECTION_FLAG_WRITE
memif_msg_connect_t connect
clib_error_t * memif_init_regions_and_queues(memif_if_t *mif)
@ MEMIF_MSG_TYPE_CONNECTED
memif_get_external_region_addr_t * get_external_region_addr
static size_t strlcpy(char *dest, const char *src, size_t len)
vnet_hw_if_output_node_runtime_t * r
@ MEMIF_MSG_TYPE_ADD_RING
clib_error_t * memif_conn_fd_accept_ready(clib_file_t *uf)
memif_log2_ring_size_t log2_ring_size
int free_list_elt(memif_list_elt_t *list, uint16_t len, int key)
#define MEMIF_MAX_LOG2_RING_SIZE
memif_realloc_t * realloc
@ MEMIF_MSG_TYPE_ADD_REGION
#define MEMIF_MAX_M2S_RING
int get_list_elt(memif_list_elt_t **e, memif_list_elt_t *list, uint16_t len, int key)
memif_region_index_t region
memif_list_elt_t * interface_list
memif_list_elt_t * pending_list
memif_region_index_t region
if(node->flags &VLIB_NODE_FLAG_TRACE) vnet_interface_output_trace(vm
memif_version_t min_version
uint16_t private_hdr_size
vnet_feature_config_main_t * cm
memif_control_fd_update_t * control_fd_update
#define MEMIF_FD_EVENT_DEL
if set, informs that fd is going to be closed (user may want to stop watching for events on this fd)
uint16_t control_list_len
struct memif_msg_queue_elt * next
clib_error_t * memif_msg_send_disconnect(memif_if_t *mif, clib_error_t *err)
#define MEMIF_MSG_ADD_RING_FLAG_S2M
memif_version_t max_version
uint16_t interface_list_len
memif_msg_add_region_t add_region
int memif_disconnect_internal(memif_connection_t *c)
memif_msg_connected_t connected
memif_region_offset_t offset
memif_msg_disconnect_t disconnect
int memif_syscall_error_handler(int err_code)
memif_log2_ring_size_t log2_ring_size
memif_list_elt_t * interrupt_list
libmemif_main_t * get_libmemif_main(memif_socket_t *ms)
uint16_t interrupt_list_len
memif_list_elt_t * control_list
memif_region_index_t index
#define MEMIF_MAX_S2M_RING
#define MEMIF_FD_EVENT_READ
user needs to set events that occurred on fd and pass them to memif_control_fd_handler
int add_list_elt(libmemif_main_t *lm, memif_list_elt_t *e, memif_list_elt_t **list, uint16_t *len)