FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
memif.c
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 
19 #define _GNU_SOURCE
20 #include <stdint.h>
21 #include <net/if.h>
22 #include <sys/types.h>
23 #include <fcntl.h>
24 #include <sys/ioctl.h>
25 #include <sys/socket.h>
26 #include <sys/un.h>
27 #include <sys/uio.h>
28 #include <sys/mman.h>
29 #include <sys/prctl.h>
30 #include <sys/eventfd.h>
31 #include <inttypes.h>
32 #include <limits.h>
33 
34 #include <vlib/vlib.h>
35 #include <vlib/unix/unix.h>
36 #include <vppinfra/linux/syscall.h>
37 #include <vnet/plugin/plugin.h>
38 #include <vnet/ethernet/ethernet.h>
39 #include <vpp/app/version.h>
40 #include <memif/memif.h>
41 #include <memif/private.h>
42 
44 
45 static u32
47 {
48  /* nothing for now */
49  return 0;
50 }
51 
52 static void
54 {
55  if (mq->int_clib_file_index != ~0)
56  {
58  mq->int_clib_file_index = ~0;
59  mq->int_fd = -1;
60  }
61  else if (mq->int_fd > -1)
62  {
63  close (mq->int_fd);
64  mq->int_fd = -1;
65  }
66 }
67 
68 void
70 {
71  memif_main_t *mm = &memif_main;
72  vnet_main_t *vnm = vnet_get_main ();
73  memif_region_t *mr;
74  memif_queue_t *mq;
75  int i;
76 
77  if (mif == 0)
78  return;
79 
80  DBG ("disconnect %u (%v)", mif->dev_instance, err ? err->what : 0);
81 
82  if (err)
83  {
84  clib_error_t *e = 0;
85  mif->local_disc_string = vec_dup (err->what);
86  if (mif->sock && clib_socket_is_connected (mif->sock))
87  e = memif_msg_send_disconnect (mif, err);
88  clib_error_free (e);
89  }
90 
91  /* set interface down */
92  mif->flags &= ~(MEMIF_IF_FLAG_CONNECTED | MEMIF_IF_FLAG_CONNECTING);
93  if (mif->hw_if_index != ~0)
95 
96  /* close connection socket */
97  if (mif->sock && mif->sock->fd)
98  {
100  mif->socket_file_index);
101  hash_unset (msf->dev_instance_by_fd, mif->sock->fd);
102  memif_socket_close (&mif->sock);
103  }
104  else if (mif->sock)
105  {
106  clib_error_t *err;
107  err = clib_socket_close (mif->sock);
108  if (err)
109  clib_error_report (err);
110  clib_mem_free (mif->sock);
111  }
112 
113  vec_foreach_index (i, mif->rx_queues)
114  {
115  mq = vec_elt_at_index (mif->rx_queues, i);
116  if (mq->ring)
117  {
118  int rv;
120  if (rv)
121  DBG ("Warning: unable to unassign interface %d, "
122  "queue %d: rc=%d", mif->hw_if_index, i, rv);
123  mq->ring = 0;
124  }
125  }
126 
127  /* free tx and rx queues */
129  vec_free (mif->rx_queues);
130 
132  vec_free (mif->tx_queues);
133 
134  /* free memory regions */
135  vec_foreach (mr, mif->regions)
136  {
137  int rv;
138  if ((rv = munmap (mr->shm, mr->region_size)))
139  clib_warning ("munmap failed, rv = %d", rv);
140  if (mr->fd > -1)
141  close (mr->fd);
142  }
143  vec_free (mif->regions);
144  vec_free (mif->remote_name);
145  vec_free (mif->remote_if_name);
146  clib_fifo_free (mif->msg_queue);
147 }
148 
149 static clib_error_t *
151 {
152  memif_main_t *mm = &memif_main;
153  vnet_main_t *vnm = vnet_get_main ();
154  u16 qid = uf->private_data & 0xFFFF;
155  memif_if_t *mif = vec_elt_at_index (mm->interfaces, uf->private_data >> 16);
156  memif_queue_t *mq = vec_elt_at_index (mif->rx_queues, qid);
157  u64 b;
158  ssize_t size;
159 
160  size = read (uf->file_descriptor, &b, sizeof (b));
161  if (size < 0)
162  {
163  DBG_UNIX_LOG ("Failed to read from socket");
164  return 0;
165  }
166 
168  mq->int_count++;
169 
170  return 0;
171 }
172 
173 
174 clib_error_t *
176 {
177  vnet_main_t *vnm = vnet_get_main ();
178  clib_file_t template = { 0 };
179  memif_region_t *mr;
180  int i;
181 
182  DBG ("connect %u", mif->dev_instance);
183 
186 
187  vec_foreach (mr, mif->regions)
188  {
189  if (mr->shm)
190  continue;
191 
192  if (mr->fd < 0)
193  clib_error_return (0, "no memory region fd");
194 
195  if ((mr->shm = mmap (NULL, mr->region_size, PROT_READ | PROT_WRITE,
196  MAP_SHARED, mr->fd, 0)) == MAP_FAILED)
197  return clib_error_return_unix (0, "mmap");
198  }
199 
200  template.read_function = memif_int_fd_read_ready;
201 
202  vec_foreach_index (i, mif->tx_queues)
203  {
204  memif_queue_t *mq = vec_elt_at_index (mif->tx_queues, i);
205 
206  mq->ring = mif->regions[mq->region].shm + mq->offset;
207  if (mq->ring->cookie != MEMIF_COOKIE)
208  return clib_error_return (0, "wrong cookie on tx ring %u", i);
209  }
210 
211  vec_foreach_index (i, mif->rx_queues)
212  {
213  memif_queue_t *mq = vec_elt_at_index (mif->rx_queues, i);
214  int rv;
215 
216  mq->ring = mif->regions[mq->region].shm + mq->offset;
217  if (mq->ring->cookie != MEMIF_COOKIE)
218  return clib_error_return (0, "wrong cookie on tx ring %u", i);
219 
220  if (mq->int_fd > -1)
221  {
222  template.file_descriptor = mq->int_fd;
223  template.private_data = (mif->dev_instance << 16) | (i & 0xFFFF);
224  memif_file_add (&mq->int_clib_file_index, &template);
225  }
227  rv = vnet_hw_interface_set_rx_mode (vnm, mif->hw_if_index, i,
229  if (rv)
231  ("Warning: unable to set rx mode for interface %d queue %d: "
232  "rc=%d", mif->hw_if_index, i, rv);
233  else
234  {
236  vnet_hw_interface_get_rx_mode (vnm, mif->hw_if_index, i, &rxmode);
237 
238  if (rxmode == VNET_HW_INTERFACE_RX_MODE_POLLING)
240  }
241  }
242 
243  mif->flags &= ~MEMIF_IF_FLAG_CONNECTING;
244  mif->flags |= MEMIF_IF_FLAG_CONNECTED;
245 
248  return 0;
249 }
250 
253 {
254  if (vec_len (mif->regions) == 0)
255  return NULL;
256  void *p = mif->regions[0].shm;
257  int ring_size =
258  sizeof (memif_ring_t) +
259  sizeof (memif_desc_t) * (1 << mif->run.log2_ring_size);
260  p += (ring_num + type * mif->run.num_s2m_rings) * ring_size;
261 
262  return (memif_ring_t *) p;
263 }
264 
265 clib_error_t *
267 {
268  memif_ring_t *ring = NULL;
269  int i, j;
270  u64 buffer_offset;
271  memif_region_t *r;
272  clib_mem_vm_alloc_t alloc = { 0 };
273  clib_error_t *err;
274 
276  r = vec_elt_at_index (mif->regions, 0);
277 
278  buffer_offset = (mif->run.num_s2m_rings + mif->run.num_m2s_rings) *
279  (sizeof (memif_ring_t) +
280  sizeof (memif_desc_t) * (1 << mif->run.log2_ring_size));
281 
282  r->region_size = buffer_offset +
283  mif->run.buffer_size * (1 << mif->run.log2_ring_size) *
284  (mif->run.num_s2m_rings + mif->run.num_m2s_rings);
285 
286  alloc.name = "memif region";
287  alloc.size = r->region_size;
288  alloc.flags = CLIB_MEM_VM_F_SHARED;
289 
290  err = clib_mem_vm_ext_alloc (&alloc);
291  if (err)
292  return err;
293 
294  r->fd = alloc.fd;
295  r->shm = alloc.addr;
296 
297  for (i = 0; i < mif->run.num_s2m_rings; i++)
298  {
299  ring = memif_get_ring (mif, MEMIF_RING_S2M, i);
300  ring->head = ring->tail = 0;
301  ring->cookie = MEMIF_COOKIE;
302  for (j = 0; j < (1 << mif->run.log2_ring_size); j++)
303  {
304  u16 slot = i * (1 << mif->run.log2_ring_size) + j;
305  ring->desc[j].region = 0;
306  ring->desc[j].offset =
307  buffer_offset + (u32) (slot * mif->run.buffer_size);
308  ring->desc[j].buffer_length = mif->run.buffer_size;
309  }
310  }
311  for (i = 0; i < mif->run.num_m2s_rings; i++)
312  {
313  ring = memif_get_ring (mif, MEMIF_RING_M2S, i);
314  ring->head = ring->tail = 0;
315  ring->cookie = MEMIF_COOKIE;
316  for (j = 0; j < (1 << mif->run.log2_ring_size); j++)
317  {
318  u16 slot =
319  (i + mif->run.num_s2m_rings) * (1 << mif->run.log2_ring_size) + j;
320  ring->desc[j].region = 0;
321  ring->desc[j].offset =
322  buffer_offset + (u32) (slot * mif->run.buffer_size);
323  ring->desc[j].buffer_length = mif->run.buffer_size;
324  }
325  }
326 
327  ASSERT (mif->tx_queues == 0);
330  vec_foreach_index (i, mif->tx_queues)
331  {
332  memif_queue_t *mq = vec_elt_at_index (mif->tx_queues, i);
333  if ((mq->int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
334  return clib_error_return_unix (0, "eventfd[tx queue %u]", i);
335  mq->int_clib_file_index = ~0;
336  mq->ring = memif_get_ring (mif, MEMIF_RING_S2M, i);
337  mq->log2_ring_size = mif->cfg.log2_ring_size;
338  mq->region = 0;
339  mq->offset = (void *) mq->ring - (void *) mif->regions[mq->region].shm;
340  mq->last_head = 0;
341  }
342 
343  ASSERT (mif->rx_queues == 0);
346  vec_foreach_index (i, mif->rx_queues)
347  {
348  memif_queue_t *mq = vec_elt_at_index (mif->rx_queues, i);
349  if ((mq->int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
350  return clib_error_return_unix (0, "eventfd[rx queue %u]", i);
351  mq->int_clib_file_index = ~0;
352  mq->ring = memif_get_ring (mif, MEMIF_RING_M2S, i);
353  mq->log2_ring_size = mif->cfg.log2_ring_size;
354  mq->region = 0;
355  mq->offset = (void *) mq->ring - (void *) mif->regions[mq->region].shm;
356  mq->last_head = 0;
357  }
358 
359  return 0;
360 }
361 
362 static uword
364 {
365  memif_main_t *mm = &memif_main;
366  memif_if_t *mif;
367  clib_socket_t *sock;
368  uword *event_data = 0, event_type;
369  u8 enabled = 0;
370  f64 start_time, last_run_duration = 0, now;
371  clib_error_t *err;
372 
373  sock = clib_mem_alloc (sizeof (clib_socket_t));
374  memset (sock, 0, sizeof (clib_socket_t));
375 
376  while (1)
377  {
378  if (enabled)
380  last_run_duration);
381  else
383 
384  event_type = vlib_process_get_events (vm, &event_data);
385  vec_reset_length (event_data);
386 
387  switch (event_type)
388  {
389  case ~0:
390  break;
392  enabled = 1;
393  break;
395  enabled = 0;
396  continue;
397  default:
398  ASSERT (0);
399  }
400 
401  last_run_duration = start_time = vlib_time_now (vm);
402  /* *INDENT-OFF* */
403  pool_foreach (mif, mm->interfaces,
404  ({
405  memif_socket_file_t * msf = vec_elt_at_index (mm->socket_files, mif->socket_file_index);
406  /* Allow no more than 10us without a pause */
407  now = vlib_time_now (vm);
408  if (now > start_time + 10e-6)
409  {
410  vlib_process_suspend (vm, 100e-6); /* suspend for 100 us */
411  start_time = vlib_time_now (vm);
412  }
413 
414  if ((mif->flags & MEMIF_IF_FLAG_ADMIN_UP) == 0)
415  continue;
416 
417  if (mif->flags & MEMIF_IF_FLAG_CONNECTING)
418  continue;
419 
420  if (mif->flags & MEMIF_IF_FLAG_CONNECTED)
421  continue;
422 
423  if (mif->flags & MEMIF_IF_FLAG_IS_SLAVE)
424  {
425  memset (sock, 0, sizeof(clib_socket_t));
426  sock->config = (char *) msf->filename;
427  sock->flags = CLIB_SOCKET_F_IS_CLIENT| CLIB_SOCKET_F_SEQPACKET;
428 
429  if ((err = clib_socket_init (sock)))
430  {
431  clib_error_free (err);
432  }
433  else
434  {
435  clib_file_t t = { 0 };
436 
437  t.read_function = memif_slave_conn_fd_read_ready;
438  t.write_function = memif_slave_conn_fd_write_ready;
439  t.error_function = memif_slave_conn_fd_error;
440  t.file_descriptor = sock->fd;
441  t.private_data = mif->dev_instance;
442  memif_file_add (&sock->private_data, &t);
443  hash_set (msf->dev_instance_by_fd, sock->fd, mif->dev_instance);
444 
445  mif->flags |= MEMIF_IF_FLAG_CONNECTING;
446  mif->sock = sock;
447  sock = clib_mem_alloc (sizeof(clib_socket_t));
448  }
449  }
450  }));
451  /* *INDENT-ON* */
452  last_run_duration = vlib_time_now (vm) - last_run_duration;
453  }
454  return 0;
455 }
456 
457 /* *INDENT-OFF* */
459  .function = memif_process,
460  .type = VLIB_NODE_TYPE_PROCESS,
461  .name = "memif-process",
462 };
463 /* *INDENT-ON* */
464 
465 int
467 {
468  vnet_main_t *vnm = vnet_get_main ();
469  memif_main_t *mm = &memif_main;
470  memif_socket_file_t *msf =
472  clib_error_t *err;
473 
474  mif->flags |= MEMIF_IF_FLAG_DELETING;
477 
478  /* bring down the interface */
481 
482  err = clib_error_return (0, "interface deleted");
483  memif_disconnect (mif, err);
484  clib_error_free (err);
485 
486  /* remove the interface */
487  if (mif->mode == MEMIF_INTERFACE_MODE_IP)
489  else
491  mif->hw_if_index = ~0;
492 
493  /* free interface data structures */
494  clib_spinlock_free (&mif->lockp);
495  mhash_unset (&msf->dev_instance_by_id, &mif->id, 0);
496 
497  /* remove socket file */
498  if (--(msf->ref_cnt) == 0)
499  {
500  if (msf->is_listener)
501  {
502  int i;
504  {
506  }
507  memif_socket_close (&msf->sock);
508  vec_free (msf->pending_clients);
509  }
513  vec_free (msf->filename);
514  if (msf->sock)
515  {
516  err = clib_socket_close (msf->sock);
517  if (err)
518  clib_error_report (err);
519  clib_mem_free (msf->sock);
520  }
521  pool_put (mm->socket_files, msf);
522  }
523 
524  memset (mif, 0, sizeof (*mif));
525  pool_put (mm->interfaces, mif);
526 
527  if (pool_elts (mm->interfaces) == 0)
530 
531  return 0;
532 }
533 
534 /* *INDENT-OFF* */
535 VNET_HW_INTERFACE_CLASS (memif_ip_hw_if_class, static) =
536 {
537  .name = "memif-ip",
539 };
540 /* *INDENT-ON* */
541 
542 int
544 {
545  memif_main_t *mm = &memif_main;
547  vnet_main_t *vnm = vnet_get_main ();
548  memif_if_t *mif = 0;
550  clib_error_t *error = 0;
551  int ret = 0;
552  uword *p;
554  memif_socket_file_t *msf = 0;
555  u8 *socket_filename;
556  int rv = 0;
557 
558  if (args->socket_filename == 0 || args->socket_filename[0] != '/')
559  {
560  clib_error_t *error;
562  if (error)
563  {
564  clib_error_free (error);
565  return VNET_API_ERROR_SYSCALL_ERROR_1;
566  }
567 
568  if (args->socket_filename == 0)
569  socket_filename = format (0, "%s/%s%c", vlib_unix_get_runtime_dir (),
571  else
572  socket_filename = format (0, "%s/%s%c", vlib_unix_get_runtime_dir (),
573  args->socket_filename, 0);
574 
575  }
576  else
577  socket_filename = vec_dup (args->socket_filename);
578 
579  p = mhash_get (&mm->socket_file_index_by_filename, socket_filename);
580 
581  if (p)
582  {
583  msf = vec_elt_at_index (mm->socket_files, p[0]);
584 
585  /* existing socket file can be either master or slave but cannot be both */
586  if (!msf->is_listener != !args->is_master)
587  {
588  rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
589  goto done;
590  }
591 
592  p = mhash_get (&msf->dev_instance_by_id, &args->id);
593  if (p)
594  {
595  rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
596  goto done;
597  }
598  }
599 
600  /* Create new socket file */
601  if (msf == 0)
602  {
603  struct stat file_stat;
604  /* If we are creating listener make sure file doesn't exist or if it
605  * exists thn delete it if it is old socket file */
606  if (args->is_master &&
607  (stat ((char *) socket_filename, &file_stat) == 0))
608  {
609  if (S_ISSOCK (file_stat.st_mode))
610  {
611  unlink ((char *) socket_filename);
612  }
613  else
614  {
615  error = clib_error_return (0, "File exists for %s",
616  socket_filename);
617  clib_error_report (error);
618  rv = VNET_API_ERROR_VALUE_EXIST;
619  goto done;
620  }
621  }
622  pool_get (mm->socket_files, msf);
623  memset (msf, 0, sizeof (memif_socket_file_t));
624  mhash_init (&msf->dev_instance_by_id, sizeof (uword),
625  sizeof (memif_interface_id_t));
626  msf->dev_instance_by_fd = hash_create (0, sizeof (uword));
627  msf->filename = socket_filename;
628  msf->is_listener = (args->is_master != 0);
629  socket_filename = 0;
631  msf - mm->socket_files, 0);
632  DBG ("creating socket file %s", msf->filename);
633  }
634 
635  pool_get (mm->interfaces, mif);
636  memset (mif, 0, sizeof (*mif));
637  mif->dev_instance = mif - mm->interfaces;
638  mif->socket_file_index = msf - mm->socket_files;
639  mif->id = args->id;
640  mif->sw_if_index = mif->hw_if_index = mif->per_interface_next_index = ~0;
641  mif->mode = args->mode;
642  if (args->secret)
643  mif->secret = vec_dup (args->secret);
644 
645  if (tm->n_vlib_mains > 1)
646  clib_spinlock_init (&mif->lockp);
647 
648 
650  {
651 
652  if (!args->hw_addr_set)
653  {
654  f64 now = vlib_time_now (vm);
655  u32 rnd;
656  rnd = (u32) (now * 1e6);
657  rnd = random_u32 (&rnd);
658 
659  memcpy (args->hw_addr + 2, &rnd, sizeof (rnd));
660  args->hw_addr[0] = 2;
661  args->hw_addr[1] = 0xfe;
662  }
664  mif->dev_instance, args->hw_addr,
665  &mif->hw_if_index,
667  }
668  else if (mif->mode == MEMIF_INTERFACE_MODE_IP)
669  {
670  mif->hw_if_index =
672  mif->dev_instance,
673  memif_ip_hw_if_class.index,
674  mif->dev_instance);
675  }
676  else
677  error = clib_error_return (0, "unsupported interface mode");
678 
679  if (error)
680  {
681  clib_error_report (error);
682  ret = VNET_API_ERROR_SYSCALL_ERROR_2;
683  goto error;
684  }
685 
686  sw = vnet_get_hw_sw_interface (vnm, mif->hw_if_index);
687  mif->sw_if_index = sw->sw_if_index;
688 
689  mif->cfg.log2_ring_size = args->log2_ring_size;
690  mif->cfg.buffer_size = args->buffer_size;
691  mif->cfg.num_s2m_rings =
692  args->is_master ? args->rx_queues : args->tx_queues;
693  mif->cfg.num_m2s_rings =
694  args->is_master ? args->tx_queues : args->rx_queues;
695 
696  args->sw_if_index = mif->sw_if_index;
697 
698  /* If this is new one, start listening */
699  if (msf->is_listener && msf->ref_cnt == 0)
700  {
701  struct stat file_stat;
703 
704  ASSERT (msf->sock == 0);
705  msf->sock = s;
706 
707  memset (s, 0, sizeof (clib_socket_t));
708  s->config = (char *) msf->filename;
709  s->flags = CLIB_SOCKET_F_IS_SERVER |
712 
713  if ((error = clib_socket_init (s)))
714  {
715  clib_error_report (error);
716  ret = VNET_API_ERROR_SYSCALL_ERROR_4;
717  goto error;
718  }
719 
720  if (stat ((char *) msf->filename, &file_stat) == -1)
721  {
722  ret = VNET_API_ERROR_SYSCALL_ERROR_8;
723  goto error;
724  }
725 
726  clib_file_t template = { 0 };
728  template.file_descriptor = msf->sock->fd;
729  template.private_data = mif->socket_file_index;
730  memif_file_add (&msf->sock->private_data, &template);
731  }
732 
733  msf->ref_cnt++;
734 
735  if (args->is_master == 0)
736  mif->flags |= MEMIF_IF_FLAG_IS_SLAVE;
737 
738  hw = vnet_get_hw_interface (vnm, mif->hw_if_index);
741  memif_input_node.index);
742 
743  mhash_set (&msf->dev_instance_by_id, &mif->id, mif->dev_instance, 0);
744 
745  if (pool_elts (mm->interfaces) == 1)
746  {
749  }
750  goto done;
751 
752 error:
753  if (mif->hw_if_index != ~0)
754  {
755  if (mif->mode == MEMIF_INTERFACE_MODE_IP)
757  else
759  mif->hw_if_index = ~0;
760  }
761  memif_delete_if (vm, mif);
762  return ret;
763 
764 done:
765  vec_free (socket_filename);
766  return rv;
767 }
768 
769 
770 static clib_error_t *
772 {
773  memif_main_t *mm = &memif_main;
775 
776  memset (mm, 0, sizeof (memif_main_t));
777 
778  /* initialize binary API */
780 
782 
785 
786  return 0;
787 }
788 
790 
791 /* *INDENT-OFF* */
793  .version = VPP_BUILD_VER,
794  .description = "Packet Memory Interface (experimetal)",
795 };
796 /* *INDENT-ON* */
797 
798 /*
799  * fd.io coding-style-patch-verification: ON
800  *
801  * Local Variables:
802  * eval: (c-set-style "gnu")
803  * End:
804  */
#define DBG_UNIX_LOG(...)
memif_if_t * interfaces
Definition: private.h:181
vmrglw vmrglh hi
#define vec_foreach_index(var, v)
Iterate over vector indices.
#define hash_set(h, key, value)
Definition: hash.h:254
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:538
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...
Definition: node_funcs.h:699
#define hash_unset(h, key)
Definition: hash.h:260
u8 * secret
Definition: private.h:141
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:619
void ethernet_delete_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface.c:322
clib_socket_t ** pending_clients
Definition: private.h:69
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static uword clib_socket_is_connected(clib_socket_t *sock)
Definition: socket.h:112
mhash_t socket_file_index_by_filename
Definition: private.h:185
memif_socket_file_t * socket_files
Definition: private.h:184
memif_log2_ring_size_t log2_ring_size
Definition: private.h:154
#define NULL
Definition: clib.h:55
uword mhash_unset(mhash_t *h, void *key, uword *old_value)
Definition: mhash.c:353
struct memif_if_t::@366 run
void * addr
Pointer to allocated memory, set on successful allocation.
Definition: mem.h:344
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:224
struct memif_if_t::@365 cfg
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u32 file_descriptor
Definition: file.h:53
static clib_error_t * memif_init(vlib_main_t *vm)
Definition: memif.c:771
clib_error_t * clib_socket_init(clib_socket_t *s)
Definition: socket.c:376
clib_error_t * memif_msg_send_disconnect(memif_if_t *mif, clib_error_t *err)
Definition: socket.c:189
memif_interface_mode_t mode
Definition: private.h:208
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:394
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:443
u8 num_m2s_rings
Definition: private.h:156
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:225
#define memif_file_del_by_index(a)
Definition: private.h:62
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
clib_file_function_t * read_function
Definition: file.h:63
static void clib_spinlock_free(clib_spinlock_t *p)
Definition: lock.h:40
uint32_t buffer_length
Definition: memif.h:151
static vnet_sw_interface_t * vnet_get_hw_sw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define CLIB_SOCKET_F_IS_SERVER
Definition: socket.h:58
vnet_hw_interface_rx_mode
Definition: interface.h:51
#define static_always_inline
Definition: clib.h:93
clib_error_t * clib_mem_vm_ext_alloc(clib_mem_vm_alloc_t *a)
Definition: mem.c:58
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:438
u8 * remote_name
Definition: private.h:149
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
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...
Definition: node_funcs.h:542
clib_error_t * memif_plugin_api_hookup(vlib_main_t *vm)
Definition: memif_api.c:311
uword socket_file_index
Definition: private.h:139
static char * vlib_unix_get_runtime_dir(void)
Definition: unix.h:138
uint32_t cookie
Definition: memif.h:167
char * name
Name for memory allocation, set by caller.
Definition: mem.h:341
clib_error_t * memif_init_regions_and_queues(memif_if_t *mif)
Definition: memif.c:266
static_always_inline void vnet_device_input_set_interrupt_pending(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.h:136
u16 buffer_size
Definition: private.h:157
memif_log2_ring_size_t log2_ring_size
Definition: private.h:209
#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
Definition: private.h:135
#define clib_error_return(e, args...)
Definition: error.h:99
memif_region_offset_t offset
Definition: private.h:99
unsigned long u64
Definition: types.h:89
uword size
Allocation size, set by caller.
Definition: mem.h:342
#define memif_file_add(a, b)
Definition: private.h:58
u32 vnet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u32 hw_class_index, u32 hw_instance)
Definition: interface.c:689
static u32 memif_eth_flag_change(vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 flags)
Definition: memif.c:46
mhash_t dev_instance_by_id
Definition: private.h:74
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:33
#define CLIB_MEM_VM_F_SHARED
Definition: mem.h:326
memif_region_index_t region
Definition: memif.h:150
u16 last_head
Definition: private.h:101
vlib_node_registration_t memif_input_node
(constructor) VLIB_REGISTER_NODE (memif_input_node)
Definition: node.c:497
memif_desc_t desc[0]
Definition: memif.h:174
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:950
int memif_delete_if(vlib_main_t *vm, memif_if_t *mif)
Definition: memif.c:466
int fd
File desriptor, set on successful allocation if CLIB_MEM_VM_F_SHARED is set.
Definition: mem.h:345
uword dev_instance
Definition: private.h:132
static clib_error_t * clib_socket_close(clib_socket_t *sock)
Definition: socket.h:175
clib_spinlock_t lockp
Definition: private.h:127
#define clib_error_return_unix(e, args...)
Definition: error.h:102
int vnet_hw_interface_get_rx_mode(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, vnet_hw_interface_rx_mode *mode)
Definition: devices.c:312
#define hash_free(h)
Definition: hash.h:309
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:271
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:370
memif_interface_id_t id
Definition: private.h:204
int memif_create_if(vlib_main_t *vm, memif_create_if_args_t *args)
Definition: memif.c:543
uword int_clib_file_index
Definition: private.h:106
#define VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE
Definition: interface.h:420
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)
Definition: mhash.h:117
memif_queue_t * tx_queues
Definition: private.h:146
clib_error_t * memif_connect(memif_if_t *mif)
Definition: memif.c:175
static void mhash_init_c_string(mhash_t *h, uword n_value_bytes)
Definition: mhash.h:78
void mhash_init(mhash_t *h, uword n_value_bytes, uword n_key_bytes)
Definition: mhash.c:168
vlib_main_t * vm
Definition: buffer.c:283
u8 * local_disc_string
Definition: private.h:169
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
#define clib_warning(format, args...)
Definition: error.h:59
#define DBG(...)
uint32_t memif_interface_id_t
Definition: memif.h:64
void memif_disconnect(memif_if_t *mif, clib_error_t *err)
Definition: memif.c:69
u32 flags
vm allocation flags: CLIB_MEM_VM_F_SHARED: request shared memory, file destiptor will be provided o...
Definition: mem.h:331
memif_region_t * regions
Definition: private.h:143
#define hash_create(elts, value_bytes)
Definition: hash.h:681
u32 ** rx_buffers
Definition: private.h:188
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
void vnet_hw_interface_assign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, uword thread_index)
Definition: devices.c:138
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
static void memif_queue_intfd_close(memif_queue_t *mq)
Definition: memif.c:53
static void mhash_free(mhash_t *h)
Definition: mhash.h:149
static clib_error_t * memif_int_fd_read_ready(clib_file_t *uf)
Definition: memif.c:150
u32 flags
Definition: private.h:128
memif_ring_t * ring
Definition: private.h:96
u64 size
Definition: vhost-user.h:76
static void clib_mem_free(void *p)
Definition: mem.h:179
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)
Definition: interface.c:273
#define clib_error_report(e)
Definition: error.h:113
u32 hw_if_index
Definition: private.h:130
struct _socket_t clib_socket_t
clib_error_t * memif_slave_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:568
#define clib_fifo_free(f)
Definition: fifo.h:257
#define MEMIF_RING_FLAG_MASK_INT
Definition: memif.h:169
static void * clib_mem_alloc(uword size)
Definition: mem.h:112
clib_error_t * memif_slave_conn_fd_error(clib_file_t *uf)
Definition: socket.c:576
#define CLIB_SOCKET_F_SEQPACKET
Definition: socket.h:63
clib_error_t * memif_slave_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:525
u64 int_count
Definition: private.h:107
void vnet_delete_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface.c:899
u64 uword
Definition: types.h:112
memif_region_offset_t offset
Definition: memif.h:154
uword * dev_instance_by_fd
Definition: private.h:77
u8 num_s2m_rings
Definition: private.h:155
VLIB_PLUGIN_REGISTER()
clib_error_t * vlib_unix_recursive_mkdir(char *path)
Definition: util.c:102
unsigned short u16
Definition: types.h:57
static_always_inline memif_ring_t * memif_get_ring(memif_if_t *mif, memif_ring_type_t type, u16 ring_num)
Definition: memif.c:252
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
#define MEMIF_DEFAULT_SOCKET_FILENAME
Definition: private.h:20
#define CLIB_SOCKET_F_PASSCRED
Definition: socket.h:64
a point 2 point interface
Definition: interface.h:289
void memif_socket_close(clib_socket_t **sock)
Definition: socket.c:43
#define clib_error_free(e)
Definition: error.h:86
void * shm
Definition: private.h:82
u8 * remote_if_name
Definition: private.h:150
memif_interface_id_t id
Definition: private.h:129
memif_log2_ring_size_t log2_ring_size
Definition: private.h:97
int vnet_hw_interface_unassign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.c:187
static u32 random_u32(u32 *seed)
32-bit random number generator
Definition: random.h:69
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
uint16_t flags
Definition: memif.h:168
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
static vlib_node_registration_t memif_process_node
(constructor) VLIB_REGISTER_NODE (memif_process_node)
Definition: memif.c:458
u8 * remote_disc_string
Definition: private.h:170
memif_ring_type_t
Definition: memif.h:47
#define vec_foreach(var, vec)
Vector iterator.
volatile uint16_t head
Definition: memif.h:170
uword private_data
Definition: file.h:60
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: interface.c:546
Definition: file.h:50
clib_socket_t * sock
Definition: private.h:138
memif_queue_t * rx_queues
Definition: private.h:145
int vnet_hw_interface_set_rx_mode(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, vnet_hw_interface_rx_mode mode)
Definition: devices.c:252
clib_error_t * memif_conn_fd_accept_ready(clib_file_t *uf)
Definition: socket.c:628
u32 flags
Definition: vhost-user.h:77
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
#define CLIB_SOCKET_F_ALLOW_GROUP_WRITE
Definition: socket.h:62
memif_msg_fifo_elt_t * msg_queue
Definition: private.h:140
memif_main_t memif_main
Definition: memif.c:43
memif_region_index_t region
Definition: private.h:98
clib_socket_t * sock
Definition: private.h:68
#define MEMIF_COOKIE
Definition: memif.h:25
u32 sw_if_index
Definition: private.h:131
static void vnet_hw_interface_set_input_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: devices.h:79
volatile uint16_t tail
Definition: memif.h:172
memif_interface_mode_t mode
Definition: private.h:133
static uword memif_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: memif.c:363
memif_region_size_t region_size
Definition: private.h:83
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128