FD.io VPP  v17.10-9-gd594711
Vector Packet Processing
socket.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2016 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 #define _GNU_SOURCE
19 #include <stdint.h>
20 #include <net/if.h>
21 #include <sys/types.h>
22 #include <fcntl.h>
23 #include <sys/ioctl.h>
24 #include <sys/socket.h>
25 #include <sys/un.h>
26 #include <sys/uio.h>
27 #include <sys/mman.h>
28 #include <sys/prctl.h>
29 #include <sys/eventfd.h>
30 #include <inttypes.h>
31 #include <limits.h>
32 
33 #include <vlib/vlib.h>
34 #include <vlib/unix/unix.h>
35 #include <vnet/plugin/plugin.h>
36 #include <vnet/ethernet/ethernet.h>
37 #include <vpp/app/version.h>
38 
39 #include <memif/memif.h>
40 #include <memif/private.h>
41 
42 static u8 *
43 memif_str2vec (uint8_t * str, int len)
44 {
45  u8 *s = 0;
46  int i;
47 
48  if (str[0] == 0)
49  return s;
50 
51  for (i = 0; i < len; i++)
52  {
53  vec_add1 (s, str[i]);
54  if (str[i] == 0)
55  return s;
56  }
57  vec_add1 (s, 0);
58 
59  return s;
60 }
61 
62 static clib_error_t *
63 memif_msg_send (int fd, memif_msg_t * msg, int afd)
64 {
65  struct msghdr mh = { 0 };
66  struct iovec iov[1];
67  char ctl[CMSG_SPACE (sizeof (int))];
68  int rv;
69 
70  iov[0].iov_base = (void *) msg;
71  iov[0].iov_len = sizeof (memif_msg_t);
72  mh.msg_iov = iov;
73  mh.msg_iovlen = 1;
74 
75  if (afd > 0)
76  {
77  struct cmsghdr *cmsg;
78  memset (&ctl, 0, sizeof (ctl));
79  mh.msg_control = ctl;
80  mh.msg_controllen = sizeof (ctl);
81  cmsg = CMSG_FIRSTHDR (&mh);
82  cmsg->cmsg_len = CMSG_LEN (sizeof (int));
83  cmsg->cmsg_level = SOL_SOCKET;
84  cmsg->cmsg_type = SCM_RIGHTS;
85  memcpy (CMSG_DATA (cmsg), &afd, sizeof (int));
86  }
87  rv = sendmsg (fd, &mh, 0);
88  if (rv < 0)
89  return clib_error_return_unix (0, "sendmsg");
90  DBG ("Message type %u sent (fd %d)", msg->type, afd);
91  return 0;
92 }
93 
94 static void
96 {
98  clib_fifo_add2 (mif->msg_queue, e);
99 
101  e->fd = -1;
102 }
103 
104 static clib_error_t *
106 {
107  u8 *s;
108  memif_msg_t msg = { 0 };
109  memif_msg_hello_t *h = &msg.hello;
117  s = format (0, "VPP %s%c", VPP_BUILD_VER, 0);
118  strncpy ((char *) h->name, (char *) s, sizeof (h->name) - 1);
119  vec_free (s);
120  return memif_msg_send (fd, &msg, -1);
121 }
122 
123 static void
125 {
126  u8 *s;
128  clib_fifo_add2 (mif->msg_queue, e);
129  memif_msg_init_t *i = &e->msg.init;
130 
132  e->fd = -1;
133  i->version = MEMIF_VERSION;
134  i->id = mif->id;
135  i->mode = mif->mode;
136  s = format (0, "VPP %s%c", VPP_BUILD_VER, 0);
137  strncpy ((char *) i->name, (char *) s, sizeof (i->name) - 1);
138  if (mif->secret)
139  strncpy ((char *) i->secret, (char *) mif->secret,
140  sizeof (i->secret) - 1);
141  vec_free (s);
142 }
143 
144 static void
146 {
148  clib_fifo_add2 (mif->msg_queue, e);
150 
152  e->fd = mif->regions[region].fd;
153  ar->index = region;
154  ar->size = mif->regions[region].region_size;
155 }
156 
157 static void
158 memif_msg_enq_add_ring (memif_if_t * mif, u8 index, u8 direction)
159 {
161  clib_fifo_add2 (mif->msg_queue, e);
163  memif_queue_t *mq;
164 
165  ASSERT ((mif->flags & MEMIF_IF_FLAG_IS_SLAVE) != 0);
166 
168 
169  if (direction == MEMIF_RING_M2S)
170  mq = vec_elt_at_index (mif->rx_queues, index);
171  else
172  mq = vec_elt_at_index (mif->tx_queues, index);
173 
174  e->fd = mq->int_fd;
175  ar->index = index;
176  ar->region = mq->region;
177  ar->offset = mq->offset;
178  ar->log2_ring_size = mq->log2_ring_size;
179  ar->flags = (direction == MEMIF_RING_S2M) ? MEMIF_MSG_ADD_RING_FLAG_S2M : 0;
180 }
181 
182 static void
184 {
186  clib_fifo_add2 (mif->msg_queue, e);
188  u8 *s;
189 
191  e->fd = -1;
192  s = format (0, "%U%c", format_memif_device_name, mif->dev_instance, 0);
193  strncpy ((char *) c->if_name, (char *) s, sizeof (c->if_name) - 1);
194  vec_free (s);
195 }
196 
197 static void
199 {
201  clib_fifo_add2 (mif->msg_queue, e);
203  u8 *s;
204 
206  e->fd = -1;
207  s = format (0, "%U%c", format_memif_device_name, mif->dev_instance, 0);
208  strncpy ((char *) c->if_name, (char *) s, sizeof (c->if_name) - 1);
209  vec_free (s);
210 }
211 
212 clib_error_t *
214 {
215  memif_msg_t msg = { 0 };
218 
219  d->code = err->code;
220  strncpy ((char *) d->string, (char *) err->what, sizeof (d->string) - 1);
221 
222  return memif_msg_send (mif->conn_fd, &msg, -1);
223 }
224 
225 static clib_error_t *
227 {
228  memif_msg_hello_t *h = &msg->hello;
229 
230  if (msg->hello.min_version > MEMIF_VERSION ||
232  return clib_error_return (0, "incompatible protocol version");
233 
234  mif->run.num_s2m_rings = clib_min (h->max_s2m_ring + 1,
235  mif->cfg.num_s2m_rings);
236  mif->run.num_m2s_rings = clib_min (h->max_m2s_ring + 1,
237  mif->cfg.num_m2s_rings);
239  mif->cfg.log2_ring_size);
240  mif->run.buffer_size = mif->cfg.buffer_size;
241 
242  mif->remote_name = memif_str2vec (h->name, sizeof (h->name));
243 
244  return 0;
245 }
246 
247 static clib_error_t *
249  clib_file_t * uf)
250 {
251  memif_main_t *mm = &memif_main;
252  memif_socket_file_t *msf =
254  memif_msg_init_t *i = &msg->init;
255  memif_if_t *mif, tmp;
256  clib_error_t *err;
257  uword *p;
258 
259  if (i->version != MEMIF_VERSION)
260  {
262  return clib_error_return (0, "unsupported version");
263  }
264 
265  p = mhash_get (&msf->dev_instance_by_id, &i->id);
266 
267  if (!p)
268  {
269  err = clib_error_return (0, "unmatched interface id");
270  goto error;
271  }
272 
273  mif = vec_elt_at_index (mm->interfaces, p[0]);
274 
275  if (mif->flags & MEMIF_IF_FLAG_IS_SLAVE)
276  {
277  err = clib_error_return (0, "cannot connect to slave");
278  goto error;
279  }
280 
281  if (mif->conn_fd != -1)
282  {
283  err = clib_error_return (0, "already connected");
284  goto error;
285  }
286 
287  if (i->mode != mif->mode)
288  {
289  err = clib_error_return (0, "mode mismatch");
290  goto error;
291  }
292 
293  mif->conn_fd = uf->file_descriptor;
295  hash_set (msf->dev_instance_by_fd, mif->conn_fd, mif->dev_instance);
296  mif->remote_name = memif_str2vec (i->name, sizeof (i->name));
297  *mifp = mif;
298 
299  if (mif->secret)
300  {
301  u8 *s;
302  int r;
303  s = memif_str2vec (i->secret, sizeof (i->secret));
304  if (s == 0)
305  return clib_error_return (0, "secret required");
306 
307  r = vec_cmp (s, mif->secret);
308  vec_free (s);
309 
310  if (r)
311  return clib_error_return (0, "incorrect secret");
312  }
313 
314  return 0;
315 
316 error:
317  tmp.conn_fd = uf->file_descriptor;
318  memif_msg_send_disconnect (&tmp, err);
320  return err;
321 }
322 
323 static clib_error_t *
325 {
327  memif_region_t *mr;
328  if (fd < 0)
329  return clib_error_return (0, "missing memory region fd");
330 
331  if (ar->index != vec_len (mif->regions))
332  return clib_error_return (0, "unexpected region index");
333 
334  if (ar->index > MEMIF_MAX_REGION)
335  return clib_error_return (0, "too many regions");
336 
338  mr = vec_elt_at_index (mif->regions, ar->index);
339  mr->fd = fd;
340  mr->region_size = ar->size;
341 
342  return 0;
343 }
344 
345 static clib_error_t *
347 {
348  memif_msg_add_ring_t *ar = &msg->add_ring;
349  memif_queue_t *mq;
350 
351  if (fd < 0)
352  return clib_error_return (0, "missing ring interrupt fd");
353 
355  {
356  if (ar->index != vec_len (mif->rx_queues))
357  return clib_error_return (0, "unexpected ring index");
358 
359  if (ar->index > MEMIF_MAX_S2M_RING)
360  return clib_error_return (0, "too many rings");
361 
363  mq = vec_elt_at_index (mif->rx_queues, ar->index);
364  mif->run.num_s2m_rings = vec_len (mif->rx_queues);
365  }
366  else
367  {
368  if (ar->index != vec_len (mif->tx_queues))
369  return clib_error_return (0, "unexpected ring index");
370 
371  if (ar->index > MEMIF_MAX_M2S_RING)
372  return clib_error_return (0, "too many rings");
373 
375  mq = vec_elt_at_index (mif->tx_queues, ar->index);
376  mif->run.num_m2s_rings = vec_len (mif->tx_queues);
377  }
378 
379  mq->int_fd = fd;
380  mq->int_clib_file_index = ~0;
381  mq->log2_ring_size = ar->log2_ring_size;
382  mq->region = ar->region;
383  mq->offset = ar->offset;
384 
385  return 0;
386 }
387 
388 static clib_error_t *
390 {
391  clib_error_t *err;
392  memif_msg_connect_t *c = &msg->connect;
393 
394  if ((err = memif_connect (mif)))
395  return err;
396 
397  mif->remote_if_name = memif_str2vec (c->if_name, sizeof (c->if_name));
398 
399  return 0;
400 }
401 
402 static clib_error_t *
404 {
405  clib_error_t *err;
407 
408  if ((err = memif_connect (mif)))
409  return err;
410 
411  mif->remote_if_name = memif_str2vec (c->if_name, sizeof (c->if_name));
412  return 0;
413 }
414 
415 static clib_error_t *
417 {
419 
420  mif->remote_disc_string = memif_str2vec (d->string, sizeof (d->string));
421  return clib_error_return (0, "disconnect received");
422 }
423 
424 static clib_error_t *
426 {
427  char ctl[CMSG_SPACE (sizeof (int)) +
428  CMSG_SPACE (sizeof (struct ucred))] = { 0 };
429  struct msghdr mh = { 0 };
430  struct iovec iov[1];
431  memif_msg_t msg = { 0 };
432  ssize_t size;
433  clib_error_t *err = 0;
434  int fd = -1;
435  int i;
436  memif_if_t *mif = *mifp;
437 
438  iov[0].iov_base = (void *) &msg;
439  iov[0].iov_len = sizeof (memif_msg_t);
440  mh.msg_iov = iov;
441  mh.msg_iovlen = 1;
442  mh.msg_control = ctl;
443  mh.msg_controllen = sizeof (ctl);
444 
445  /* receive the incoming message */
446  size = recvmsg (uf->file_descriptor, &mh, 0);
447  if (size != sizeof (memif_msg_t))
448  {
449  return (size == 0) ? clib_error_return (0, "disconnected") :
451  "recvmsg: malformed message received on fd %d",
452  uf->file_descriptor);
453  }
454 
455  if (mif == 0 && msg.type != MEMIF_MSG_TYPE_INIT)
456  {
457  memif_file_del (uf);
458  return clib_error_return (0, "unexpected message received");
459  }
460 
461  /* process anciliary data */
462  struct ucred *cr = 0;
463  struct cmsghdr *cmsg;
464 
465  cmsg = CMSG_FIRSTHDR (&mh);
466  while (cmsg)
467  {
468  if (cmsg->cmsg_level == SOL_SOCKET)
469  {
470  if (cmsg->cmsg_type == SCM_CREDENTIALS)
471  {
472  cr = (struct ucred *) CMSG_DATA (cmsg);
473  }
474  else if (cmsg->cmsg_type == SCM_RIGHTS)
475  {
476  int *fdp = (int *) CMSG_DATA (cmsg);
477  fd = *fdp;
478  }
479  }
480  cmsg = CMSG_NXTHDR (&mh, cmsg);
481  }
482 
483  DBG ("Message type %u received", msg.type);
484  /* process the message based on its type */
485  switch (msg.type)
486  {
487  case MEMIF_MSG_TYPE_ACK:
488  break;
489 
491  if ((err = memif_msg_receive_hello (mif, &msg)))
492  return err;
493  if ((err = memif_init_regions_and_queues (mif)))
494  return err;
495  memif_msg_enq_init (mif);
496  memif_msg_enq_add_region (mif, 0);
497  vec_foreach_index (i, mif->tx_queues)
499  vec_foreach_index (i, mif->rx_queues)
501  memif_msg_enq_connect (mif);
502  break;
503 
504  case MEMIF_MSG_TYPE_INIT:
505  if ((err = memif_msg_receive_init (mifp, &msg, uf)))
506  return err;
507  mif = *mifp;
508  mif->remote_pid = cr->pid;
509  mif->remote_uid = cr->uid;
510  mif->remote_gid = cr->gid;
511  memif_msg_enq_ack (mif);
512  break;
513 
515  if ((err = memif_msg_receive_add_region (mif, &msg, fd)))
516  return err;
517  memif_msg_enq_ack (mif);
518  break;
519 
521  if ((err = memif_msg_receive_add_ring (mif, &msg, fd)))
522  return err;
523  memif_msg_enq_ack (mif);
524  break;
525 
527  if ((err = memif_msg_receive_connect (mif, &msg)))
528  return err;
530  break;
531 
533  if ((err = memif_msg_receive_connected (mif, &msg)))
534  return err;
535  break;
536 
538  if ((err = memif_msg_receive_disconnect (mif, &msg)))
539  return err;
540  break;
541 
542  default:
543  err = clib_error_return (0, "unknown message type (0x%x)", msg.type);
544  return err;
545  }
546 
547  if (clib_fifo_elts (mif->msg_queue) && mif->conn_clib_file_index != ~0)
549  mif->conn_clib_file_index, 1);
550  return 0;
551 }
552 
553 clib_error_t *
555 {
556  memif_main_t *mm = &memif_main;
557  memif_socket_file_t *msf =
559  uword *p;
560  memif_if_t *mif = 0;
561  uword conn_clib_file_index = ~0;
562  clib_error_t *err = 0;
563 
565  if (p)
566  {
567  mif = vec_elt_at_index (mm->interfaces, p[0]);
568  }
569  else
570  {
571  /* This is new connection, remove index from pending vector */
572  int i;
574  if (msf->pending_file_indices[i] == uf - file_main.file_pool)
575  {
576  conn_clib_file_index = msf->pending_file_indices[i];
577  vec_del1 (msf->pending_file_indices, i);
578  break;
579  }
580  ASSERT (conn_clib_file_index != ~0);
581  }
582  err = memif_msg_receive (&mif, uf);
583  if (err)
584  {
585  memif_disconnect (mif, err);
586  clib_error_free (err);
587  }
588  return 0;
589 }
590 
591 clib_error_t *
593 {
594  memif_main_t *mm = &memif_main;
595  clib_error_t *err;
597  err = memif_msg_receive (&mif, uf);
598  if (err)
599  {
600  memif_disconnect (mif, err);
601  clib_error_free (err);
602  }
603  return 0;
604 }
605 
606 static clib_error_t *
608 {
610  clib_fifo_sub2 (mif->msg_queue, e);
612  mif->conn_clib_file_index, 0);
613  memif_msg_send (mif->conn_fd, &e->msg, e->fd);
614  return 0;
615 }
616 
617 clib_error_t *
619 {
620  memif_main_t *mm = &memif_main;
621  memif_socket_file_t *msf =
623  uword *p;
624  memif_if_t *mif;
625 
627  if (!p)
628  return 0;
629 
630  mif = vec_elt_at_index (mm->interfaces, p[0]);
631  return memif_conn_fd_write_ready (uf, mif);
632 }
633 
634 clib_error_t *
636 {
637  memif_main_t *mm = &memif_main;
639  return memif_conn_fd_write_ready (uf, mif);
640 }
641 
642 clib_error_t *
644 {
645  memif_main_t *mm = &memif_main;
647  clib_error_t *err;
648 
649  err = clib_error_return (0, "connection fd error");
650  memif_disconnect (mif, err);
651  clib_error_free (err);
652 
653  return 0;
654 }
655 
656 clib_error_t *
658 {
659  memif_main_t *mm = &memif_main;
660  memif_socket_file_t *msf =
662  uword *p;
663 
664 
666  if (p)
667  {
668  memif_if_t *mif;
669  clib_error_t *err;
670  mif = vec_elt_at_index (mm->interfaces, p[0]);
671  err = clib_error_return (0, "connection fd error");
672  memif_disconnect (mif, err);
673  clib_error_free (err);
674  }
675  else
676  {
677  int i;
679  if (msf->pending_file_indices[i] == uf - file_main.file_pool)
680  {
681  vec_del1 (msf->pending_file_indices, i);
682  memif_file_del (uf);
683  return 0;
684  }
685  }
686 
687  clib_warning ("Error on unknown file descriptor %d", uf->file_descriptor);
688  memif_file_del (uf);
689  return 0;
690 }
691 
692 
693 clib_error_t *
695 {
696  memif_main_t *mm = &memif_main;
697  memif_socket_file_t *msf =
699  int addr_len;
700  struct sockaddr_un client;
701  int conn_fd;
702  clib_file_t template = { 0 };
703  uword clib_file_index = ~0;
704  clib_error_t *err;
705 
706 
707  addr_len = sizeof (client);
708  conn_fd = accept (uf->file_descriptor,
709  (struct sockaddr *) &client, (socklen_t *) & addr_len);
710 
711  if (conn_fd < 0)
712  return clib_error_return_unix (0, "accept fd %d", uf->file_descriptor);
713 
714  template.read_function = memif_master_conn_fd_read_ready;
715  template.write_function = memif_master_conn_fd_write_ready;
716  template.error_function = memif_master_conn_fd_error;
717  template.file_descriptor = conn_fd;
718  template.private_data = uf->private_data;
719 
720  memif_file_add (&clib_file_index, &template);
721 
722  err = memif_msg_enq_hello (conn_fd);
723  if (err)
724  {
725  clib_error_report (err);
726  memif_file_del_by_index (clib_file_index);
727  }
728  else
729  vec_add1 (msf->pending_file_indices, clib_file_index);
730 
731  return 0;
732 }
733 
734 /*
735  * fd.io coding-style-patch-verification: ON
736  *
737  * Local Variables:
738  * eval: (c-set-style "gnu")
739  * End:
740  */
memif_if_t * interfaces
Definition: private.h:188
memif_version_t max_version
Definition: memif.h:76
memif_interface_mode_t mode
Definition: memif.h:87
static clib_error_t * memif_msg_receive_connect(memif_if_t *mif, memif_msg_t *msg)
Definition: socket.c:389
#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 * memif_master_conn_fd_error(clib_file_t *uf)
Definition: socket.c:657
#define clib_min(x, y)
Definition: clib.h:332
clib_error_t * memif_conn_fd_accept_ready(clib_file_t *uf)
Definition: socket.c:694
u8 * secret
Definition: private.h:145
#define clib_fifo_sub2(f, p)
Definition: fifo.h:232
memif_msg_add_region_t add_region
Definition: memif.h:131
clib_error_t * memif_slave_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:635
static uword clib_fifo_elts(void *v)
Definition: fifo.h:66
#define memif_file_del(a)
Definition: private.h:63
static clib_error_t * memif_msg_receive_connected(memif_if_t *mif, memif_msg_t *msg)
Definition: socket.c:403
uint8_t string[96]
Definition: memif.h:121
static clib_error_t * memif_msg_receive_add_ring(memif_if_t *mif, memif_msg_t *msg, int fd)
Definition: socket.c:346
memif_socket_file_t * socket_files
Definition: private.h:191
memif_log2_ring_size_t log2_ring_size
Definition: private.h:161
memif_msg_add_ring_t add_ring
Definition: memif.h:132
#define MEMIF_MSG_ADD_RING_FLAG_S2M
Definition: memif.h:101
#define MEMIF_MAX_REGION
Definition: private.h:28
u32 file_descriptor
Definition: file.h:53
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:518
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
memif_region_index_t region
Definition: memif.h:103
#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
static uword clib_file_set_data_available_to_write(clib_file_main_t *um, u32 clib_file_index, uword is_available)
Definition: file.h:111
memif_version_t min_version
Definition: memif.h:75
uint8_t secret[24]
Definition: memif.h:88
uid_t remote_uid
Definition: private.h:154
#define memif_file_del_by_index(a)
Definition: private.h:64
struct memif_if_t::@337 cfg
clib_file_t * file_pool
Definition: file.h:76
clib_error_t * memif_slave_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:592
memif_interface_id_t id
Definition: memif.h:86
uint8_t name[32]
Definition: memif.h:74
u8 * remote_name
Definition: private.h:156
static clib_error_t * memif_msg_enq_hello(int fd)
Definition: socket.c:105
static clib_error_t * memif_msg_send(int fd, memif_msg_t *msg, int afd)
Definition: socket.c:63
gid_t remote_gid
Definition: private.h:155
static clib_error_t * memif_msg_receive_hello(memif_if_t *mif, memif_msg_t *msg)
Definition: socket.c:226
static clib_error_t * memif_conn_fd_write_ready(clib_file_t *uf, memif_if_t *mif)
Definition: socket.c:607
memif_ring_index_t max_m2s_ring
Definition: memif.h:78
clib_error_t * memif_init_regions_and_queues(memif_if_t *mif)
Definition: memif.c:264
u16 buffer_size
Definition: private.h:164
static clib_error_t * memif_msg_receive_init(memif_if_t **mifp, memif_msg_t *msg, clib_file_t *uf)
Definition: socket.c:248
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
Definition: error.h:99
clib_file_main_t file_main
Definition: main.c:63
memif_region_offset_t offset
Definition: private.h:102
static void memif_msg_enq_add_region(memif_if_t *mif, u8 region)
Definition: socket.c:145
#define MEMIF_MAX_M2S_RING
Definition: private.h:26
memif_region_offset_t offset
Definition: memif.h:104
#define memif_file_add(a, b)
Definition: private.h:59
#define MEMIF_MAX_LOG2_RING_SIZE
Definition: private.h:29
mhash_t dev_instance_by_id
Definition: private.h:77
static void memif_msg_enq_init(memif_if_t *mif)
Definition: socket.c:124
clib_error_t * memif_slave_conn_fd_error(clib_file_t *uf)
Definition: socket.c:643
static u8 * memif_str2vec(uint8_t *str, int len)
Definition: socket.c:43
memif_msg_init_t init
Definition: memif.h:130
memif_ring_index_t index
Definition: memif.h:102
clib_error_t * memif_msg_send_disconnect(memif_if_t *mif, clib_error_t *err)
Definition: socket.c:213
#define hash_get(h, key)
Definition: hash.h:248
static void memif_msg_enq_connected(memif_if_t *mif)
Definition: socket.c:198
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:458
uword dev_instance
Definition: private.h:135
memif_msg_disconnect_t disconnect
Definition: memif.h:135
#define clib_error_return_unix(e, args...)
Definition: error.h:102
pid_t remote_pid
Definition: private.h:153
static clib_error_t * memif_msg_receive_disconnect(memif_if_t *mif, memif_msg_t *msg)
Definition: socket.c:416
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:801
uword int_clib_file_index
Definition: private.h:109
memif_msg_hello_t hello
Definition: memif.h:129
static void memif_msg_enq_add_ring(memif_if_t *mif, u8 index, u8 direction)
Definition: socket.c:158
memif_log2_ring_size_t max_log2_ring_size
Definition: memif.h:80
memif_queue_t * tx_queues
Definition: private.h:150
clib_error_t * memif_connect(memif_if_t *mif)
Definition: memif.c:173
uint8_t if_name[32]
Definition: memif.h:110
uint8_t name[32]
Definition: memif.h:89
svmdb_client_t * c
static void memif_msg_enq_ack(memif_if_t *mif)
Definition: socket.c:95
vec_header_t h
Definition: buffer.c:282
uint8_t if_name[32]
Definition: memif.h:115
#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(...)
memif_region_index_t index
Definition: memif.h:94
clib_error_t * memif_master_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:618
void memif_disconnect(memif_if_t *mif, clib_error_t *err)
Definition: memif.c:69
memif_log2_ring_size_t log2_ring_size
Definition: memif.h:105
memif_version_t version
Definition: memif.h:85
memif_region_t * regions
Definition: private.h:147
memif_ring_index_t max_s2m_ring
Definition: memif.h:79
#define ASSERT(truth)
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
memif_msg_t msg
Definition: private.h:92
memif_msg_connect_t connect
Definition: memif.h:133
#define MEMIF_VERSION
Definition: memif.h:28
u32 flags
Definition: private.h:131
u64 size
Definition: vhost-user.h:76
int conn_fd
Definition: private.h:142
#define clib_error_report(e)
Definition: error.h:113
#define vec_cmp(v1, v2)
Compare two vectors (only applicable to vectors of signed numbers).
Definition: vec.h:916
uword conn_clib_file_index
Definition: private.h:143
static clib_error_t * memif_msg_receive_add_region(memif_if_t *mif, memif_msg_t *msg, int fd)
Definition: socket.c:324
u64 uword
Definition: types.h:112
static void memif_msg_enq_connect(memif_if_t *mif)
Definition: socket.c:183
uword * dev_instance_by_fd
Definition: private.h:80
u8 num_s2m_rings
Definition: private.h:162
struct memif_if_t::@338 run
uint16_t flags
Definition: memif.h:100
#define MEMIF_MAX_S2M_RING
Definition: private.h:27
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
memif_region_size_t size
Definition: memif.h:95
memif_region_index_t max_region
Definition: memif.h:77
memif_msg_type_t type
Definition: memif.h:126
static clib_error_t * memif_msg_receive(memif_if_t **mifp, clib_file_t *uf)
Definition: socket.c:425
#define clib_error_free(e)
Definition: error.h:86
u8 * remote_if_name
Definition: private.h:157
clib_error_t * memif_master_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:554
memif_interface_id_t id
Definition: private.h:132
memif_log2_ring_size_t log2_ring_size
Definition: private.h:100
#define clib_fifo_add2(f, p)
Definition: fifo.h:200
memif_msg_connected_t connected
Definition: memif.h:134
u8 * remote_disc_string
Definition: private.h:177
uword private_data
Definition: file.h:60
Definition: file.h:50
memif_queue_t * rx_queues
Definition: private.h:149
uword * pending_file_indices
Definition: private.h:72
#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
memif_interface_mode_t mode
Definition: private.h:136
u8 * format_memif_device_name(u8 *s, va_list *args)
Definition: device.c:52
memif_region_size_t region_size
Definition: private.h:86