FD.io VPP  v17.10-9-gd594711
Vector Packet Processing
private.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #include <vppinfra/lock.h>
19 
20 #define MEMIF_DEFAULT_SOCKET_FILENAME "memif.sock"
21 #define MEMIF_DEFAULT_RING_SIZE 1024
22 #define MEMIF_DEFAULT_RX_QUEUES 1
23 #define MEMIF_DEFAULT_TX_QUEUES 1
24 #define MEMIF_DEFAULT_BUFFER_SIZE 2048
25 
26 #define MEMIF_MAX_M2S_RING (vec_len (vlib_mains) - 1)
27 #define MEMIF_MAX_S2M_RING (vec_len (vlib_mains) - 1)
28 #define MEMIF_MAX_REGION 255
29 #define MEMIF_MAX_LOG2_RING_SIZE 14
30 
31 #define MEMIF_DEBUG 0
32 
33 #if MEMIF_DEBUG == 1
34 #define DBG(...) clib_warning(__VA_ARGS__)
35 #define DBG_UNIX_LOG(...) clib_unix_warning(__VA_ARGS__)
36 #else
37 #define DBG(...)
38 #define DBG_UNIX_LOG(...)
39 #endif
40 
41 #if MEMIF_DEBUG == 1
42 #define memif_file_add(a, b) do { \
43  ASSERT (*a == ~0); \
44  *a = clib_file_add (&file_main, b); \
45  clib_warning ("clib_file_add fd %d private_data %u idx %u", \
46  (b)->file_descriptor, (b)->private_data, *a); \
47 } while (0)
48 
49 #define memif_file_del(a) do { \
50  clib_warning ("clib_file_del idx %u",a - file_main.file_pool); \
51  clib_file_del (&file_main, a); \
52 } while (0)
53 
54 #define memif_file_del_by_index(a) do { \
55  clib_warning ("clib_file_del idx %u", a); \
56  clib_file_del_by_index (&file_main, a); \
57 } while (0)
58 #else
59 #define memif_file_add(a, b) do { \
60  ASSERT (*a == ~0); \
61  *a = clib_file_add (&file_main, b); \
62 } while (0)
63 #define memif_file_del(a) clib_file_del(&file_main, a)
64 #define memif_file_del_by_index(a) clib_file_del_by_index(&file_main, a)
65 #endif
66 
67 typedef struct
68 {
70  int fd;
73  int ref_cnt;
75 
76  /* hash of all registered id */
78 
79  /* hash of all registered fds */
82 
83 typedef struct
84 {
85  void *shm;
87  int fd;
89 
90 typedef struct
91 {
93  int fd;
95 
96 typedef struct
97 {
98  /* ring data */
103 
106 
107  /* interrupts */
108  int int_fd;
111 } memif_queue_t;
112 
113 #define foreach_memif_if_flag \
114  _(0, ADMIN_UP, "admin-up") \
115  _(1, IS_SLAVE, "slave") \
116  _(2, CONNECTING, "connecting") \
117  _(3, CONNECTED, "connected") \
118  _(4, DELETING, "deleting")
119 
120 typedef enum
121 {
122 #define _(a, b, c) MEMIF_IF_FLAG_##b = (1 << a),
124 #undef _
126 
127 typedef struct
128 {
129  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
137 
139 
140  /* socket connection */
142  int conn_fd;
146 
148 
151 
152  /* remote info */
153  pid_t remote_pid;
154  uid_t remote_uid;
155  gid_t remote_gid;
158 
159  struct
160  {
165  } cfg;
166 
167  struct
168  {
169  memif_log2_ring_size_t log2_ring_size;
170  u8 num_s2m_rings;
171  u8 num_m2s_rings;
172  u16 buffer_size;
173  } run;
174 
175  /* disconnect strings */
178 } memif_if_t;
179 
180 typedef struct
181 {
182  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
183 
184  /** API message ID base */
186 
187  /* pool of all memory interfaces */
189 
190  /* pool of all unix socket files */
193 
194  /* rx buffer cache */
196 
197 } memif_main_t;
198 
199 extern memif_main_t memif_main;
202 
203 enum
204 {
208 
209 typedef struct
210 {
219  u8 hw_addr[6];
222 
223  /* return */
226 
230 
233 {
234  u16 region = ring->desc[slot].region;
235  return mif->regions[region].shm + ring->desc[slot].offset;
236 }
237 
238 /* memif.c */
241 void memif_disconnect (memif_if_t * mif, clib_error_t * err);
242 
243 /* socket.c */
252  clib_error_t * err);
253 u8 *format_memif_device_name (u8 * s, va_list * args);
254 
255 /*
256  * fd.io coding-style-patch-verification: ON
257  *
258  * Local Variables:
259  * eval: (c-set-style "gnu")
260  * End:
261  */
memif_if_t * interfaces
Definition: private.h:188
Definition: mhash.h:46
vlib_node_registration_t memif_input_node
(constructor) VLIB_REGISTER_NODE (memif_input_node)
Definition: node.c:512
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:68
u8 * secret
Definition: private.h:145
u8 * format_memif_device_name(u8 *s, va_list *args)
Definition: device.c:52
mhash_t socket_file_index_by_filename
Definition: private.h:192
memif_socket_file_t * socket_files
Definition: private.h:191
memif_log2_ring_size_t log2_ring_size
Definition: private.h:161
void memif_disconnect(memif_if_t *mif, clib_error_t *err)
Definition: memif.c:69
memif_interface_mode_t
Definition: memif.h:53
uint16_t memif_region_index_t
Definition: memif.h:60
struct _vlib_node_registration vlib_node_registration_t
clib_error_t * memif_msg_send_disconnect(memif_if_t *mif, clib_error_t *err)
Definition: socket.c:213
struct _vnet_device_class vnet_device_class_t
u8 num_m2s_rings
Definition: private.h:163
uid_t remote_uid
Definition: private.h:154
#define static_always_inline
Definition: clib.h:85
u8 * remote_name
Definition: private.h:156
gid_t remote_gid
Definition: private.h:155
clib_error_t * memif_master_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:554
uword socket_file_index
Definition: private.h:141
u16 buffer_size
Definition: private.h:164
memif_log2_ring_size_t log2_ring_size
Definition: private.h:216
vnet_device_class_t memif_device_class
u32 per_interface_next_index
Definition: private.h:138
memif_region_offset_t offset
Definition: private.h:102
u16 msg_id_base
API message ID base.
Definition: private.h:185
unsigned long u64
Definition: types.h:89
mhash_t dev_instance_by_id
Definition: private.h:77
clib_error_t * memif_master_conn_fd_error(clib_file_t *uf)
Definition: socket.c:657
memif_region_index_t region
Definition: memif.h:150
u16 last_head
Definition: private.h:104
clib_error_t * memif_master_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:618
memif_desc_t desc[0]
Definition: memif.h:174
int memif_delete_if(vlib_main_t *vm, memif_if_t *mif)
Definition: memif.c:473
uword dev_instance
Definition: private.h:135
uint8_t memif_log2_ring_size_t
Definition: memif.h:66
clib_spinlock_t lockp
Definition: private.h:130
pid_t remote_pid
Definition: private.h:153
#define foreach_memif_if_flag
Definition: private.h:113
memif_interface_id_t id
Definition: private.h:211
uword int_clib_file_index
Definition: private.h:109
memif_queue_t * tx_queues
Definition: private.h:150
int memif_create_if(vlib_main_t *vm, memif_create_if_args_t *args)
Definition: memif.c:543
vlib_main_t * vm
Definition: buffer.c:283
u8 * local_disc_string
Definition: private.h:176
clib_error_t * memif_connect(memif_if_t *mif)
Definition: memif.c:173
uint32_t memif_interface_id_t
Definition: memif.h:64
u16 last_tail
Definition: private.h:105
memif_region_t * regions
Definition: private.h:147
u32 ** rx_buffers
Definition: private.h:195
memif_main_t memif_main
Definition: memif.c:43
unsigned int u32
Definition: types.h:88
memif_msg_t msg
Definition: private.h:92
static_always_inline void * memif_get_buffer(memif_if_t *mif, memif_ring_t *ring, u16 slot)
Definition: private.h:232
u32 flags
Definition: private.h:131
memif_ring_t * ring
Definition: private.h:99
int conn_fd
Definition: private.h:142
u32 hw_if_index
Definition: private.h:133
clib_error_t * memif_slave_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:635
enum @336 memif_process_event_t
uword conn_clib_file_index
Definition: private.h:143
clib_error_t * memif_slave_conn_fd_error(clib_file_t *uf)
Definition: socket.c:643
clib_error_t * memif_slave_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:592
u64 int_count
Definition: private.h:110
u64 uword
Definition: types.h:112
memif_region_offset_t offset
Definition: memif.h:154
uword * dev_instance_by_fd
Definition: private.h:80
u8 num_s2m_rings
Definition: private.h:162
unsigned short u16
Definition: types.h:57
uint64_t memif_region_size_t
Definition: memif.h:62
unsigned char u8
Definition: types.h:56
void * shm
Definition: private.h:85
u8 * remote_if_name
Definition: private.h:157
memif_interface_id_t id
Definition: private.h:132
uword clib_file_index
Definition: private.h:71
clib_error_t * memif_init_regions_and_queues(memif_if_t *mif)
Definition: memif.c:264
memif_log2_ring_size_t log2_ring_size
Definition: private.h:100
clib_error_t * memif_plugin_api_hookup(vlib_main_t *vm)
Definition: memif_api.c:311
u8 * remote_disc_string
Definition: private.h:177
Definition: file.h:50
memif_queue_t * rx_queues
Definition: private.h:149
clib_error_t * memif_conn_fd_accept_ready(clib_file_t *uf)
Definition: socket.c:694
uword * pending_file_indices
Definition: private.h:72
uint64_t memif_region_offset_t
Definition: memif.h:61
memif_msg_fifo_elt_t * msg_queue
Definition: private.h:144
memif_region_index_t region
Definition: private.h:101
u32 sw_if_index
Definition: private.h:134
memif_region_size_t region_size
Definition: private.h:86
memif_if_flag_t
Definition: private.h:120