22 #include <sys/types.h> 24 #include <sys/ioctl.h> 25 #include <sys/socket.h> 29 #include <sys/prctl.h> 30 #include <sys/eventfd.h> 39 #include <vpp/app/version.h> 93 mif->
flags &= ~(MEMIF_IF_FLAG_CONNECTED | MEMIF_IF_FLAG_CONNECTING);
127 "Unable to unassign interface %d, queue %d: rc=%d",
212 MAP_SHARED, mr->
fd, 0)) == MAP_FAILED)
249 template.file_descriptor = mq->
int_fd;
250 template.private_data = (mif->
dev_instance << 16) | (i & 0xFFFF);
251 template.description =
format (0,
"%U rx %u int",
261 (mif,
"Warning: unable to set rx mode for interface %d queue %d: " 276 mif->
flags &= ~MEMIF_IF_FLAG_CONNECTING;
277 mif->
flags |= MEMIF_IF_FLAG_CONNECTED;
322 if ((mif->
flags & MEMIF_IF_FLAG_ZERO_COPY) == 0)
326 alloc.
name =
"memif region";
337 if (mif->
flags & MEMIF_IF_FLAG_ZERO_COPY)
360 if (mif->
flags & MEMIF_IF_FLAG_ZERO_COPY)
378 if (mif->
flags & MEMIF_IF_FLAG_ZERO_COPY)
400 if ((mq->
int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
412 if (mif->
flags & MEMIF_IF_FLAG_ZERO_COPY)
426 if ((mq->
int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
438 if (mif->
flags & MEMIF_IF_FLAG_ZERO_COPY)
457 uword *event_data = 0, event_type;
459 f64 start_time, last_run_duration = 0, now;
494 memif_socket_file_t * msf = vec_elt_at_index (mm->socket_files, mif->socket_file_index);
496 now = vlib_time_now (vm);
497 if (now > start_time + 10e-6)
499 vlib_process_suspend (vm, 100e-6);
500 start_time = vlib_time_now (vm);
503 if ((mif->
flags & MEMIF_IF_FLAG_ADMIN_UP) == 0)
506 if (mif->
flags & MEMIF_IF_FLAG_CONNECTING)
509 if (mif->
flags & MEMIF_IF_FLAG_CONNECTED)
512 if (mif->
flags & MEMIF_IF_FLAG_IS_SLAVE)
514 memset (sock, 0, sizeof(clib_socket_t));
515 sock->config = (char *) msf->filename;
516 sock->flags = CLIB_SOCKET_F_IS_CLIENT| CLIB_SOCKET_F_SEQPACKET;
518 if ((err = clib_socket_init (sock)))
520 clib_error_free (err);
524 clib_file_t t = { 0 };
529 t.file_descriptor = sock->fd;
532 t.description =
format (0,
"%U ctl",
537 mif->
flags |= MEMIF_IF_FLAG_CONNECTING;
553 .name =
"memif-process",
568 if (strcmp ((
char *) msf->
filename, (
char *) socket_filename) == 0)
575 return VNET_API_ERROR_ENTRY_ALREADY_EXISTS;
601 return VNET_API_ERROR_INVALID_ARGUMENT;
607 return VNET_API_ERROR_UNEXPECTED_INTF_STATE;
625 if ((sock_id == 0 && is_add == 0) || sock_id == ~0)
627 return VNET_API_ERROR_INVALID_ARGUMENT;
635 if (sock_filename == 0 || sock_filename[0] == 0)
637 return VNET_API_ERROR_INVALID_ARGUMENT;
640 if (sock_filename[0] !=
'/')
650 tmp = strrchr ((
char *) sock_filename,
'/');
653 idx = tmp - (
char *) sock_filename;
654 vec_add (dir, sock_filename, idx);
663 return VNET_API_ERROR_SYSCALL_ERROR_1;
671 sock_filename =
vec_dup (sock_filename);
674 tmp = strrchr ((
char *) sock_filename,
'/');
677 idx = tmp - (
char *) sock_filename;
678 vec_add (dir, sock_filename, idx);
685 (faccessat ( -1, dir, F_OK | R_OK | W_OK, AT_EACCESS)
689 return VNET_API_ERROR_INVALID_ARGUMENT;
706 mif->
flags |= MEMIF_IF_FLAG_DELETING;
759 memset (mif, 0,
sizeof (*mif));
795 rv = VNET_API_ERROR_INVALID_ARGUMENT;
806 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
813 rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
821 struct stat file_stat;
827 if (S_ISSOCK (file_stat.st_mode))
835 rv = VNET_API_ERROR_VALUE_EXIST;
864 bt->
flags = VLIB_BUFFER_TOTAL_LENGTH_VALID;
878 memset (mif, 0,
sizeof (*mif));
897 rnd = (
u32) (now * 1e6);
900 memcpy (args->
hw_addr + 2, &rnd, sizeof (rnd));
914 memif_ip_hw_if_class.index,
922 ret = VNET_API_ERROR_SYSCALL_ERROR_2;
941 struct stat file_stat;
955 ret = VNET_API_ERROR_SYSCALL_ERROR_4;
959 if (stat ((
char *) msf->
filename, &file_stat) == -1)
961 ret = VNET_API_ERROR_SYSCALL_ERROR_8;
967 template.file_descriptor = msf->
sock->fd;
969 template.description =
format (0,
"memif listener %s", msf->
filename);
977 mif->
flags |= MEMIF_IF_FLAG_IS_SLAVE;
979 mif->
flags |= MEMIF_IF_FLAG_ZERO_COPY;
1044 .version = VPP_BUILD_VER,
1045 .description =
"Packet Memory Interface (experimental)",
#define memif_log_err(dev, f,...)
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
vlib_log_class_t log_class
vlib_physmem_region_index_t physmem_region
#define vec_foreach_index(var, v)
Iterate over vector indices.
u8 * format_clib_error(u8 *s, va_list *va)
#define hash_set(h, key, value)
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
#define hash_unset(h, key)
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
void ethernet_delete_interface(vnet_main_t *vnm, u32 hw_if_index)
clib_socket_t ** pending_clients
vnet_main_t * vnet_get_main(void)
static uword clib_socket_is_connected(clib_socket_t *sock)
memif_socket_file_t * socket_files
memif_log2_ring_size_t log2_ring_size
uword mhash_unset(mhash_t *h, void *key, uword *old_value)
void * addr
Pointer to allocated memory, set on successful allocation.
static f64 vlib_time_now(vlib_main_t *vm)
#define vec_add2_aligned(V, P, N, A)
Add N elements to end of vector V, return pointer to new elements in P.
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static clib_error_t * memif_init(vlib_main_t *vm)
clib_error_t * clib_socket_init(clib_socket_t *s)
clib_error_t * memif_msg_send_disconnect(memif_if_t *mif, clib_error_t *err)
memif_interface_mode_t mode
#define VNET_HW_INTERFACE_FLAG_LINK_UP
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define memif_file_del_by_index(a)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
clib_file_function_t * read_function
static void clib_spinlock_free(clib_spinlock_t *p)
static vnet_sw_interface_t * vnet_get_hw_sw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
#define CLIB_SOCKET_F_IS_SERVER
vnet_hw_interface_rx_mode
memset(h->entries, 0, sizeof(h->entries[0])*entries)
#define static_always_inline
clib_error_t * clib_mem_vm_ext_alloc(clib_mem_vm_alloc_t *a)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static int memif_add_socket_file(u32 sock_id, u8 *socket_filename)
#define VLIB_INIT_FUNCTION(x)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
clib_error_t * memif_plugin_api_hookup(vlib_main_t *vm)
static char * vlib_unix_get_runtime_dir(void)
char * name
Name for memory allocation, set by caller.
clib_error_t * memif_init_regions_and_queues(memif_if_t *mif)
static_always_inline void vnet_device_input_set_interrupt_pending(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
memif_log2_ring_size_t log2_ring_size
struct memif_if_t::@486 cfg
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
vnet_device_class_t memif_device_class
u32 per_interface_next_index
static int memif_delete_socket_file(u32 sock_id)
#define clib_error_return(e, args...)
memif_region_offset_t offset
uword size
Allocation size, set by caller.
#define memif_file_add(a, b)
u32 vnet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u32 hw_class_index, u32 hw_instance)
static u32 memif_eth_flag_change(vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 flags)
mhash_t dev_instance_by_id
static vlib_physmem_region_t * vlib_physmem_get_region(vlib_main_t *vm, u8 index)
static void clib_spinlock_init(clib_spinlock_t *p)
#define CLIB_MEM_VM_F_SHARED
memif_region_index_t region
memif_copy_op_t * copy_ops
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
vlib_node_registration_t memif_input_node
(constructor) VLIB_REGISTER_NODE (memif_input_node)
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
int memif_delete_if(vlib_main_t *vm, memif_if_t *mif)
int fd
File descriptor, set on successful allocation if CLIB_MEM_VM_F_SHARED is set.
static clib_error_t * clib_socket_close(clib_socket_t *sock)
#define clib_error_return_unix(e, args...)
int vnet_hw_interface_get_rx_mode(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, vnet_hw_interface_rx_mode *mode)
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX
#define pool_put(P, E)
Free an object E in pool P.
#define vec_dup(V)
Return copy of vector (no header, no alignment)
vlib_buffer_pool_t * buffer_pools
int memif_create_if(vlib_main_t *vm, memif_create_if_args_t *args)
uword int_clib_file_index
#define VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE
VNET_HW_INTERFACE_CLASS(memif_ip_hw_if_class, static)
static uword mhash_set(mhash_t *h, void *key, uword new_value, uword *old_value)
memif_queue_t * tx_queues
clib_error_t * memif_connect(memif_if_t *mif)
#define VLIB_REGISTER_NODE(x,...)
void mhash_init(mhash_t *h, uword n_value_bytes, uword n_key_bytes)
#define vec_free(V)
Free vector's memory (no header).
int memif_socket_filename_add_del(u8 is_add, u32 sock_id, u8 *sock_filename)
uint32_t memif_interface_id_t
void memif_disconnect(memif_if_t *mif, clib_error_t *err)
u32 flags
vm allocation flags: CLIB_MEM_VM_F_SHARED: request shared memory, file descriptor will be provided ...
#define hash_create(elts, value_bytes)
void vnet_hw_interface_assign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, uword thread_index)
static uword * mhash_get(mhash_t *h, const void *key)
static void memif_queue_intfd_close(memif_queue_t *mq)
static void mhash_free(mhash_t *h)
static clib_error_t * memif_int_fd_read_ready(clib_file_t *uf)
static void clib_mem_free(void *p)
clib_error_t * ethernet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u8 *address, u32 *hw_if_index_return, ethernet_flag_change_function_t flag_change)
vlib_buffer_t buffer_template
struct _socket_t clib_socket_t
clib_error_t * memif_slave_conn_fd_write_ready(clib_file_t *uf)
#define clib_fifo_free(f)
#define MEMIF_RING_FLAG_MASK_INT
static void * clib_mem_alloc(uword size)
clib_error_t * memif_slave_conn_fd_error(clib_file_t *uf)
#define CLIB_SOCKET_F_SEQPACKET
clib_error_t * memif_slave_conn_fd_read_ready(clib_file_t *uf)
static vlib_main_t * vlib_get_main(void)
void vnet_delete_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
memif_region_offset_t offset
uword * dev_instance_by_fd
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
clib_error_t * vlib_unix_recursive_mkdir(char *path)
static_always_inline memif_ring_t * memif_get_ring(memif_if_t *mif, memif_ring_type_t type, u16 ring_num)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define MEMIF_DEFAULT_SOCKET_FILENAME
#define CLIB_SOCKET_F_PASSCRED
#define memif_log_warn(dev, f,...)
a point 2 point interface
void memif_socket_close(clib_socket_t **sock)
#define clib_error_free(e)
memif_log2_ring_size_t log2_ring_size
int vnet_hw_interface_unassign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
static void vlib_buffer_init_for_free_list(vlib_buffer_t *dst, vlib_buffer_free_list_t *fl)
static u32 random_u32(u32 *seed)
32-bit random number generator
struct memif_if_t::@487 run
static vlib_thread_main_t * vlib_get_thread_main()
memif_per_thread_data_t * per_thread_data
static vlib_node_registration_t memif_process_node
(constructor) VLIB_REGISTER_NODE (memif_process_node)
vlib_buffer_main_t buffer_main
#define memif_log_debug(dev, f,...)
#define vec_foreach(var, vec)
Vector iterator.
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
memif_queue_t * rx_queues
int vnet_hw_interface_set_rx_mode(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, vnet_hw_interface_rx_mode mode)
clib_error_t * memif_conn_fd_accept_ready(clib_file_t *uf)
uword * socket_file_index_by_sock_id
static vlib_buffer_free_list_t * vlib_buffer_get_free_list(vlib_main_t *vm, vlib_buffer_free_list_index_t free_list_index)
#define CLIB_CACHE_LINE_BYTES
#define CLIB_SOCKET_F_ALLOW_GROUP_WRITE
memif_msg_fifo_elt_t * msg_queue
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
memif_region_index_t region
static void vnet_hw_interface_set_input_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
memif_interface_mode_t mode
static uword memif_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
u8 * format_memif_device_name(u8 *s, va_list *args)
memif_region_size_t region_size
static uword pool_elts(void *v)
Number of active elements in a pool.