FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * api.c - message handler registration
4  *
5  * Copyright (c) 2010-2018 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sys/types.h>
24 #include <sys/mman.h>
25 #include <sys/stat.h>
26 #include <netinet/in.h>
27 #include <signal.h>
28 #include <pthread.h>
29 #include <unistd.h>
30 #include <time.h>
31 #include <fcntl.h>
32 #include <string.h>
33 #include <pwd.h>
34 #include <grp.h>
35 
36 #include <vppinfra/clib.h>
37 #include <vppinfra/vec.h>
38 #include <vppinfra/hash.h>
39 #include <vppinfra/bitmap.h>
40 #include <vppinfra/fifo.h>
41 #include <vppinfra/time.h>
42 #include <vppinfra/mheap.h>
43 #include <vppinfra/heap.h>
44 #include <vppinfra/pool.h>
45 #include <vppinfra/format.h>
46 #include <vppinfra/error.h>
47 
48 #include <vnet/api_errno.h>
49 #include <vnet/vnet.h>
50 
51 #include <vlib/log.h>
52 #include <vlib/vlib.h>
53 #include <vlib/unix/unix.h>
54 #include <vlibapi/api.h>
55 #include <vlibmemory/api.h>
56 
57 #undef BIHASH_TYPE
58 #undef __included_bihash_template_h__
59 
60 #include <vnet/ip/format.h>
61 
62 #include <vpp/api/vpe_msg_enum.h>
63 #include <vpp/api/types.h>
64 
65 #define vl_typedefs /* define message structures */
66 #include <vpp/api/vpe_all_api_h.h>
67 #undef vl_typedefs
68 #define vl_endianfun /* define message structures */
69 #include <vpp/api/vpe_all_api_h.h>
70 #undef vl_endianfun
71 /* instantiate all the print functions we know about */
72 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
73 #define vl_printfun
74 #include <vpp/api/vpe_all_api_h.h>
75 #undef vl_printfun
77 
78 #define foreach_vpe_api_msg \
79 _(CONTROL_PING, control_ping) \
80 _(CLI, cli) \
81 _(CLI_INBAND, cli_inband) \
82 _(GET_NODE_INDEX, get_node_index) \
83 _(ADD_NODE_NEXT, add_node_next) \
84 _(SHOW_VERSION, show_version) \
85 _(SHOW_THREADS, show_threads) \
86 _(GET_NODE_GRAPH, get_node_graph) \
87 _(GET_NEXT_INDEX, get_next_index) \
88 _(LOG_DUMP, log_dump) \
89 _(SHOW_VPE_SYSTEM_TIME, show_vpe_system_time) \
90 _(GET_F64_ENDIAN_VALUE, get_f64_endian_value) \
91 _(GET_F64_INCREMENT_BY_ONE, get_f64_increment_by_one) \
92 
93 #define QUOTE_(x) #x
94 #define QUOTE(x) QUOTE_(x)
95 
96 typedef enum
97 {
100 } resolve_t;
101 
103 
104 /* Clean up all registrations belonging to the indicated client */
105 static clib_error_t *
107 {
110  uword *p;
111 
112 #define _(a) \
113  p = hash_get (vam->a##_registration_hash, client_index); \
114  if (p) { \
115  rp = pool_elt_at_index (vam->a##_registrations, p[0]); \
116  pool_put (vam->a##_registrations, rp); \
117  hash_unset (vam->a##_registration_hash, client_index); \
118  }
120 #undef _
121  return 0;
122 }
123 
125 
126 static void
128 {
130  int rv = 0;
131 
132  /* *INDENT-OFF* */
133  REPLY_MACRO2(VL_API_CONTROL_PING_REPLY,
134  ({
135  rmp->vpe_pid = ntohl (getpid());
136  }));
137  /* *INDENT-ON* */
138 }
139 
140 static void
141 shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
142 {
143  u8 **shmem_vecp = (u8 **) arg;
144  u8 *shmem_vec;
145  void *oldheap;
146  api_main_t *am = &api_main;
147  u32 offset;
148 
149  shmem_vec = *shmem_vecp;
150 
151  offset = vec_len (shmem_vec);
152 
153  pthread_mutex_lock (&am->vlib_rp->mutex);
154  oldheap = svm_push_data_heap (am->vlib_rp);
155 
156  vec_validate (shmem_vec, offset + buffer_bytes - 1);
157 
158  clib_memcpy (shmem_vec + offset, buffer, buffer_bytes);
159 
160  svm_pop_heap (oldheap);
161  pthread_mutex_unlock (&am->vlib_rp->mutex);
162 
163  *shmem_vecp = shmem_vec;
164 }
165 
166 
167 static void
169 {
170  vl_api_cli_reply_t *rp;
173  api_main_t *am = &api_main;
174  unformat_input_t input;
175  u8 *shmem_vec = 0;
176  void *oldheap;
177 
179  if (!reg)
180  return;;
181 
182  rp = vl_msg_api_alloc (sizeof (*rp));
183  rp->_vl_msg_id = ntohs (VL_API_CLI_REPLY);
184  rp->context = mp->context;
185 
186  unformat_init_vector (&input, (u8 *) (uword) mp->cmd_in_shmem);
187 
188  vlib_cli_input (vm, &input, shmem_cli_output, (uword) & shmem_vec);
189 
190  pthread_mutex_lock (&am->vlib_rp->mutex);
191  oldheap = svm_push_data_heap (am->vlib_rp);
192 
193  vec_add1 (shmem_vec, 0);
194 
195  svm_pop_heap (oldheap);
196  pthread_mutex_unlock (&am->vlib_rp->mutex);
197 
198  rp->reply_in_shmem = (uword) shmem_vec;
199 
200  vl_api_send_msg (reg, (u8 *) rp);
201 }
202 
203 static void
204 inband_cli_output (uword arg, u8 * buffer, uword buffer_bytes)
205 {
206  u8 **mem_vecp = (u8 **) arg;
207  u8 *mem_vec = *mem_vecp;
208  u32 offset = vec_len (mem_vec);
209 
210  vec_validate (mem_vec, offset + buffer_bytes - 1);
211  clib_memcpy (mem_vec + offset, buffer, buffer_bytes);
212  *mem_vecp = mem_vec;
213 }
214 
215 static void
217 {
219  int rv = 0;
221  unformat_input_t input;
222  u8 *out_vec = 0;
223  u32 len = 0;
224 
225  if (vl_msg_api_get_msg_length (mp) <
226  vl_api_string_len (&mp->cmd) + sizeof (*mp))
227  {
228  rv = -1;
229  goto error;
230  }
231 
232  unformat_init_string (&input, (char *) vl_api_from_api_string (&mp->cmd),
233  vl_api_string_len (&mp->cmd));
234  rv = vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec);
235 
236  len = vec_len (out_vec);
237 
238 error:
239  /* *INDENT-OFF* */
240  REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len,
241  ({
242  vl_api_to_api_string(len, (const char *)out_vec, &rmp->reply);
243  }));
244  /* *INDENT-ON* */
245  vec_free (out_vec);
246 }
247 
248 static void
250 {
252  int rv = 0;
253  char *vpe_api_get_build_directory (void);
254  char *vpe_api_get_version (void);
255  char *vpe_api_get_build_date (void);
256 
257  /* *INDENT-OFF* */
258  REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY,
259  ({
260  strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1);
261  strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(),
262  ARRAY_LEN(rmp->build_directory)-1);
263  strncpy ((char *) rmp->version, vpe_api_get_version(),
264  ARRAY_LEN(rmp->version)-1);
265  strncpy ((char *) rmp->build_date, vpe_api_get_build_date(),
266  ARRAY_LEN(rmp->build_date)-1);
267  }));
268  /* *INDENT-ON* */
269 }
270 
271 static void
273 {
275  td->id = htonl (index);
276  if (w->name)
277  strncpy ((char *) td->name, (char *) w->name, ARRAY_LEN (td->name) - 1);
278  if (w->registration)
279  strncpy ((char *) td->type, (char *) w->registration->name,
280  ARRAY_LEN (td->type) - 1);
281  td->pid = htonl (w->lwp);
282  td->cpu_id = htonl (w->cpu_id);
283  td->core = htonl (w->core_id);
284  td->cpu_socket = htonl (w->socket_id);
285 }
286 
287 static void
289 {
290  int count = 0;
291 
292 #if !defined(__powerpc64__)
296  int i, msg_size = 0;
297  count = vec_len (vlib_worker_threads);
298  if (!count)
299  return;
300 
301  msg_size = sizeof (*rmp) + sizeof (rmp->thread_data[0]) * count;
303  if (!reg)
304  return;
305 
306  rmp = vl_msg_api_alloc (msg_size);
307  clib_memset (rmp, 0, msg_size);
308  rmp->_vl_msg_id = htons (VL_API_SHOW_THREADS_REPLY);
309  rmp->context = mp->context;
310  rmp->count = htonl (count);
311  td = rmp->thread_data;
312 
313  for (i = 0; i < count; i++)
314  {
315  get_thread_data (&td[i], i);
316  }
317 
318  vl_api_send_msg (reg, (u8 *) rmp);
319 #else
320 
321  /* unimplemented support */
322  rv = -9;
323  clib_warning ("power pc does not support show threads api");
324  /* *INDENT-OFF* */
325  REPLY_MACRO2(VL_API_SHOW_THREADS_REPLY,
326  ({
327  rmp->count = htonl(count);
328  }));
329  /* *INDENT-ON* */
330 #endif
331 }
332 
333 static void
335 {
338  vlib_node_t *n;
339  int rv = 0;
340  u32 node_index = ~0;
341 
342  n = vlib_get_node_by_name (vm, mp->node_name);
343 
344  if (n == 0)
345  rv = VNET_API_ERROR_NO_SUCH_NODE;
346  else
347  node_index = n->index;
348 
349  /* *INDENT-OFF* */
350  REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
351  ({
352  rmp->node_index = ntohl(node_index);
353  }));
354  /* *INDENT-ON* */
355 }
356 
357 static void
359 {
362  vlib_node_t *node, *next_node;
363  int rv = 0;
364  u32 next_node_index = ~0, next_index = ~0;
365  uword *p;
366 
367  node = vlib_get_node_by_name (vm, mp->node_name);
368 
369  if (node == 0)
370  {
371  rv = VNET_API_ERROR_NO_SUCH_NODE;
372  goto out;
373  }
374 
375  next_node = vlib_get_node_by_name (vm, mp->next_name);
376 
377  if (next_node == 0)
378  {
379  rv = VNET_API_ERROR_NO_SUCH_NODE2;
380  goto out;
381  }
382  else
383  next_node_index = next_node->index;
384 
385  p = hash_get (node->next_slot_by_node, next_node_index);
386 
387  if (p == 0)
388  {
389  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
390  goto out;
391  }
392  else
393  next_index = p[0];
394 
395 out:
396  /* *INDENT-OFF* */
397  REPLY_MACRO2(VL_API_GET_NEXT_INDEX_REPLY,
398  ({
399  rmp->next_index = ntohl(next_index);
400  }));
401  /* *INDENT-ON* */
402 }
403 
404 static void
406 {
409  vlib_node_t *n, *next;
410  int rv = 0;
411  u32 next_index = ~0;
412 
413  n = vlib_get_node_by_name (vm, mp->node_name);
414 
415  if (n == 0)
416  {
417  rv = VNET_API_ERROR_NO_SUCH_NODE;
418  goto out;
419  }
420 
421  next = vlib_get_node_by_name (vm, mp->next_name);
422 
423  if (next == 0)
424  rv = VNET_API_ERROR_NO_SUCH_NODE2;
425  else
426  next_index = vlib_node_add_next (vm, n->index, next->index);
427 
428 out:
429  /* *INDENT-OFF* */
430  REPLY_MACRO2(VL_API_GET_NODE_INDEX_REPLY,
431  ({
432  rmp->next_index = ntohl(next_index);
433  }));
434  /* *INDENT-ON* */
435 }
436 
437 static void
439 {
440  int rv = 0;
441  u8 *vector = 0;
442  api_main_t *am = &api_main;
444  void *oldheap;
446  static vlib_node_t ***node_dups;
447  static vlib_main_t **stat_vms;
448 
449  pthread_mutex_lock (&am->vlib_rp->mutex);
450  oldheap = svm_push_data_heap (am->vlib_rp);
451 
452  /*
453  * Keep the number of memcpy ops to a minimum (e.g. 1).
454  */
455  vec_validate (vector, 16384);
456  vec_reset_length (vector);
457 
458  vlib_node_get_nodes (vm, 0 /* main threads */ ,
459  0 /* include stats */ ,
460  1 /* barrier sync */ ,
461  &node_dups, &stat_vms);
462  vector = vlib_node_serialize (vm, node_dups, vector, 1 /* include nexts */ ,
463  1 /* include stats */ );
464 
465  svm_pop_heap (oldheap);
466  pthread_mutex_unlock (&am->vlib_rp->mutex);
467 
468  /* *INDENT-OFF* */
469  REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
470  ({
471  rmp->reply_in_shmem = (uword) vector;
472  }));
473  /* *INDENT-ON* */
474 }
475 
476 static void
478  f64 timestamp,
479  vl_api_log_level_t * level, u8 * msg_class, u8 * message)
480 {
481  u32 msg_size;
482 
484  int class_len =
485  clib_min (vec_len (msg_class) + 1, ARRAY_LEN (rmp->msg_class));
486  int message_len =
487  clib_min (vec_len (message) + 1, ARRAY_LEN (rmp->message));
488  msg_size = sizeof (*rmp) + class_len + message_len;
489 
490  rmp = vl_msg_api_alloc (msg_size);
491  clib_memset (rmp, 0, msg_size);
492  rmp->_vl_msg_id = ntohs (VL_API_LOG_DETAILS);
493 
494  rmp->context = context;
495  rmp->timestamp = clib_host_to_net_f64 (timestamp);
496  rmp->level = htonl (*level);
497 
498  memcpy (rmp->msg_class, msg_class, class_len - 1);
499  memcpy (rmp->message, message, message_len - 1);
500  /* enforced by memset() above */
501  ASSERT (0 == rmp->msg_class[class_len - 1]);
502  ASSERT (0 == rmp->message[message_len - 1]);
503 
504  vl_api_send_msg (reg, (u8 *) rmp);
505 }
506 
507 static void
509 {
510 
511  /* from log.c */
512  vlib_log_main_t *lm = &log_main;
513  vlib_log_entry_t *e;
514  int i = last_log_entry ();
515  int count = lm->count;
516  f64 time_offset, start_time;
518 
520  if (reg == 0)
521  return;
522 
523  start_time = clib_net_to_host_f64 (mp->start_timestamp);
524 
525  time_offset = (f64) lm->time_zero_timeval.tv_sec
526  + (((f64) lm->time_zero_timeval.tv_usec) * 1e-6) - lm->time_zero;
527 
528  while (count--)
529  {
530  e = vec_elt_at_index (lm->entries, i);
531  if (start_time <= e->timestamp + time_offset)
532  show_log_details (reg, mp->context, e->timestamp + time_offset,
533  (vl_api_log_level_t *) & e->level,
534  format (0, "%U", format_vlib_log_class, e->class),
535  e->string);
536  i = (i + 1) % lm->size;
537  }
538 
539 }
540 
541 static void
543 {
544  int rv = 0;
546  /* *INDENT-OFF* */
547  REPLY_MACRO2(VL_API_SHOW_VPE_SYSTEM_TIME_REPLY,
548  ({
550  }));
551  /* *INDENT-ON* */
552 }
553 
554 static void
556 {
557  int rv = 0;
558  f64 one = 1.0;
560  if (1.0 != clib_net_to_host_f64 (mp->f64_one))
561  rv = VNET_API_ERROR_API_ENDIAN_FAILED;
562 
563  /* *INDENT-OFF* */
564  REPLY_MACRO2(VL_API_GET_F64_ENDIAN_VALUE_REPLY,
565  ({
567  }));
568  /* *INDENT-ON* */
569 }
570 
571 static void
573  mp)
574 {
575  int rv = 0;
577 
578  /* *INDENT-OFF* */
579  REPLY_MACRO2(VL_API_GET_F64_INCREMENT_BY_ONE_REPLY,
580  ({
582  }));
583  /* *INDENT-ON* */
584 }
585 
586 #define BOUNCE_HANDLER(nn) \
587 static void vl_api_##nn##_t_handler ( \
588  vl_api_##nn##_t *mp) \
589 { \
590  vpe_client_registration_t *reg; \
591  vpe_api_main_t * vam = &vpe_api_main; \
592  svm_queue_t * q; \
593  \
594  /* One registration only... */ \
595  pool_foreach(reg, vam->nn##_registrations, \
596  ({ \
597  q = vl_api_client_index_to_input_queue (reg->client_index); \
598  if (q) { \
599  /* \
600  * If the queue is stuffed, turf the msg and complain \
601  * It's unlikely that the intended recipient is \
602  * alive; avoid deadlock at all costs. \
603  */ \
604  if (q->cursize == q->maxsize) { \
605  clib_warning ("ERROR: receiver queue full, drop msg"); \
606  vl_msg_api_free (mp); \
607  return; \
608  } \
609  vl_msg_api_send_shmem (q, (u8 *)&mp); \
610  return; \
611  } \
612  })); \
613  vl_msg_api_free (mp); \
614 }
615 
616 static void setup_message_id_table (api_main_t * am);
617 
618 /*
619  * vpe_api_hookup
620  * Add vpe's API message handlers to the table.
621  * vlib has already mapped shared memory and
622  * added the client registration handlers.
623  * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
624  */
625 static clib_error_t *
627 {
628  api_main_t *am = &api_main;
629 
630 #define _(N,n) \
631  vl_msg_api_set_handlers(VL_API_##N, #n, \
632  vl_api_##n##_t_handler, \
633  vl_noop_handler, \
634  vl_api_##n##_t_endian, \
635  vl_api_##n##_t_print, \
636  sizeof(vl_api_##n##_t), 1);
638 #undef _
639 
640  /*
641  * Trace space for classifier mask+match
642  */
643  am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_TABLE].size += 5 * sizeof (u32x4);
644  am->api_trace_cfg[VL_API_CLASSIFY_ADD_DEL_SESSION].size +=
645  5 * sizeof (u32x4);
646 
647  /*
648  * Thread-safe API messages
649  */
650  am->is_mp_safe[VL_API_CONTROL_PING] = 1;
651  am->is_mp_safe[VL_API_CONTROL_PING_REPLY] = 1;
652  am->is_mp_safe[VL_API_IP_ROUTE_ADD_DEL] = 1;
653  am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
654 
655  /*
656  * Set up the (msg_name, crc, message-id) table
657  */
659 
660  return 0;
661 }
662 
664 
665 clib_error_t *
667 {
669 
670  am->vlib_main = vm;
671  am->vnet_main = vnet_get_main ();
672 #define _(a) \
673  am->a##_registration_hash = hash_create (0, sizeof (uword));
675 #undef _
676 
677  vl_set_memory_region_name ("/vpe-api");
678  vl_mem_api_enable_disable (vm, 1 /* enable it */ );
679 
680  return 0;
681 }
682 
683 static clib_error_t *
685 {
686  u8 *chroot_path;
687  u64 baseva, size, pvt_heap_size;
688  int uid, gid, rv;
689  const int max_buf_size = 4096;
690  char *s, *buf;
691  struct passwd _pw, *pw;
692  struct group _grp, *grp;
693  clib_error_t *e;
694  buf = vec_new (char, 128);
696  {
697  if (unformat (input, "prefix %s", &chroot_path))
698  {
699  vec_add1 (chroot_path, 0);
700  vl_set_memory_root_path ((char *) chroot_path);
701  }
702  else if (unformat (input, "uid %d", &uid))
703  vl_set_memory_uid (uid);
704  else if (unformat (input, "gid %d", &gid))
705  vl_set_memory_gid (gid);
706  else if (unformat (input, "baseva %llx", &baseva))
708  else if (unformat (input, "global-size %lldM", &size))
709  vl_set_global_memory_size (size * (1ULL << 20));
710  else if (unformat (input, "global-size %lldG", &size))
711  vl_set_global_memory_size (size * (1ULL << 30));
712  else if (unformat (input, "global-size %lld", &size))
714  else if (unformat (input, "global-pvt-heap-size %lldM", &pvt_heap_size))
715  vl_set_global_pvt_heap_size (pvt_heap_size * (1ULL << 20));
716  else if (unformat (input, "global-pvt-heap-size size %lld",
717  &pvt_heap_size))
718  vl_set_global_pvt_heap_size (pvt_heap_size);
719  else if (unformat (input, "api-pvt-heap-size %lldM", &pvt_heap_size))
720  vl_set_api_pvt_heap_size (pvt_heap_size * (1ULL << 20));
721  else if (unformat (input, "api-pvt-heap-size size %lld",
722  &pvt_heap_size))
723  vl_set_api_pvt_heap_size (pvt_heap_size);
724  else if (unformat (input, "api-size %lldM", &size))
725  vl_set_api_memory_size (size * (1ULL << 20));
726  else if (unformat (input, "api-size %lldG", &size))
727  vl_set_api_memory_size (size * (1ULL << 30));
728  else if (unformat (input, "api-size %lld", &size))
729  vl_set_api_memory_size (size);
730  else if (unformat (input, "uid %s", &s))
731  {
732  /* lookup the username */
733  pw = NULL;
734  while (((rv =
735  getpwnam_r (s, &_pw, buf, vec_len (buf), &pw)) == ERANGE)
736  && (vec_len (buf) <= max_buf_size))
737  {
738  vec_resize (buf, vec_len (buf) * 2);
739  }
740  if (rv < 0)
741  {
742  e = clib_error_return_code (0, rv,
745  "cannot fetch username %s", s);
746  vec_free (s);
747  vec_free (buf);
748  return e;
749  }
750  if (pw == NULL)
751  {
752  e =
753  clib_error_return_fatal (0, "username %s does not exist", s);
754  vec_free (s);
755  vec_free (buf);
756  return e;
757  }
758  vec_free (s);
759  vl_set_memory_uid (pw->pw_uid);
760  }
761  else if (unformat (input, "gid %s", &s))
762  {
763  /* lookup the group name */
764  grp = NULL;
765  while (((rv =
766  getgrnam_r (s, &_grp, buf, vec_len (buf),
767  &grp)) == ERANGE)
768  && (vec_len (buf) <= max_buf_size))
769  {
770  vec_resize (buf, vec_len (buf) * 2);
771  }
772  if (rv != 0)
773  {
774  e = clib_error_return_code (0, rv,
777  "cannot fetch group %s", s);
778  vec_free (s);
779  vec_free (buf);
780  return e;
781  }
782  if (grp == NULL)
783  {
784  e = clib_error_return_fatal (0, "group %s does not exist", s);
785  vec_free (s);
786  vec_free (buf);
787  return e;
788  }
789  vec_free (s);
790  vec_free (buf);
791  vl_set_memory_gid (grp->gr_gid);
792  }
793  else
794  return clib_error_return (0, "unknown input `%U'",
795  format_unformat_error, input);
796  }
797  return 0;
798 }
799 
801 
802 void *
804 {
805  return (void *) &unformat_vnet_sw_interface;
806 }
807 
808 static u8 *
809 format_arp_event (u8 * s, va_list * args)
810 {
811  vl_api_ip4_arp_event_t *event = va_arg (*args, vl_api_ip4_arp_event_t *);
812 
813  s = format (s, "pid %d: ", ntohl (event->pid));
814  s = format (s, "resolution for %U", format_vl_api_ip4_address, event->ip);
815  return s;
816 }
817 
818 static u8 *
819 format_nd_event (u8 * s, va_list * args)
820 {
821  vl_api_ip6_nd_event_t *event = va_arg (*args, vl_api_ip6_nd_event_t *);
822 
823  s = format (s, "pid %d: ", ntohl (event->pid));
824  s = format (s, "resolution for %U", format_vl_api_ip6_address, event->ip);
825  return s;
826 }
827 
828 static clib_error_t *
830  unformat_input_t * input, vlib_cli_command_t * cmd)
831 {
833  vl_api_ip4_arp_event_t *arp_event;
834  vl_api_ip6_nd_event_t *nd_event;
835 
836  if (pool_elts (am->arp_events) == 0 && pool_elts (am->nd_events) == 0 &&
837  pool_elts (am->wc_ip4_arp_events_registrations) == 0 &&
838  pool_elts (am->wc_ip6_nd_events_registrations) == 0)
839  {
840  vlib_cli_output (vm, "No active arp or nd event registrations");
841  return 0;
842  }
843 
844  /* *INDENT-OFF* */
845  pool_foreach (arp_event, am->arp_events,
846  ({
847  vlib_cli_output (vm, "%U", format_arp_event, arp_event);
848  }));
849 
851  pool_foreach(reg, am->wc_ip4_arp_events_registrations,
852  ({
853  vlib_cli_output (vm, "pid %d: bd mac/ip4 binding events",
854  ntohl (reg->client_pid));
855  }));
856 
857  pool_foreach (nd_event, am->nd_events,
858  ({
859  vlib_cli_output (vm, "%U", format_nd_event, nd_event);
860  }));
861 
862  pool_foreach(reg, am->wc_ip6_nd_events_registrations,
863  ({
864  vlib_cli_output (vm, "pid %d: bd mac/ip6 binding events",
865  ntohl (reg->client_pid));
866  }));
867  /* *INDENT-ON* */
868 
869  return 0;
870 }
871 
872 /* *INDENT-OFF* */
873 VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
874  .path = "show arp-nd-event registrations",
875  .function = show_ip_arp_nd_events_fn,
876  .short_help = "Show ip4 arp and ip6 nd event registrations",
877 };
878 /* *INDENT-ON* */
879 
880 #define vl_msg_name_crc_list
881 #include <vpp/api/vpe_all_api_h.h>
882 #undef vl_msg_name_crc_list
883 
884 static void
886 {
887 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
888  foreach_vl_msg_name_crc_memclnt;
889  foreach_vl_msg_name_crc_vpe;
890 #undef _
891 
892 #define vl_api_version_tuple(n,mj, mi, p) \
893  vl_msg_api_add_version (am, #n, mj, mi, p);
894 #include <vpp/api/vpe_all_api_h.h>
895 #undef vl_api_version_tuple
896 }
897 
898 
899 /*
900  * fd.io coding-style-patch-verification: ON
901  *
902  * Local Variables:
903  * eval: (c-set-style "gnu")
904  * End:
905  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
int vl_api_to_api_string(u32 len, const char *buf, vl_api_string_t *str)
Definition: api_shared.c:1060
static clib_error_t * memclnt_delete_callback(u32 client_index)
Definition: api.c:106
#define clib_min(x, y)
Definition: clib.h:302
vnet_main_t * vnet_main
static void svm_pop_heap(void *oldheap)
Definition: svm.h:94
Reply for get next node index.
Definition: vpe.api:281
vpe parser cli string response
Definition: vpe.api:103
string cmd[]
Definition: vpe.api:95
#define foreach_vpe_api_msg
Definition: api.c:78
show_threads_reply
Definition: vpe.api:233
void vl_set_global_memory_baseva(u64 baseva)
u32 client_index
Definition: vpe.api:289
vlib_log_entry_t * entries
Definition: log.h:71
static void vl_api_cli_t_handler(vl_api_cli_t *mp)
Definition: api.c:168
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
Optimized string handling code, including c11-compliant "safe C library" variants.
Control ping from client to api server request.
Definition: vpe.api:60
int size
for sanity checking
Definition: api_common.h:82
void vl_set_memory_uid(int uid)
unsigned long u64
Definition: types.h:89
int last_log_entry()
Definition: log.c:30
Fixed length block allocator.
void vl_set_global_pvt_heap_size(u64 size)
vl_api_thread_data_t thread_data[count]
Definition: vpe.api:238
#define REPLY_MACRO2(t, body)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:280
f64 types are not standardized across the wire.
Definition: vpe.api:329
VLIB_API_INIT_FUNCTION(vpe_api_hookup)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
static clib_error_t * api_segment_config(vlib_main_t *vm, unformat_input_t *input)
Definition: api.c:684
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
Verify f64 wire format by sending a value and receiving the value + 1.0.
Definition: vpe.api:353
int i
f64 timestamp
Definition: log.h:43
vlib_main_t * vlib_main
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unformat_function_t unformat_vnet_sw_interface
u8 * vlib_node_serialize(vlib_main_t *vm, vlib_node_t ***node_dups, u8 *vector, int include_nexts, int include_stats)
void * vl_msg_api_alloc(int nbytes)
u8 * format_vl_api_ip6_address(u8 *s, va_list *args)
Definition: types.c:77
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1092
unsigned char u8
Definition: types.h:56
trace_cfg_t * api_trace_cfg
Current trace configuration.
Definition: api_common.h:250
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
Process a vpe parser cli string request.
Definition: vpe.api:85
double f64
Definition: types.h:142
void vl_set_global_memory_size(u64 size)
resolve_t
Definition: api.c:96
#define clib_memcpy(d, s, n)
Definition: string.h:180
static void vl_api_get_f64_increment_by_one_t_handler(vl_api_get_f64_increment_by_one_t *mp)
Definition: api.c:572
static void vl_api_get_next_index_t_handler(vl_api_get_next_index_t *mp)
Definition: api.c:358
Get node index using name request.
Definition: vpe.api:133
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
static void vl_api_get_node_graph_t_handler(vl_api_get_node_graph_t *mp)
Definition: api.c:438
static void * svm_push_data_heap(svm_region_t *rp)
Definition: svm.h:86
u32 context
Definition: vpe.api:88
void vlib_node_get_nodes(vlib_main_t *vm, u32 max_threads, int include_stats, int barrier_sync, vlib_node_t ****node_dupsp, vlib_main_t ***stat_vmsp)
Get list of nodes.
Definition: node.c:551
vl_api_timestamp_t timestamp
Definition: vpe.api:296
struct timeval time_zero_timeval
Definition: log.h:85
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
Definition: vec.h:311
struct _vl_api_ip4_arp_event * arp_events
#define clib_error_return_fatal(e, args...)
Definition: error.h:105
static f64 unix_time_now(void)
Definition: time.h:255
#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
svm_region_t * vlib_rp
Current binary api segment descriptor.
Definition: api_common.h:256
get_node_graph_reply
Definition: vpe.api:255
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
Definition: vec.h:242
unsigned int u32
Definition: types.h:88
void unformat_init_string(unformat_input_t *input, char *string, int string_len)
Definition: unformat.c:1029
get_f64_endian_value reply message
Definition: vpe.api:341
f64 f64_one[default=1.0]
Definition: vpe.api:333
u64 cmd_in_shmem
Definition: vpe.api:89
void vl_set_memory_root_path(const char *name)
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:37
#define hash_get(h, key)
Definition: hash.h:249
uword size
vl_api_log_level_t level
Definition: vpe.api:297
static void shmem_cli_output(uword arg, u8 *buffer, uword buffer_bytes)
Definition: api.c:141
static void vl_api_get_node_index_t_handler(vl_api_get_node_index_t *mp)
Definition: api.c:334
char * vpe_api_get_version(void)
Return the image version string.
Definition: version.c:154
vl_api_timestamp_t start_timestamp
Definition: vpe.api:291
struct _unformat_input_t unformat_input_t
static u8 * format_nd_event(u8 *s, va_list *args)
Definition: api.c:819
int size
Definition: log.h:73
vlib_log_main_t log_main
Definition: log.c:21
u32 vl_api_string_len(vl_api_string_t *astr)
Definition: api_shared.c:1084
Tell client about an IP4 ARP resolution event or MAC/IP info from ARP requests in L2 BDs...
Definition: ip.api:767
void vl_set_api_pvt_heap_size(u64 size)
u32 client_index
Definition: vpe.api:87
#define REPLY_MACRO3(t, n, body)
struct _vl_api_ip6_nd_event * nd_events
u8 len
Definition: ip_types.api:90
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:203
IP Set the next node for a given node response.
Definition: vpe.api:159
Get node index using name request.
Definition: vpe.api:121
void unformat_init_vector(unformat_input_t *input, u8 *vector_string)
Definition: unformat.c:1037
string build_directory[256]
Definition: vpe.api:190
static void vl_api_add_node_next_t_handler(vl_api_add_node_next_t *mp)
Definition: api.c:405
An API client registration, only in vpp/vlib.
Definition: api_common.h:46
void vl_mem_api_enable_disable(vlib_main_t *vm, int yesno)
Definition: vlib_api.c:433
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
Definition: init.h:226
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
vlib_main_t * vm
Definition: buffer.c:323
static void vl_api_log_dump_t_handler(vl_api_log_dump_t *mp)
Definition: api.c:508
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
clib_error_t * vpe_api_init(vlib_main_t *vm)
Definition: api.c:666
string msg_class[32]
Definition: vpe.api:298
#define clib_warning(format, args...)
Definition: error.h:59
char * vpe_api_get_build_directory(void)
Return the image build directory name.
Definition: version.c:147
get_f64_increment_by_one reply
Definition: vpe.api:365
void vl_set_memory_gid(int gid)
static void inband_cli_output(uword arg, u8 *buffer, uword buffer_bytes)
Definition: api.c:204
static void vl_api_show_version_t_handler(vl_api_show_version_t *mp)
Definition: api.c:249
thread data
Definition: vpe.api:216
Reply for show vpe system time.
Definition: vpe.api:317
static void show_log_details(vl_api_registration_t *reg, u32 context, f64 timestamp, vl_api_log_level_t *level, u8 *msg_class, u8 *message)
Definition: api.c:477
#define ARRAY_LEN(x)
Definition: clib.h:63
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:57
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:161
vl_api_timestamp_t vpe_system_time
Definition: vpe.api:321
static void vl_api_get_f64_endian_value_t_handler(vl_api_get_f64_endian_value_t *mp)
Definition: api.c:555
Definition: log.h:39
#define ASSERT(truth)
static clib_error_t * show_ip_arp_nd_events_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: api.c:829
u8 * format_vl_api_ip4_address(u8 *s, va_list *args)
Definition: types.c:67
vlib_log_class_t class
Definition: log.h:42
static void vl_api_cli_inband_t_handler(vl_api_cli_inband_t *mp)
Definition: api.c:216
static void setup_message_id_table(api_main_t *am)
Definition: api.c:885
static f64 clib_net_to_host_f64(f64 x)
Definition: byte_order.h:215
int count
Definition: log.h:73
Control ping from the client to the server response.
Definition: vpe.api:72
f64 f64_value[default=1.0]
Definition: vpe.api:357
void vl_set_memory_region_name(const char *name)
Definition: memory_api.c:1012
static f64 clib_host_to_net_f64(f64 x)
Definition: byte_order.h:216
Bitmaps built as vectors of machine words.
Set the next node for a given node request.
Definition: vpe.api:146
uword * next_slot_by_node
Definition: node.h:349
Query relative index via node names.
Definition: vpe.api:268
show version
Definition: vpe.api:170
size_t count
Definition: vapi.c:47
static void vl_api_show_vpe_system_time_t_handler(vl_api_show_vpe_system_time_t *mp)
Definition: api.c:542
static void vl_api_show_threads_t_handler(vl_api_show_threads_t *mp)
Definition: api.c:288
Show the current system timestamp.
Definition: vpe.api:306
int vlib_cli_input(vlib_main_t *vm, unformat_input_t *input, vlib_cli_output_function_t *function, uword function_arg)
Definition: cli.c:730
VL_MSG_API_REAPER_FUNCTION(memclnt_delete_callback)
vlib_log_level_t level
Definition: log.h:41
f64 time_zero
Definition: log.h:86
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
template key/value backing page structure
Definition: bihash_doc.h:44
string message[256]
Definition: vpe.api:299
u64 reply_in_shmem
Definition: vpe.api:107
u8 * format_vlib_log_class(u8 *s, va_list *args)
Definition: log.c:73
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void * get_unformat_vnet_sw_interface(void)
Definition: api.c:803
u64 uword
Definition: types.h:112
static u8 * format_arp_event(u8 *s, va_list *args)
Definition: api.c:809
static void get_thread_data(vl_api_thread_data_t *td, int index)
Definition: api.c:272
show version response
Definition: vpe.api:183
vpe_api_main_t vpe_api_main
Definition: interface_api.c:49
Tell client about an IP6 ND resolution or MAC/IP info from ICMP6 Neighbor Solicitation in L2 BDs...
Definition: ip.api:809
static void vl_api_control_ping_t_handler(vl_api_control_ping_t *mp)
Definition: api.c:127
struct clib_bihash_value offset
template key/value backing page structure
f64 timestamp
Definition: vpe_types.api:29
u8 * vl_api_from_api_string(vl_api_string_t *astr)
Definition: api_shared.c:1078
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
char * vpe_api_get_build_date(void)
return the build date
Definition: version.c:161
void vl_set_api_memory_size(u64 size)
u8 * is_mp_safe
Message is mp safe vector.
Definition: api_common.h:226
#define clib_error_return_code(e, code, flags, args...)
Definition: error.h:93
unsigned long long u32x4
Definition: ixge.c:28
u32 vl_msg_api_get_msg_length(void *msg_arg)
Definition: api_shared.c:719
u8 * string
Definition: log.h:44
vlib_thread_registration_t * registration
Definition: threads.h:102
u32 context
Definition: gre.api:45
api_main_t api_main
Definition: api_shared.c:35
static clib_error_t * vpe_api_hookup(vlib_main_t *vm)
Definition: api.c:626
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:772
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
#define foreach_registration_hash
pthread_mutex_t mutex
Definition: svm_common.h:37
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
show_threads display the information about vpp threads running on system along with their process id...
Definition: vpe.api:198
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128