FD.io VPP  v17.10-9-gd594711
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->conn_fd > -1)
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->conn_clib_file_index != ~0)
98  {
100  mif->socket_file_index);
103  mif->conn_clib_file_index = ~0;
104  }
105  else if (mif->conn_fd > -1)
106  close (mif->conn_fd);
107  mif->conn_fd = -1;
108 
109  vec_foreach_index (i, mif->rx_queues)
110  {
111  mq = vec_elt_at_index (mif->rx_queues, i);
112  if (mq->ring)
113  {
114  int rv;
116  if (rv)
117  DBG ("Warning: unable to unassign interface %d, "
118  "queue %d: rc=%d", mif->hw_if_index, i, rv);
119  mq->ring = 0;
120  }
121  }
122 
123  /* free tx and rx queues */
125  vec_free (mif->rx_queues);
126 
128  vec_free (mif->tx_queues);
129 
130  /* free memory regions */
131  vec_foreach (mr, mif->regions)
132  {
133  int rv;
134  if ((rv = munmap (mr->shm, mr->region_size)))
135  clib_warning ("munmap failed, rv = %d", rv);
136  if (mr->fd > -1)
137  close (mr->fd);
138  }
139  vec_free (mif->regions);
140 
141  mif->remote_pid = 0;
142  vec_free (mif->remote_name);
143  vec_free (mif->remote_if_name);
144  clib_fifo_free (mif->msg_queue);
145 }
146 
147 static clib_error_t *
149 {
150  memif_main_t *mm = &memif_main;
151  vnet_main_t *vnm = vnet_get_main ();
152  u16 qid = uf->private_data & 0xFFFF;
153  memif_if_t *mif = vec_elt_at_index (mm->interfaces, uf->private_data >> 16);
154  memif_queue_t *mq = vec_elt_at_index (mif->rx_queues, qid);
155  u64 b;
156  ssize_t size;
157 
158  size = read (uf->file_descriptor, &b, sizeof (b));
159  if (size < 0)
160  {
161  DBG_UNIX_LOG ("Failed to read from socket");
162  return 0;
163  }
164 
166  mq->int_count++;
167 
168  return 0;
169 }
170 
171 
172 clib_error_t *
174 {
175  vnet_main_t *vnm = vnet_get_main ();
176  clib_file_t template = { 0 };
177  memif_region_t *mr;
178  int i;
179 
180  DBG ("connect %u", mif->dev_instance);
181 
184 
185  vec_foreach (mr, mif->regions)
186  {
187  if (mr->shm)
188  continue;
189 
190  if (mr->fd < 0)
191  clib_error_return (0, "no memory region fd");
192 
193  if ((mr->shm = mmap (NULL, mr->region_size, PROT_READ | PROT_WRITE,
194  MAP_SHARED, mr->fd, 0)) == MAP_FAILED)
195  return clib_error_return_unix (0, "mmap");
196  }
197 
198  template.read_function = memif_int_fd_read_ready;
199 
200  vec_foreach_index (i, mif->tx_queues)
201  {
202  memif_queue_t *mq = vec_elt_at_index (mif->tx_queues, i);
203 
204  mq->ring = mif->regions[mq->region].shm + mq->offset;
205  if (mq->ring->cookie != MEMIF_COOKIE)
206  return clib_error_return (0, "wrong cookie on tx ring %u", i);
207  }
208 
209  vec_foreach_index (i, mif->rx_queues)
210  {
211  memif_queue_t *mq = vec_elt_at_index (mif->rx_queues, i);
212  int rv;
213 
214  mq->ring = mif->regions[mq->region].shm + mq->offset;
215  if (mq->ring->cookie != MEMIF_COOKIE)
216  return clib_error_return (0, "wrong cookie on tx ring %u", i);
217 
218  if (mq->int_fd > -1)
219  {
220  template.file_descriptor = mq->int_fd;
221  template.private_data = (mif->dev_instance << 16) | (i & 0xFFFF);
222  memif_file_add (&mq->int_clib_file_index, &template);
223  }
225  rv = vnet_hw_interface_set_rx_mode (vnm, mif->hw_if_index, i,
227  if (rv)
229  ("Warning: unable to set rx mode for interface %d queue %d: "
230  "rc=%d", mif->hw_if_index, i, rv);
231  else
232  {
234  vnet_hw_interface_get_rx_mode (vnm, mif->hw_if_index, i, &rxmode);
235 
236  if (rxmode == VNET_HW_INTERFACE_RX_MODE_POLLING)
238  }
239  }
240 
241  mif->flags &= ~MEMIF_IF_FLAG_CONNECTING;
242  mif->flags |= MEMIF_IF_FLAG_CONNECTED;
243 
246  return 0;
247 }
248 
251 {
252  if (vec_len (mif->regions) == 0)
253  return NULL;
254  void *p = mif->regions[0].shm;
255  int ring_size =
256  sizeof (memif_ring_t) +
257  sizeof (memif_desc_t) * (1 << mif->run.log2_ring_size);
258  p += (ring_num + type * mif->run.num_s2m_rings) * ring_size;
259 
260  return (memif_ring_t *) p;
261 }
262 
263 clib_error_t *
265 {
266  memif_ring_t *ring = NULL;
267  int i, j;
268  u64 buffer_offset;
269  memif_region_t *r;
270  clib_mem_vm_alloc_t alloc = { 0 };
271  clib_error_t *err;
272 
274  r = vec_elt_at_index (mif->regions, 0);
275 
276  buffer_offset = (mif->run.num_s2m_rings + mif->run.num_m2s_rings) *
277  (sizeof (memif_ring_t) +
278  sizeof (memif_desc_t) * (1 << mif->run.log2_ring_size));
279 
280  r->region_size = buffer_offset +
281  mif->run.buffer_size * (1 << mif->run.log2_ring_size) *
282  (mif->run.num_s2m_rings + mif->run.num_m2s_rings);
283 
284  alloc.name = "memif region";
285  alloc.size = r->region_size;
286  alloc.flags = CLIB_MEM_VM_F_SHARED;
287 
288  err = clib_mem_vm_ext_alloc (&alloc);
289  if (err)
290  return err;
291 
292  r->fd = alloc.fd;
293  r->shm = alloc.addr;
294 
295  for (i = 0; i < mif->run.num_s2m_rings; i++)
296  {
297  ring = memif_get_ring (mif, MEMIF_RING_S2M, i);
298  ring->head = ring->tail = 0;
299  ring->cookie = MEMIF_COOKIE;
300  for (j = 0; j < (1 << mif->run.log2_ring_size); j++)
301  {
302  u16 slot = i * (1 << mif->run.log2_ring_size) + j;
303  ring->desc[j].region = 0;
304  ring->desc[j].offset =
305  buffer_offset + (u32) (slot * mif->run.buffer_size);
306  ring->desc[j].buffer_length = mif->run.buffer_size;
307  }
308  }
309  for (i = 0; i < mif->run.num_m2s_rings; i++)
310  {
311  ring = memif_get_ring (mif, MEMIF_RING_M2S, i);
312  ring->head = ring->tail = 0;
313  ring->cookie = MEMIF_COOKIE;
314  for (j = 0; j < (1 << mif->run.log2_ring_size); j++)
315  {
316  u16 slot =
317  (i + mif->run.num_s2m_rings) * (1 << mif->run.log2_ring_size) + j;
318  ring->desc[j].region = 0;
319  ring->desc[j].offset =
320  buffer_offset + (u32) (slot * mif->run.buffer_size);
321  ring->desc[j].buffer_length = mif->run.buffer_size;
322  }
323  }
324 
325  ASSERT (mif->tx_queues == 0);
328  vec_foreach_index (i, mif->tx_queues)
329  {
330  memif_queue_t *mq = vec_elt_at_index (mif->tx_queues, i);
331  if ((mq->int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
332  return clib_error_return_unix (0, "eventfd[tx queue %u]", i);
333  mq->int_clib_file_index = ~0;
334  mq->ring = memif_get_ring (mif, MEMIF_RING_S2M, i);
335  mq->log2_ring_size = mif->cfg.log2_ring_size;
336  mq->region = 0;
337  mq->offset = (void *) mq->ring - (void *) mif->regions[mq->region].shm;
338  mq->last_head = 0;
339  }
340 
341  ASSERT (mif->rx_queues == 0);
344  vec_foreach_index (i, mif->rx_queues)
345  {
346  memif_queue_t *mq = vec_elt_at_index (mif->rx_queues, i);
347  if ((mq->int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
348  return clib_error_return_unix (0, "eventfd[rx queue %u]", i);
349  mq->int_clib_file_index = ~0;
350  mq->ring = memif_get_ring (mif, MEMIF_RING_M2S, i);
351  mq->log2_ring_size = mif->cfg.log2_ring_size;
352  mq->region = 0;
353  mq->offset = (void *) mq->ring - (void *) mif->regions[mq->region].shm;
354  mq->last_head = 0;
355  }
356 
357  return 0;
358 }
359 
360 static uword
362 {
363  memif_main_t *mm = &memif_main;
364  memif_if_t *mif;
365  struct sockaddr_un sun;
366  int sockfd;
367  uword *event_data = 0, event_type;
368  u8 enabled = 0;
369  f64 start_time, last_run_duration = 0, now;
370 
371  sockfd = socket (AF_UNIX, SOCK_SEQPACKET, 0);
372  if (sockfd < 0)
373  {
374  DBG_UNIX_LOG ("socket AF_UNIX");
375  return 0;
376  }
377  sun.sun_family = AF_UNIX;
378 
379  while (1)
380  {
381  if (enabled)
383  last_run_duration);
384  else
386 
387  event_type = vlib_process_get_events (vm, &event_data);
388  vec_reset_length (event_data);
389 
390  switch (event_type)
391  {
392  case ~0:
393  break;
395  enabled = 1;
396  break;
398  enabled = 0;
399  continue;
400  default:
401  ASSERT (0);
402  }
403 
404  last_run_duration = start_time = vlib_time_now (vm);
405  /* *INDENT-OFF* */
406  pool_foreach (mif, mm->interfaces,
407  ({
408  memif_socket_file_t * msf = vec_elt_at_index (mm->socket_files, mif->socket_file_index);
409  /* Allow no more than 10us without a pause */
410  now = vlib_time_now (vm);
411  if (now > start_time + 10e-6)
412  {
413  vlib_process_suspend (vm, 100e-6); /* suspend for 100 us */
414  start_time = vlib_time_now (vm);
415  }
416 
417  if ((mif->flags & MEMIF_IF_FLAG_ADMIN_UP) == 0)
418  continue;
419 
420  if (mif->flags & MEMIF_IF_FLAG_CONNECTING)
421  continue;
422 
423  if (mif->flags & MEMIF_IF_FLAG_CONNECTED)
424  continue;
425 
426  if (mif->flags & MEMIF_IF_FLAG_IS_SLAVE)
427  {
428  strncpy (sun.sun_path, (char *) msf->filename,
429  sizeof (sun.sun_path) - 1);
430 
431  if (connect
432  (sockfd, (struct sockaddr *) &sun,
433  sizeof (struct sockaddr_un)) == 0)
434  {
435  clib_file_t t = { 0 };
436 
437  mif->conn_fd = sockfd;
438  t.read_function = memif_slave_conn_fd_read_ready;
439  t.write_function = memif_slave_conn_fd_write_ready;
440  t.error_function = memif_slave_conn_fd_error;
441  t.file_descriptor = mif->conn_fd;
442  t.private_data = mif->dev_instance;
443  memif_file_add (&mif->conn_clib_file_index, &t);
444  hash_set (msf->dev_instance_by_fd, mif->conn_fd, mif->dev_instance);
445 
446  mif->flags |= MEMIF_IF_FLAG_CONNECTING;
447 
448  /* grab another fd */
449  sockfd = socket (AF_UNIX, SOCK_SEQPACKET, 0);
450  if (sockfd < 0)
451  {
452  DBG_UNIX_LOG ("socket AF_UNIX");
453  return 0;
454  }
455  }
456  }
457  }));
458  /* *INDENT-ON* */
459  last_run_duration = vlib_time_now (vm) - last_run_duration;
460  }
461  return 0;
462 }
463 
464 /* *INDENT-OFF* */
466  .function = memif_process,
467  .type = VLIB_NODE_TYPE_PROCESS,
468  .name = "memif-process",
469 };
470 /* *INDENT-ON* */
471 
472 int
474 {
475  vnet_main_t *vnm = vnet_get_main ();
476  memif_main_t *mm = &memif_main;
477  memif_socket_file_t *msf =
479  clib_error_t *err;
480 
481  mif->flags |= MEMIF_IF_FLAG_DELETING;
484 
485  /* bring down the interface */
488 
489  err = clib_error_return (0, "interface deleted");
490  memif_disconnect (mif, err);
491  clib_error_free (err);
492 
493  /* remove the interface */
494  if (mif->mode == MEMIF_INTERFACE_MODE_IP)
496  else
498  mif->hw_if_index = ~0;
499 
500  /* free interface data structures */
501  clib_spinlock_free (&mif->lockp);
502  mhash_unset (&msf->dev_instance_by_id, &mif->id, 0);
503 
504  /* remove socket file */
505  if (--(msf->ref_cnt) == 0)
506  {
507  if (msf->is_listener)
508  {
509  uword *x;
512  {
514  }
516  }
520  vec_free (msf->filename);
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->fd = -1;
629  msf->is_listener = (args->is_master != 0);
630  socket_filename = 0;
632  msf - mm->socket_files, 0);
633  DBG ("creating socket file %s", msf->filename);
634  }
635 
636  pool_get (mm->interfaces, mif);
637  memset (mif, 0, sizeof (*mif));
638  mif->dev_instance = mif - mm->interfaces;
639  mif->socket_file_index = msf - mm->socket_files;
640  mif->id = args->id;
641  mif->sw_if_index = mif->hw_if_index = mif->per_interface_next_index = ~0;
642  mif->conn_clib_file_index = ~0;
643  mif->conn_fd = -1;
644  mif->mode = args->mode;
645  if (args->secret)
646  mif->secret = vec_dup (args->secret);
647 
648  if (tm->n_vlib_mains > 1)
649  clib_spinlock_init (&mif->lockp);
650 
651 
653  {
654 
655  if (!args->hw_addr_set)
656  {
657  f64 now = vlib_time_now (vm);
658  u32 rnd;
659  rnd = (u32) (now * 1e6);
660  rnd = random_u32 (&rnd);
661 
662  memcpy (args->hw_addr + 2, &rnd, sizeof (rnd));
663  args->hw_addr[0] = 2;
664  args->hw_addr[1] = 0xfe;
665  }
667  mif->dev_instance, args->hw_addr,
668  &mif->hw_if_index,
670  }
671  else if (mif->mode == MEMIF_INTERFACE_MODE_IP)
672  {
673  mif->hw_if_index =
675  mif->dev_instance,
676  memif_ip_hw_if_class.index,
677  mif->dev_instance);
678  }
679  else
680  error = clib_error_return (0, "unsupported interface mode");
681 
682  if (error)
683  {
684  clib_error_report (error);
685  ret = VNET_API_ERROR_SYSCALL_ERROR_2;
686  goto error;
687  }
688 
689  sw = vnet_get_hw_sw_interface (vnm, mif->hw_if_index);
690  mif->sw_if_index = sw->sw_if_index;
691 
692  mif->cfg.log2_ring_size = args->log2_ring_size;
693  mif->cfg.buffer_size = args->buffer_size;
694  mif->cfg.num_s2m_rings =
695  args->is_master ? args->rx_queues : args->tx_queues;
696  mif->cfg.num_m2s_rings =
697  args->is_master ? args->tx_queues : args->rx_queues;
698 
699  args->sw_if_index = mif->sw_if_index;
700 
701  /* If this is new one, start listening */
702  if (msf->is_listener && msf->ref_cnt == 0)
703  {
704  struct sockaddr_un un = { 0 };
705  struct stat file_stat;
706  int on = 1;
707 
708  if ((msf->fd = socket (AF_UNIX, SOCK_SEQPACKET, 0)) < 0)
709  {
710  ret = VNET_API_ERROR_SYSCALL_ERROR_4;
711  goto error;
712  }
713 
714  un.sun_family = AF_UNIX;
715  strncpy ((char *) un.sun_path, (char *) msf->filename,
716  sizeof (un.sun_path) - 1);
717 
718  if (setsockopt (msf->fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on)) < 0)
719  {
720  ret = VNET_API_ERROR_SYSCALL_ERROR_5;
721  goto error;
722  }
723  if (bind (msf->fd, (struct sockaddr *) &un, sizeof (un)) == -1)
724  {
725  ret = VNET_API_ERROR_SYSCALL_ERROR_6;
726  goto error;
727  }
728  if (listen (msf->fd, 1) == -1)
729  {
730  ret = VNET_API_ERROR_SYSCALL_ERROR_7;
731  goto error;
732  }
733 
734  if (stat ((char *) msf->filename, &file_stat) == -1)
735  {
736  ret = VNET_API_ERROR_SYSCALL_ERROR_8;
737  goto error;
738  }
739 
740  msf->clib_file_index = ~0;
741  clib_file_t template = { 0 };
743  template.file_descriptor = msf->fd;
744  template.private_data = mif->socket_file_index;
745  memif_file_add (&msf->clib_file_index, &template);
746  }
747 
748  msf->ref_cnt++;
749 
750  if (args->is_master == 0)
751  mif->flags |= MEMIF_IF_FLAG_IS_SLAVE;
752 
753  hw = vnet_get_hw_interface (vnm, mif->hw_if_index);
756  memif_input_node.index);
757 
758  mhash_set (&msf->dev_instance_by_id, &mif->id, mif->dev_instance, 0);
759 
760  if (pool_elts (mm->interfaces) == 1)
761  {
764  }
765  goto done;
766 
767 error:
768  if (mif->hw_if_index != ~0)
769  {
770  if (mif->mode == MEMIF_INTERFACE_MODE_IP)
772  else
774  mif->hw_if_index = ~0;
775  }
776  memif_delete_if (vm, mif);
777  return ret;
778 
779 done:
780  vec_free (socket_filename);
781  return rv;
782 }
783 
784 
785 static clib_error_t *
787 {
788  memif_main_t *mm = &memif_main;
790 
791  memset (mm, 0, sizeof (memif_main_t));
792 
793  /* initialize binary API */
795 
797 
800 
801  return 0;
802 }
803 
805 
806 /* *INDENT-OFF* */
808  .version = VPP_BUILD_VER,
809  .description = "Packet Memory Interface (experimetal)",
810 };
811 /* *INDENT-ON* */
812 
813 /*
814  * fd.io coding-style-patch-verification: ON
815  *
816  * Local Variables:
817  * eval: (c-set-style "gnu")
818  * End:
819  */
#define DBG_UNIX_LOG(...)
memif_if_t * interfaces
Definition: private.h:188
vmrglw vmrglh hi
#define vec_foreach_index(var, v)
Iterate over vector indices.
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:145
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
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
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
#define NULL
Definition: clib.h:55
uword mhash_unset(mhash_t *h, void *key, uword *old_value)
Definition: mhash.c:353
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:221
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:786
clib_error_t * memif_msg_send_disconnect(memif_if_t *mif, clib_error_t *err)
Definition: socket.c:213
memif_interface_mode_t mode
Definition: private.h:215
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:163
#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:64
#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)
struct memif_if_t::@337 cfg
vnet_hw_interface_rx_mode
Definition: interface.h:51
#define static_always_inline
Definition: clib.h:85
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:437
u8 * remote_name
Definition: private.h:156
#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:141
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:264
static_always_inline void vnet_device_input_set_interrupt_pending(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.h:135
u16 buffer_size
Definition: private.h:164
memif_log2_ring_size_t log2_ring_size
Definition: private.h:216
#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:138
#define clib_error_return(e, args...)
Definition: error.h:99
memif_region_offset_t offset
Definition: private.h:102
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:59
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:77
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:104
vlib_node_registration_t memif_input_node
(constructor) VLIB_REGISTER_NODE (memif_input_node)
Definition: node.c:512
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:473
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:135
clib_spinlock_t lockp
Definition: private.h:130
#define clib_error_return_unix(e, args...)
Definition: error.h:102
pid_t remote_pid
Definition: private.h:153
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:302
#define hash_free(h)
Definition: hash.h:286
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:270
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:370
memif_interface_id_t id
Definition: private.h:211
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:109
#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:150
clib_error_t * memif_connect(memif_if_t *mif)
Definition: memif.c:173
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:176
#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:147
#define hash_create(elts, value_bytes)
Definition: hash.h:658
u32 ** rx_buffers
Definition: private.h:195
#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:128
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:148
u32 flags
Definition: private.h:131
memif_ring_t * ring
Definition: private.h:99
u64 size
Definition: vhost-user.h:76
int conn_fd
Definition: private.h:142
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:133
uword conn_clib_file_index
Definition: private.h:143
#define clib_fifo_free(f)
Definition: fifo.h:257
#define MEMIF_RING_FLAG_MASK_INT
Definition: memif.h:169
u64 int_count
Definition: private.h:110
void vnet_delete_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface.c:894
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
struct memif_if_t::@338 run
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:250
#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
a point 2 point interface
Definition: interface.h:289
#define clib_error_free(e)
Definition: error.h:86
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
memif_log2_ring_size_t log2_ring_size
Definition: private.h:100
int vnet_hw_interface_unassign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.c:177
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:465
u8 * remote_disc_string
Definition: private.h:177
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
memif_queue_t * rx_queues
Definition: private.h:149
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:242
clib_error_t * memif_conn_fd_accept_ready(clib_file_t *uf)
Definition: socket.c:694
uword * pending_file_indices
Definition: private.h:72
u32 flags
Definition: vhost-user.h:77
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
memif_msg_fifo_elt_t * msg_queue
Definition: private.h:144
memif_main_t memif_main
Definition: memif.c:43
memif_region_index_t region
Definition: private.h:101
#define MEMIF_COOKIE
Definition: memif.h:25
u32 sw_if_index
Definition: private.h:134
static void vnet_hw_interface_set_input_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: devices.h:78
volatile uint16_t tail
Definition: memif.h:172
memif_interface_mode_t mode
Definition: private.h:136
static uword memif_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: memif.c:361
memif_region_size_t region_size
Definition: private.h:86
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128