FD.io VPP  v17.10-9-gd594711
Vector Packet Processing
api_shared.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * api_shared.c - API message handling, common code for both clients
4  * and the vlib process itself.
5  *
6  *
7  * Copyright (c) 2009 Cisco and/or its affiliates.
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at:
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *------------------------------------------------------------------
20  */
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stddef.h>
25 #include <string.h>
26 #include <vppinfra/format.h>
27 #include <vppinfra/byte_order.h>
28 #include <vppinfra/error.h>
29 #include <vlib/vlib.h>
30 #include <vlib/unix/unix.h>
31 #include <vlibapi/api.h>
32 #include <vppinfra/elog.h>
33 
34 /* *INDENT-OFF* */
35 api_main_t api_main =
36  {
37  .region_name = "/unset",
38  .api_uid = -1,
39  .api_gid = -1,
40  };
41 /* *INDENT-ON* */
42 
43 void
45 {
46  api_main_t *am = &api_main;
47  am->missing_clients++;
48 }
49 
50 int
52 {
53  return (am->rx_trace && am->rx_trace->enabled);
54 }
55 
56 int
58 {
59  return (am->tx_trace && am->tx_trace->enabled);
60 }
61 
62 /*
63  * vl_msg_api_trace
64  */
65 void
67 {
68  u8 **this_trace;
69  u8 **old_trace;
70  u8 *msg_copy;
71  u32 length;
72  trace_cfg_t *cfgp;
73  u16 msg_id = ntohs (*((u16 *) msg));
74  msgbuf_t *header = (msgbuf_t *) (((u8 *) msg) - offsetof (msgbuf_t, data));
75 
76  cfgp = am->api_trace_cfg + msg_id;
77 
78  if (!cfgp || !cfgp->trace_enable)
79  return;
80 
81  msg_copy = 0;
82 
83  if (tp->nitems == 0)
84  {
85  clib_warning ("tp->nitems is 0");
86  return;
87  }
88 
89  if (vec_len (tp->traces) < tp->nitems)
90  {
91  vec_add1 (tp->traces, 0);
92  this_trace = tp->traces + vec_len (tp->traces) - 1;
93  }
94  else
95  {
96  tp->wrapped = 1;
97  old_trace = tp->traces + tp->curindex++;
98  if (tp->curindex == tp->nitems)
99  tp->curindex = 0;
100  vec_free (*old_trace);
101  this_trace = old_trace;
102  }
103 
104  length = clib_net_to_host_u32 (header->data_len);
105 
106  vec_validate (msg_copy, length - 1);
107  clib_memcpy (msg_copy, msg, length);
108  *this_trace = msg_copy;
109 }
110 
111 int
113  int onoff)
114 {
115  vl_api_trace_t *tp;
116  int rv;
117 
118  switch (which)
119  {
120  case VL_API_TRACE_TX:
121  tp = am->tx_trace;
122  if (tp == 0)
123  {
124  vl_msg_api_trace_configure (am, which, 1024);
125  tp = am->tx_trace;
126  }
127  break;
128 
129  case VL_API_TRACE_RX:
130  tp = am->rx_trace;
131  if (tp == 0)
132  {
133  vl_msg_api_trace_configure (am, which, 1024);
134  tp = am->rx_trace;
135  }
136  break;
137 
138  default:
139  /* duh? */
140  return -1;
141  }
142 
143  /* Configured? */
144  if (tp == 0 || tp->nitems == 0)
145  return -1;
146 
147  rv = tp->enabled;
148  tp->enabled = onoff;
149 
150  return rv;
151 }
152 
153 int
155 {
156  vl_api_trace_t *tp;
157  int i;
158 
159  switch (which)
160  {
161  case VL_API_TRACE_TX:
162  tp = am->tx_trace;
163  break;
164 
165  case VL_API_TRACE_RX:
166  tp = am->rx_trace;
167  break;
168 
169  default:
170  /* duh? */
171  return -1;
172  }
173 
174  /* Configured? */
175  if (!tp || tp->nitems == 0)
176  return -1;
177 
178  tp->curindex = 0;
179  tp->wrapped = 0;
180 
181  for (i = 0; i < vec_len (tp->traces); i++)
182  {
183  vec_free (tp->traces[i]);
184  }
185  vec_free (tp->traces);
186 
187  return 0;
188 }
189 
190 int
192 {
193  vl_api_trace_t *tp;
194  vl_api_trace_file_header_t fh;
195  int i;
196  u8 *msg;
197 
198  switch (which)
199  {
200  case VL_API_TRACE_TX:
201  tp = am->tx_trace;
202  break;
203 
204  case VL_API_TRACE_RX:
205  tp = am->rx_trace;
206  break;
207 
208  default:
209  /* duh? */
210  return -1;
211  }
212 
213  /* Configured, data present? */
214  if (tp == 0 || tp->nitems == 0 || vec_len (tp->traces) == 0)
215  return -1;
216 
217  /* "Dare to be stupid" check */
218  if (fp == 0)
219  {
220  return -2;
221  }
222 
223  /* Write the file header */
224  fh.nitems = vec_len (tp->traces);
225  fh.endian = tp->endian;
226  fh.wrapped = tp->wrapped;
227 
228  if (fwrite (&fh, sizeof (fh), 1, fp) != 1)
229  {
230  return (-10);
231  }
232 
233  /* No-wrap case */
234  if (tp->wrapped == 0)
235  {
236  /*
237  * Note: vec_len return 0 when fed a NULL pointer.
238  * Unfortunately, the static analysis tool doesn't
239  * figure it out, hence the suppressed warnings.
240  * What a great use of my time.
241  */
242  for (i = 0; i < vec_len (tp->traces); i++)
243  {
244  u32 msg_length;
245  /*sa_ignore NO_NULL_CHK */
246  msg = tp->traces[i];
247  /*
248  * This retarded check required to pass
249  * [sic] SA-checking.
250  */
251  if (!msg)
252  continue;
253 
254  msg_length = clib_host_to_net_u32 (vec_len (msg));
255  if (fwrite (&msg_length, 1, sizeof (msg_length), fp)
256  != sizeof (msg_length))
257  {
258  return (-14);
259  }
260  if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
261  {
262  return (-11);
263  }
264  }
265  }
266  else
267  {
268  /* Wrap case: write oldest -> end of buffer */
269  for (i = tp->curindex; i < vec_len (tp->traces); i++)
270  {
271  u32 msg_length;
272  msg = tp->traces[i];
273  /*
274  * This retarded check required to pass
275  * [sic] SA-checking
276  */
277  if (!msg)
278  continue;
279 
280  msg_length = clib_host_to_net_u32 (vec_len (msg));
281  if (fwrite (&msg_length, 1, sizeof (msg_length), fp)
282  != sizeof (msg_length))
283  {
284  return (-14);
285  }
286 
287  if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
288  {
289  return (-12);
290  }
291  }
292  /* write beginning of buffer -> oldest-1 */
293  for (i = 0; i < tp->curindex; i++)
294  {
295  u32 msg_length;
296  /*sa_ignore NO_NULL_CHK */
297  msg = tp->traces[i];
298  /*
299  * This retarded check required to pass
300  * [sic] SA-checking
301  */
302  if (!msg)
303  continue;
304 
305  msg_length = clib_host_to_net_u32 (vec_len (msg));
306  if (fwrite (&msg_length, 1, sizeof (msg_length), fp)
307  != sizeof (msg_length))
308  {
309  return (-14);
310  }
311 
312  if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
313  {
314  return (-13);
315  }
316  }
317  }
318  return 0;
319 }
320 
321 int
323  u32 nitems)
324 {
325  vl_api_trace_t *tp;
326  int was_on = 0;
327 
328  switch (which)
329  {
330  case VL_API_TRACE_TX:
331  tp = am->tx_trace;
332  if (tp == 0)
333  {
334  vec_validate (am->tx_trace, 0);
335  tp = am->tx_trace;
336  }
337  break;
338 
339  case VL_API_TRACE_RX:
340  tp = am->rx_trace;
341  if (tp == 0)
342  {
343  vec_validate (am->rx_trace, 0);
344  tp = am->rx_trace;
345  }
346 
347  break;
348 
349  default:
350  return -1;
351 
352  }
353 
354  if (tp->enabled)
355  {
356  was_on = vl_msg_api_trace_onoff (am, which, 0);
357  }
358  if (tp->traces)
359  {
360  vl_msg_api_trace_free (am, which);
361  }
362 
363  memset (tp, 0, sizeof (*tp));
364 
366  {
368  }
369  else
370  {
372  }
373 
374  tp->nitems = nitems;
375  if (was_on)
376  {
377  (void) vl_msg_api_trace_onoff (am, which, was_on);
378  }
379  return 0;
380 }
381 
382 void
384 {
385 }
386 
387 void
389 {
390 }
391 
392 always_inline void
394  void *the_msg, int trace_it, int do_it, int free_it)
395 {
396  u16 id = ntohs (*((u16 *) the_msg));
397  u8 *(*print_fp) (void *, void *);
398 
399  if (id < vec_len (am->msg_handlers) && am->msg_handlers[id])
400  {
401  if (trace_it)
402  vl_msg_api_trace (am, am->rx_trace, the_msg);
403 
404  if (am->msg_print_flag)
405  {
406  fformat (stdout, "[%d]: %s\n", id, am->msg_names[id]);
407  print_fp = (void *) am->msg_print_handlers[id];
408  if (print_fp == 0)
409  {
410  fformat (stdout, " [no registered print fn]\n");
411  }
412  else
413  {
414  (*print_fp) (the_msg, stdout);
415  }
416  }
417 
418  if (do_it)
419  {
420  if (!am->is_mp_safe[id])
421  {
424  }
425  (*am->msg_handlers[id]) (the_msg);
426  if (!am->is_mp_safe[id])
428  }
429  }
430  else
431  {
432  clib_warning ("no handler for msg id %d", id);
433  }
434 
435  if (free_it)
436  vl_msg_api_free (the_msg);
437 }
438 
439 /* set to 1 if you want before/after message handler event logging */
440 #define ELOG_API_MESSAGE_HANDLERS 0
441 
442 #if ELOG_API_MESSAGE_HANDLERS > 0
443 static u32
444 elog_id_for_msg_name (vlib_main_t * vm, char *msg_name)
445 {
446  uword *p, r;
447  static uword *h;
448  u8 *name_copy;
449 
450  if (!h)
451  h = hash_create_string (0, sizeof (uword));
452 
453  p = hash_get_mem (h, msg_name);
454  if (p)
455  return p[0];
456  r = elog_string (&vm->elog_main, "%s", msg_name);
457 
458  name_copy = format (0, "%s%c", msg_name, 0);
459 
460  hash_set_mem (h, name_copy, r);
461 
462  return r;
463 }
464 #endif
465 
466 /* This is only to be called from a vlib/vnet app */
467 void
469  void *the_msg, vlib_main_t * vm,
470  vlib_node_runtime_t * node)
471 {
472  u16 id = ntohs (*((u16 *) the_msg));
473  u8 *(*handler) (void *, void *, void *);
474 
475 #if ELOG_API_MESSAGE_HANDLERS > 0
476  {
477  /* *INDENT-OFF* */
478  ELOG_TYPE_DECLARE (e) =
479  {
480  .format = "api-msg: %s",
481  .format_args = "T4",
482  };
483  /* *INDENT-ON* */
484  struct
485  {
486  u32 c;
487  } *ed;
488  ed = ELOG_DATA (&vm->elog_main, e);
489  if (id < vec_len (am->msg_names))
490  ed->c = elog_id_for_msg_name (vm, am->msg_names[id]);
491  else
492  ed->c = elog_id_for_msg_name (vm, "BOGUS");
493  }
494 #endif
495 
496  if (id < vec_len (am->msg_handlers) && am->msg_handlers[id])
497  {
498  handler = (void *) am->msg_handlers[id];
499 
500  if (am->rx_trace && am->rx_trace->enabled)
501  vl_msg_api_trace (am, am->rx_trace, the_msg);
502 
503  if (!am->is_mp_safe[id])
504  {
507  }
508  (*handler) (the_msg, vm, node);
509  if (!am->is_mp_safe[id])
511  }
512  else
513  {
514  clib_warning ("no handler for msg id %d", id);
515  }
516 
517  /*
518  * Special-case, so we can e.g. bounce messages off the vnet
519  * main thread without copying them...
520  */
521  if (!(am->message_bounce[id]))
522  vl_msg_api_free (the_msg);
523 
524 #if ELOG_API_MESSAGE_HANDLERS > 0
525  {
526  /* *INDENT-OFF* */
527  ELOG_TYPE_DECLARE (e) = {
528  .format = "api-msg-done: %s",
529  .format_args = "T4",
530  };
531  /* *INDENT-ON* */
532 
533  struct
534  {
535  u32 c;
536  } *ed;
537  ed = ELOG_DATA (&vm->elog_main, e);
538  if (id < vec_len (am->msg_names))
539  ed->c = elog_id_for_msg_name (vm, am->msg_names[id]);
540  else
541  ed->c = elog_id_for_msg_name (vm, "BOGUS");
542  }
543 #endif
544 }
545 
546 void
547 vl_msg_api_handler (void *the_msg)
548 {
549  api_main_t *am = &api_main;
550 
551  msg_handler_internal (am, the_msg,
552  (am->rx_trace
553  && am->rx_trace->enabled) /* trace_it */ ,
554  1 /* do_it */ , 1 /* free_it */ );
555 }
556 
557 void
559 {
560  api_main_t *am = &api_main;
561  msg_handler_internal (am, the_msg,
562  (am->rx_trace
563  && am->rx_trace->enabled) /* trace_it */ ,
564  1 /* do_it */ , 0 /* free_it */ );
565 }
566 
567 void
569 {
570  api_main_t *am = &api_main;
571  msg_handler_internal (am, the_msg, 0 /* trace_it */ , 1 /* do_it */ ,
572  0 /* free_it */ );
573 }
574 
575 /*
576  * Add a trace record to the API message trace buffer, if
577  * API message tracing is enabled. Handy for adding sufficient
578  * data to the trace to reproduce autonomous state, as opposed to
579  * state downloaded via control-plane API messages. Example: the NAT
580  * application creates database entries based on packet traffic, not
581  * control-plane messages.
582  *
583  */
584 void
585 vl_msg_api_trace_only (void *the_msg)
586 {
587  api_main_t *am = &api_main;
588 
589  msg_handler_internal (am, the_msg,
590  (am->rx_trace
591  && am->rx_trace->enabled) /* trace_it */ ,
592  0 /* do_it */ , 0 /* free_it */ );
593 }
594 
595 void
597 {
598  api_main_t *am = &api_main;
599  u16 id = ntohs (*((u16 *) the_msg));
600 
601  if (PREDICT_FALSE (id >= vec_len (am->msg_cleanup_handlers)))
602  {
603  clib_warning ("_vl_msg_id too large: %d\n", id);
604  return;
605  }
606  if (am->msg_cleanup_handlers[id])
607  (*am->msg_cleanup_handlers[id]) (the_msg);
608 
609  vl_msg_api_free (the_msg);
610 }
611 
612 /*
613  * vl_msg_api_replay_handler
614  */
615 void
617 {
618  api_main_t *am = &api_main;
619 
620  u16 id = ntohs (*((u16 *) the_msg));
621 
622  if (PREDICT_FALSE (id >= vec_len (am->msg_handlers)))
623  {
624  clib_warning ("_vl_msg_id too large: %d\n", id);
625  return;
626  }
627  /* do NOT trace the message... */
628  if (am->msg_handlers[id])
629  (*am->msg_handlers[id]) (the_msg);
630  /* do NOT free the message buffer... */
631 }
632 
633 u32
635 {
636  return vl_msg_api_get_msg_length_inline (msg_arg);
637 }
638 
639 /*
640  * vl_msg_api_socket_handler
641  */
642 void
644 {
645  api_main_t *am = &api_main;
646 
647  msg_handler_internal (am, the_msg,
648  (am->rx_trace
649  && am->rx_trace->enabled) /* trace_it */ ,
650  1 /* do_it */ , 0 /* free_it */ );
651 }
652 
653 #define foreach_msg_api_vector \
654 _(msg_names) \
655 _(msg_handlers) \
656 _(msg_cleanup_handlers) \
657 _(msg_endian_handlers) \
658 _(msg_print_handlers) \
659 _(api_trace_cfg) \
660 _(message_bounce) \
661 _(is_mp_safe)
662 
663 void
665 {
666  api_main_t *am = &api_main;
667 
668  ASSERT (c->id > 0);
669 
670 #define _(a) vec_validate (am->a, c->id);
672 #undef _
673 
674  if (am->msg_handlers[c->id] && am->msg_handlers[c->id] != c->handler)
676  ("BUG: re-registering 'vl_api_%s_t_handler'."
677  "Handler was %llx, replaced by %llx",
678  c->name, am->msg_handlers[c->id], c->handler);
679 
680  am->msg_names[c->id] = c->name;
681  am->msg_handlers[c->id] = c->handler;
682  am->msg_cleanup_handlers[c->id] = c->cleanup;
683  am->msg_endian_handlers[c->id] = c->endian;
684  am->msg_print_handlers[c->id] = c->print;
685  am->message_bounce[c->id] = c->message_bounce;
686  am->is_mp_safe[c->id] = c->is_mp_safe;
687 
688  am->api_trace_cfg[c->id].size = c->size;
689  am->api_trace_cfg[c->id].trace_enable = c->traced;
690  am->api_trace_cfg[c->id].replay_enable = c->replay;
691 }
692 
693 /*
694  * vl_msg_api_set_handlers
695  * preserve the old API for a while
696  */
697 void
698 vl_msg_api_set_handlers (int id, char *name, void *handler, void *cleanup,
699  void *endian, void *print, int size, int traced)
700 {
702  vl_msg_api_msg_config_t *c = &cfg;
703 
704  memset (c, 0, sizeof (*c));
705 
706  c->id = id;
707  c->name = name;
708  c->handler = handler;
709  c->cleanup = cleanup;
710  c->endian = endian;
711  c->print = print;
712  c->traced = traced;
713  c->replay = 1;
714  c->message_bounce = 0;
715  c->is_mp_safe = 0;
716  vl_msg_api_config (c);
717 }
718 
719 void
721 {
723  vl_msg_api_msg_config_t *c = &cfg;
724 
725  memset (c, 0, sizeof (*c));
726 
727  c->id = msg_id;
728  vl_msg_api_config (c);
729 }
730 
731 void
732 vl_msg_api_set_cleanup_handler (int msg_id, void *fp)
733 {
734  api_main_t *am = &api_main;
735  ASSERT (msg_id > 0);
736 
737  vec_validate (am->msg_cleanup_handlers, msg_id);
738  am->msg_cleanup_handlers[msg_id] = fp;
739 }
740 
741 void
743 {
744  uword msg;
745 
746  while (!unix_shared_memory_queue_sub (q, (u8 *) & msg, 0))
747  vl_msg_api_handler ((void *) msg);
748 }
749 
752 {
753  switch (which)
754  {
755  case VL_API_TRACE_RX:
756  return am->rx_trace;
757  case VL_API_TRACE_TX:
758  return am->tx_trace;
759  default:
760  return 0;
761  }
762 }
763 
764 void
765 vl_noop_handler (void *mp)
766 {
767 }
768 
769 
771 
772 void
774 {
775  post_mortem_dump_enabled = enable;
776 }
777 
778 void
780 {
781  api_main_t *am = &api_main;
782  FILE *fp;
783  char filename[64];
784  int rv;
785 
786  if (post_mortem_dump_enabled == 0)
787  return;
788 
789  snprintf (filename, sizeof (filename), "/tmp/api_post_mortem.%d",
790  getpid ());
791 
792  fp = fopen (filename, "w");
793  if (fp == NULL)
794  {
795  rv = write (2, "Couldn't create ", 16);
796  rv = write (2, filename, strlen (filename));
797  rv = write (2, "\n", 1);
798  return;
799  }
800  rv = vl_msg_api_trace_save (am, VL_API_TRACE_RX, fp);
801  fclose (fp);
802  if (rv < 0)
803  {
804  rv = write (2, "Failed to save post-mortem API trace to ", 40);
805  rv = write (2, filename, strlen (filename));
806  rv = write (2, "\n", 1);
807  }
808 
809 }
810 
811 /* Layered message handling support */
812 
813 void
814 vl_msg_api_register_pd_handler (void *fp, u16 msg_id_host_byte_order)
815 {
816  api_main_t *am = &api_main;
817 
818  /* Mild idiot proofing */
819  if (msg_id_host_byte_order > 10000)
820  clib_warning ("msg_id_host_byte_order endian issue? %d arg vs %d",
821  msg_id_host_byte_order,
822  clib_net_to_host_u16 (msg_id_host_byte_order));
823  vec_validate (am->pd_msg_handlers, msg_id_host_byte_order);
824  am->pd_msg_handlers[msg_id_host_byte_order] = fp;
825 }
826 
827 int
828 vl_msg_api_pd_handler (void *mp, int rv)
829 {
830  api_main_t *am = &api_main;
831  int (*fp) (void *, int);
832  u16 msg_id;
833 
835  msg_id = clib_net_to_host_u16 (*((u16 *) mp));
836  else
837  msg_id = *((u16 *) mp);
838 
839  if (msg_id >= vec_len (am->pd_msg_handlers)
840  || am->pd_msg_handlers[msg_id] == 0)
841  return rv;
842 
843  fp = am->pd_msg_handlers[msg_id];
844  rv = (*fp) (mp, rv);
845  return rv;
846 }
847 
848 void
850 {
851  api_main_t *am = &api_main;
852 
853  am->first_available_msg_id = first_avail;
854 }
855 
856 u16
857 vl_msg_api_get_msg_ids (const char *name, int n)
858 {
859  api_main_t *am = &api_main;
860  u8 *name_copy;
861  vl_api_msg_range_t *rp;
862  uword *p;
863  u16 rv;
864 
865  if (am->msg_range_by_name == 0)
866  am->msg_range_by_name = hash_create_string (0, sizeof (uword));
867 
868  name_copy = format (0, "%s%c", name, 0);
869 
870  p = hash_get_mem (am->msg_range_by_name, name_copy);
871  if (p)
872  {
873  clib_warning ("WARNING: duplicate message range registration for '%s'",
874  name_copy);
875  vec_free (name_copy);
876  return ((u16) ~ 0);
877  }
878 
879  if (n < 0 || n > 1024)
880  {
882  ("WARNING: bad number of message-IDs (%d) requested by '%s'",
883  n, name_copy);
884  vec_free (name_copy);
885  return ((u16) ~ 0);
886  }
887 
888  vec_add2 (am->msg_ranges, rp, 1);
889 
890  rv = rp->first_msg_id = am->first_available_msg_id;
891  am->first_available_msg_id += n;
892  rp->last_msg_id = am->first_available_msg_id - 1;
893  rp->name = name_copy;
894 
895  hash_set_mem (am->msg_range_by_name, name_copy, rp - am->msg_ranges);
896 
897  return rv;
898 }
899 
900 void
901 vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string, u32 id)
902 {
903  uword *p;
904 
905  if (am->msg_index_by_name_and_crc == 0)
907 
908  p = hash_get_mem (am->msg_index_by_name_and_crc, string);
909  if (p)
910  {
911  clib_warning ("attempt to redefine '%s' ignored...", string);
912  return;
913  }
914 
915  hash_set_mem (am->msg_index_by_name_and_crc, string, id);
916 }
917 
918 
919 /*
920  * fd.io coding-style-patch-verification: ON
921  *
922  * Local Variables:
923  * eval: (c-set-style "gnu")
924  * End:
925  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:432
void vl_msg_api_set_first_available_msg_id(u16 first_avail)
Definition: api_shared.c:849
Message range (belonging to a plugin)
Definition: api_common.h:101
int vl_msg_api_trace_onoff(api_main_t *am, vl_api_trace_which_t which, int onoff)
Definition: api_shared.c:112
int vl_msg_api_trace_save(api_main_t *am, vl_api_trace_which_t which, FILE *fp)
Definition: api_shared.c:191
void vl_msg_api_set_handlers(int id, char *name, void *handler, void *cleanup, void *endian, void *print, int size, int traced)
Definition: api_shared.c:698
int vl_msg_api_trace_free(api_main_t *am, vl_api_trace_which_t which)
Definition: api_shared.c:154
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
int id
the message ID
Definition: api_common.h:111
u8 * name
name of the plugin
Definition: api_common.h:103
void vl_msg_api_set_cleanup_handler(int msg_id, void *fp)
Definition: api_shared.c:732
int vl_msg_api_pd_handler(void *mp, int rv)
Definition: api_shared.c:828
void vl_msg_api_handler(void *the_msg)
Definition: api_shared.c:547
void * print
message print function
Definition: api_common.h:117
u8 wrapped
trace has wrapped
Definition: api_common.h:83
static u64 do_it(pg_main_t *pg, pg_stream_t *s, u32 *buffers, u32 n_buffers, u32 lo_bit, u32 hi_bit, u64 v_min, u64 v_max, u64 v, pg_edit_type_t edit_type)
Definition: input.c:744
int size
for sanity checking
Definition: api_common.h:71
#define NULL
Definition: clib.h:55
static void msg_handler_internal(api_main_t *am, void *the_msg, int trace_it, int do_it, int free_it)
Definition: api_shared.c:393
u8 * message_bounce
Don&#39;t automatically free message buffer vetor.
Definition: api_common.h:202
static u8 post_mortem_dump_enabled
Definition: api_shared.c:770
Message configuration definition.
Definition: api_common.h:109
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:518
vl_api_trace_t * vl_msg_api_trace_get(api_main_t *am, vl_api_trace_which_t which)
Definition: api_shared.c:751
u32 vl_msg_api_get_msg_length(void *msg_arg)
Definition: api_shared.c:634
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:557
#define hash_set_mem(h, key, value)
Definition: hash.h:274
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
int vl_msg_api_trace_configure(api_main_t *am, vl_api_trace_which_t which, u32 nitems)
Definition: api_shared.c:322
void(** msg_cleanup_handlers)(void *)
non-default message cleanup handler vector
Definition: api_common.h:190
void vl_noop_handler(void *mp)
Definition: api_shared.c:765
void * cleanup
non-default message cleanup handler
Definition: api_common.h:115
trace_cfg_t * api_trace_cfg
Current trace configuration.
Definition: api_common.h:229
void vl_msg_api_handler_no_trace_no_free(void *the_msg)
Definition: api_shared.c:568
int size
message size
Definition: api_common.h:118
void vl_msg_api_cleanup_handler(void *the_msg)
Definition: api_shared.c:596
void * endian
message endian function
Definition: api_common.h:116
vl_api_trace_t * rx_trace
Received message trace configuration.
Definition: api_common.h:220
#define always_inline
Definition: clib.h:84
void vl_msg_api_config(vl_msg_api_msg_config_t *c)
Definition: api_shared.c:664
#define vl_msg_api_barrier_trace_context(X)
Definition: api_common.h:158
void vl_msg_api_post_mortem_dump_enable_disable(int enable)
Definition: api_shared.c:773
#define clib_arch_is_little_endian
Definition: byte_order.h:54
int vl_msg_api_tx_trace_enabled(api_main_t *am)
Definition: api_shared.c:57
void vl_msg_api_trace_only(void *the_msg)
Definition: api_shared.c:585
void vl_msg_api_clean_handlers(int msg_id)
Definition: api_shared.c:720
#define hash_create_string(elts, value_bytes)
Definition: hash.h:652
void vl_msg_api_queue_handler(unix_shared_memory_queue_t *q)
Definition: api_shared.c:742
void vl_msg_api_handler_with_vm_node(api_main_t *am, void *the_msg, vlib_main_t *vm, vlib_node_runtime_t *node)
Definition: api_shared.c:468
u16 last_msg_id
last assigned message ID
Definition: api_common.h:105
void vl_msg_api_add_msg_name_crc(api_main_t *am, const char *string, u32 id)
Definition: api_shared.c:901
int vl_msg_api_rx_trace_enabled(api_main_t *am)
Definition: api_shared.c:51
void(** msg_print_handlers)(void *, void *)
Message print function vector.
Definition: api_common.h:196
int replay_enable
This message can be replayed.
Definition: api_common.h:73
void vl_msg_api_free(void *)
int message_bounce
do not free message after processing
Definition: api_common.h:121
u32 curindex
Current index in circular buffer.
Definition: api_common.h:86
static void cleanup(void)
Definition: client.c:90
#define ELOG_DATA(em, f)
Definition: elog.h:481
#define PREDICT_FALSE(x)
Definition: clib.h:97
word fformat(FILE *f, char *fmt,...)
Definition: format.c:453
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:182
u8 enabled
trace is enabled
Definition: api_common.h:82
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
#define clib_arch_is_big_endian
Definition: byte_order.h:53
int unix_shared_memory_queue_sub(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
svmdb_client_t * c
API trace state.
Definition: api_common.h:79
vlib_main_t * vm
Definition: buffer.c:283
vec_header_t h
Definition: buffer.c:282
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
void vl_msg_api_barrier_release(void)
Definition: api_shared.c:388
vl_api_msg_range_t * msg_ranges
vector of message ranges
Definition: api_common.h:256
void vl_msg_api_post_mortem_dump(void)
Definition: api_shared.c:779
#define clib_warning(format, args...)
Definition: error.h:59
#define clib_memcpy(a, b, c)
Definition: string.h:69
elog_main_t elog_main
Definition: main.h:155
u8 ** traces
Trace ring.
Definition: api_common.h:87
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:439
const char ** msg_names
Message name vector.
Definition: api_common.h:199
int replay
is this message to be replayed?
Definition: api_common.h:120
void vl_msg_api_socket_handler(void *the_msg)
Definition: api_shared.c:643
#define VL_API_BIG_ENDIAN
Definition: api_common.h:98
api_main_t api_main
Definition: api_shared.c:35
vl_api_trace_t * tx_trace
Sent message trace configuration.
Definition: api_common.h:223
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
#define VL_API_LITTLE_ENDIAN
Definition: api_common.h:97
static u32 elog_id_for_msg_name(mc_main_t *m, char *msg_name)
Definition: mc.c:46
u32 data_len
message length not including header
Definition: api_common.h:129
Message header structure.
Definition: api_common.h:126
u64 size
Definition: vhost-user.h:76
void vl_msg_api_replay_handler(void *the_msg)
Definition: api_shared.c:616
void vl_msg_api_handler_no_free(void *the_msg)
Definition: api_shared.c:558
u64 uword
Definition: types.h:112
u32 missing_clients
Number of missing clients / failed message sends.
Definition: api_common.h:217
void vl_msg_api_increment_missing_client_counter(void)
Definition: api_shared.c:44
unsigned short u16
Definition: types.h:57
u16 first_msg_id
first assigned message ID
Definition: api_common.h:104
void vl_msg_api_register_pd_handler(void *fp, u16 msg_id_host_byte_order)
Definition: api_shared.c:814
void(** msg_endian_handlers)(void *)
Message endian handler vector.
Definition: api_common.h:193
u32 elog_string(elog_main_t *em, char *fmt,...)
add a string to the event-log string table
Definition: elog.c:534
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
static u32 vl_msg_api_get_msg_length_inline(void *msg_arg)
Definition: api.h:93
int(** pd_msg_handlers)(void *, int)
Plaform-dependent (aka hardware) message handler vector.
Definition: api_common.h:187
#define foreach_msg_api_vector
Definition: api_shared.c:653
#define hash_get_mem(h, key)
Definition: hash.h:268
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:857
u16 first_available_msg_id
First available message ID, for theplugin msg allocator.
Definition: api_common.h:250
u8 endian
trace endianness
Definition: api_common.h:81
void(** msg_handlers)(void *)
Message handler vector.
Definition: api_common.h:185
u8 * is_mp_safe
Message is mp safe vector.
Definition: api_common.h:205
void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg)
Definition: api_shared.c:66
int trace_enable
trace this message
Definition: api_common.h:72
int msg_print_flag
Print every received message.
Definition: api_common.h:226
int is_mp_safe
worker thread barrier required?
Definition: api_common.h:122
int traced
is this message to be traced?
Definition: api_common.h:119
vl_api_trace_which_t
Trace RX / TX enum.
Definition: api_common.h:91
const char * region_name
Shared VM binary API region name.
Definition: api_common.h:304
Trace configuration for a single message.
Definition: api_common.h:69
uword * msg_index_by_name_and_crc
client message index hash table
Definition: api_common.h:301
uword * msg_range_by_name
Message range by name hash.
Definition: api_common.h:253
char * name
the message name
Definition: api_common.h:112
u32 nitems
Number of trace records.
Definition: api_common.h:85
void * handler
the message handler
Definition: api_common.h:114
struct _unix_shared_memory_queue unix_shared_memory_queue_t
void vl_msg_api_barrier_sync(void)
Definition: api_shared.c:383