2 *------------------------------------------------------------------
3 * api_shared.c - API message handling, common code for both clients
4 * and the vlib process itself.
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:
12 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
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>
35 api_main_t api_global_main =
37 .region_name = "/unset",
43 /* Please use vlibapi_get_main() to access my_api_main */
44 __thread api_main_t *my_api_main = &api_global_main;
47 vl_msg_api_set_global_main (void *am_arg)
50 my_api_main = (api_main_t *) am_arg;
54 vl_msg_api_increment_missing_client_counter (void)
56 api_main_t *am = vlibapi_get_main ();
57 am->missing_clients++;
61 vl_msg_api_rx_trace_enabled (api_main_t * am)
63 return (am->rx_trace && am->rx_trace->enabled);
67 vl_msg_api_tx_trace_enabled (api_main_t * am)
69 return (am->tx_trace && am->tx_trace->enabled);
76 vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg)
83 u16 msg_id = clib_net_to_host_u16 (*((u16 *) msg));
84 msgbuf_t *header = (msgbuf_t *) (((u8 *) msg) - offsetof (msgbuf_t, data));
86 cfgp = am->api_trace_cfg + msg_id;
88 if (!cfgp || !cfgp->trace_enable)
95 clib_warning ("tp->nitems is 0");
99 if (vec_len (tp->traces) < tp->nitems)
101 vec_add1 (tp->traces, 0);
102 this_trace = tp->traces + vec_len (tp->traces) - 1;
107 old_trace = tp->traces + tp->curindex++;
108 if (tp->curindex == tp->nitems)
110 /* Reuse the trace record, may save some memory allocator traffic */
111 msg_copy = *old_trace;
112 vec_reset_length (msg_copy);
113 this_trace = old_trace;
116 length = clib_net_to_host_u32 (header->data_len);
118 vec_validate (msg_copy, length - 1);
119 clib_memcpy_fast (msg_copy, msg, length);
120 *this_trace = msg_copy;
124 vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which,
132 case VL_API_TRACE_TX:
136 vl_msg_api_trace_configure (am, which, 1024);
141 case VL_API_TRACE_RX:
145 vl_msg_api_trace_configure (am, which, 1024);
156 if (tp == 0 || tp->nitems == 0)
166 vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which)
173 case VL_API_TRACE_TX:
177 case VL_API_TRACE_RX:
187 if (!tp || tp->nitems == 0)
193 for (i = 0; i < vec_len (tp->traces); i++)
195 vec_free (tp->traces[i]);
197 vec_free (tp->traces);
203 vl_api_serialize_message_table (api_main_t * am, u8 * vector)
205 serialize_main_t _sm, *sm = &_sm;
207 u32 nmsg = hash_elts (am->msg_index_by_name_and_crc);
209 serialize_open_vector (sm, vector);
211 /* serialize the count */
212 serialize_integer (sm, nmsg, sizeof (u32));
215 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
217 serialize_likely_small_unsigned_integer (sm, hp->value[0]);
218 serialize_cstring (sm, (char *) hp->key);
222 return serialize_close_vector (sm);
226 vl_msg_api_trace_save (api_main_t * am, vl_api_trace_which_t which, FILE * fp)
229 vl_api_trace_file_header_t fh;
235 case VL_API_TRACE_TX:
239 case VL_API_TRACE_RX:
248 /* Configured, data present? */
249 if (tp == 0 || tp->nitems == 0 || vec_len (tp->traces) == 0)
252 /* "Dare to be stupid" check */
258 /* Write the file header */
259 fh.wrapped = tp->wrapped;
260 fh.nitems = clib_host_to_net_u32 (vec_len (tp->traces));
261 u8 *m = vl_api_serialize_message_table (am, 0);
262 fh.msgtbl_size = clib_host_to_net_u32 (vec_len (m));
264 if (fwrite (&fh, sizeof (fh), 1, fp) != 1)
269 /* Write the message table */
270 if (fwrite (m, vec_len (m), 1, fp) != 1)
277 if (tp->wrapped == 0)
280 * Note: vec_len return 0 when fed a NULL pointer.
281 * Unfortunately, the static analysis tool doesn't
282 * figure it out, hence the suppressed warnings.
283 * What a great use of my time.
285 for (i = 0; i < vec_len (tp->traces); i++)
288 /*sa_ignore NO_NULL_CHK */
291 * This retarded check required to pass
297 msg_length = clib_host_to_net_u32 (vec_len (msg));
298 if (fwrite (&msg_length, 1, sizeof (msg_length), fp)
299 != sizeof (msg_length))
303 if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
311 /* Wrap case: write oldest -> end of buffer */
312 for (i = tp->curindex; i < vec_len (tp->traces); i++)
317 * This retarded check required to pass
323 msg_length = clib_host_to_net_u32 (vec_len (msg));
324 if (fwrite (&msg_length, 1, sizeof (msg_length), fp)
325 != sizeof (msg_length))
330 if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
335 /* write beginning of buffer -> oldest-1 */
336 for (i = 0; i < tp->curindex; i++)
339 /*sa_ignore NO_NULL_CHK */
342 * This retarded check required to pass
348 msg_length = clib_host_to_net_u32 (vec_len (msg));
349 if (fwrite (&msg_length, 1, sizeof (msg_length), fp)
350 != sizeof (msg_length))
355 if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
365 vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which,
373 case VL_API_TRACE_TX:
377 vec_validate (am->tx_trace, 0);
382 case VL_API_TRACE_RX:
386 vec_validate (am->rx_trace, 0);
399 was_on = vl_msg_api_trace_onoff (am, which, 0);
403 vl_msg_api_trace_free (am, which);
406 clib_memset (tp, 0, sizeof (*tp));
408 if (clib_arch_is_big_endian)
410 tp->endian = VL_API_BIG_ENDIAN;
414 tp->endian = VL_API_LITTLE_ENDIAN;
420 (void) vl_msg_api_trace_onoff (am, which, was_on);
426 vl_msg_api_barrier_sync (void)
431 vl_msg_api_barrier_release (void)
436 msg_handler_internal (api_main_t * am,
437 void *the_msg, int trace_it, int do_it, int free_it)
439 u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
440 u8 *(*print_fp) (void *, void *);
442 if (PREDICT_FALSE (am->elog_trace_api_messages))
445 ELOG_TYPE_DECLARE (e) =
447 .format = "api-msg: %s",
455 ed = ELOG_DATA (am->elog_main, e);
456 if (id < vec_len (am->msg_names))
457 ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
459 ed->c = elog_string (am->elog_main, "BOGUS");
462 if (id < vec_len (am->msg_handlers) && am->msg_handlers[id])
465 vl_msg_api_trace (am, am->rx_trace, the_msg);
467 if (am->msg_print_flag)
469 fformat (stdout, "[%d]: %s\n", id, am->msg_names[id]);
470 print_fp = (void *) am->msg_print_handlers[id];
473 fformat (stdout, " [no registered print fn]\n");
477 (*print_fp) (the_msg, stdout);
483 if (!am->is_mp_safe[id])
485 vl_msg_api_barrier_trace_context (am->msg_names[id]);
486 vl_msg_api_barrier_sync ();
489 if (am->is_autoendian[id])
491 void (*endian_fp) (void *);
492 endian_fp = am->msg_endian_handlers[id];
493 (*endian_fp) (the_msg);
496 (*am->msg_handlers[id]) (the_msg);
497 if (!am->is_mp_safe[id])
498 vl_msg_api_barrier_release ();
503 clib_warning ("no handler for msg id %d", id);
507 vl_msg_api_free (the_msg);
509 if (PREDICT_FALSE (am->elog_trace_api_messages))
512 ELOG_TYPE_DECLARE (e) =
514 .format = "api-msg-done(%s): %s",
515 .format_args = "t4T4",
530 ed = ELOG_DATA (am->elog_main, e);
531 if (id < vec_len (am->msg_names))
533 ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
534 ed->barrier = !am->is_mp_safe[id];
538 ed->c = elog_string (am->elog_main, "BOGUS");
544 void (*vl_msg_api_fuzz_hook) (u16, void *);
546 /* This is only to be called from a vlib/vnet app */
548 vl_msg_api_handler_with_vm_node (api_main_t * am, svm_region_t * vlib_rp,
549 void *the_msg, vlib_main_t * vm,
550 vlib_node_runtime_t * node, u8 is_private)
552 u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
553 u8 *(*handler) (void *, void *, void *);
554 u8 *(*print_fp) (void *, void *);
555 svm_region_t *old_vlib_rp;
556 void *save_shmem_hdr;
559 if (PREDICT_FALSE (am->elog_trace_api_messages))
562 ELOG_TYPE_DECLARE (e) =
564 .format = "api-msg: %s",
572 ed = ELOG_DATA (am->elog_main, e);
573 if (id < vec_len (am->msg_names))
574 ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
576 ed->c = elog_string (am->elog_main, "BOGUS");
579 if (id < vec_len (am->msg_handlers) && am->msg_handlers[id])
581 handler = (void *) am->msg_handlers[id];
583 if (PREDICT_FALSE (am->rx_trace && am->rx_trace->enabled))
584 vl_msg_api_trace (am, am->rx_trace, the_msg);
586 if (PREDICT_FALSE (am->msg_print_flag))
588 fformat (stdout, "[%d]: %s\n", id, am->msg_names[id]);
589 print_fp = (void *) am->msg_print_handlers[id];
592 fformat (stdout, " [no registered print fn for msg %d]\n", id);
596 (*print_fp) (the_msg, vm);
599 is_mp_safe = am->is_mp_safe[id];
603 vl_msg_api_barrier_trace_context (am->msg_names[id]);
604 vl_msg_api_barrier_sync ();
608 old_vlib_rp = am->vlib_rp;
609 save_shmem_hdr = am->shmem_hdr;
610 am->vlib_rp = vlib_rp;
611 am->shmem_hdr = (void *) vlib_rp->user_ctx;
614 if (PREDICT_FALSE (vl_msg_api_fuzz_hook != 0))
615 (*vl_msg_api_fuzz_hook) (id, the_msg);
617 if (am->is_autoendian[id])
619 void (*endian_fp) (void *);
620 endian_fp = am->msg_endian_handlers[id];
621 (*endian_fp) (the_msg);
624 (*handler) (the_msg, vm, node);
627 am->vlib_rp = old_vlib_rp;
628 am->shmem_hdr = save_shmem_hdr;
631 vl_msg_api_barrier_release ();
635 clib_warning ("no handler for msg id %d", id);
639 * Special-case, so we can e.g. bounce messages off the vnet
640 * main thread without copying them...
642 if (id >= vec_len (am->message_bounce) || !(am->message_bounce[id]))
643 vl_msg_api_free (the_msg);
645 if (PREDICT_FALSE (am->elog_trace_api_messages))
648 ELOG_TYPE_DECLARE (e) =
650 .format = "api-msg-done(%s): %s",
651 .format_args = "t4T4",
666 ed = ELOG_DATA (am->elog_main, e);
667 if (id < vec_len (am->msg_names))
668 ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
670 ed->c = elog_string (am->elog_main, "BOGUS");
671 ed->barrier = is_mp_safe;
676 vl_msg_api_handler (void *the_msg)
678 api_main_t *am = vlibapi_get_main ();
680 msg_handler_internal (am, the_msg,
682 && am->rx_trace->enabled) /* trace_it */ ,
683 1 /* do_it */ , 1 /* free_it */ );
687 vl_msg_api_handler_no_free (void *the_msg)
689 api_main_t *am = vlibapi_get_main ();
690 msg_handler_internal (am, the_msg,
692 && am->rx_trace->enabled) /* trace_it */ ,
693 1 /* do_it */ , 0 /* free_it */ );
697 vl_msg_api_handler_no_trace_no_free (void *the_msg)
699 api_main_t *am = vlibapi_get_main ();
700 msg_handler_internal (am, the_msg, 0 /* trace_it */ , 1 /* do_it */ ,
705 * Add a trace record to the API message trace buffer, if
706 * API message tracing is enabled. Handy for adding sufficient
707 * data to the trace to reproduce autonomous state, as opposed to
708 * state downloaded via control-plane API messages. Example: the NAT
709 * application creates database entries based on packet traffic, not
710 * control-plane messages.
714 vl_msg_api_trace_only (void *the_msg)
716 api_main_t *am = vlibapi_get_main ();
718 msg_handler_internal (am, the_msg,
720 && am->rx_trace->enabled) /* trace_it */ ,
721 0 /* do_it */ , 0 /* free_it */ );
725 vl_msg_api_cleanup_handler (void *the_msg)
727 api_main_t *am = vlibapi_get_main ();
728 u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
730 if (PREDICT_FALSE (id >= vec_len (am->msg_cleanup_handlers)))
732 clib_warning ("_vl_msg_id too large: %d\n", id);
735 if (am->msg_cleanup_handlers[id])
736 (*am->msg_cleanup_handlers[id]) (the_msg);
738 vl_msg_api_free (the_msg);
742 * vl_msg_api_replay_handler
745 vl_msg_api_replay_handler (void *the_msg)
747 api_main_t *am = vlibapi_get_main ();
749 u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
751 if (PREDICT_FALSE (id >= vec_len (am->msg_handlers)))
753 clib_warning ("_vl_msg_id too large: %d\n", id);
756 /* do NOT trace the message... */
757 if (am->msg_handlers[id])
758 (*am->msg_handlers[id]) (the_msg);
759 /* do NOT free the message buffer... */
763 vl_msg_api_get_msg_length (void *msg_arg)
765 return vl_msg_api_get_msg_length_inline (msg_arg);
769 * vl_msg_api_socket_handler
772 vl_msg_api_socket_handler (void *the_msg)
774 api_main_t *am = vlibapi_get_main ();
776 msg_handler_internal (am, the_msg,
778 && am->rx_trace->enabled) /* trace_it */ ,
779 1 /* do_it */ , 0 /* free_it */ );
782 #define foreach_msg_api_vector \
785 _(msg_cleanup_handlers) \
786 _(msg_endian_handlers) \
787 _(msg_print_handlers) \
794 vl_msg_api_config (vl_msg_api_msg_config_t * c)
796 api_main_t *am = vlibapi_get_main ();
799 * This happens during the java core tests if the message
800 * dictionary is missing newly added xxx_reply_t messages.
801 * Should never happen, but since I shot myself in the foot once
802 * this way, I thought I'd make it easy to debug if I ever do
803 * it again... (;-)...
808 clib_warning ("Trying to register %s with a NULL msg id!", c->name);
810 clib_warning ("Trying to register a NULL msg with a NULL msg id!");
811 clib_warning ("Did you forget to call setup_message_id_table?");
815 #define _(a) vec_validate (am->a, c->id);
816 foreach_msg_api_vector;
819 if (am->msg_handlers[c->id] && am->msg_handlers[c->id] != c->handler)
821 ("BUG: re-registering 'vl_api_%s_t_handler'."
822 "Handler was %llx, replaced by %llx",
823 c->name, am->msg_handlers[c->id], c->handler);
825 am->msg_names[c->id] = c->name;
826 am->msg_handlers[c->id] = c->handler;
827 am->msg_cleanup_handlers[c->id] = c->cleanup;
828 am->msg_endian_handlers[c->id] = c->endian;
829 am->msg_print_handlers[c->id] = c->print;
830 am->message_bounce[c->id] = c->message_bounce;
831 am->is_mp_safe[c->id] = c->is_mp_safe;
832 am->is_autoendian[c->id] = c->is_autoendian;
834 am->api_trace_cfg[c->id].size = c->size;
835 am->api_trace_cfg[c->id].trace_enable = c->traced;
836 am->api_trace_cfg[c->id].replay_enable = c->replay;
840 * vl_msg_api_set_handlers
841 * preserve the old API for a while
844 vl_msg_api_set_handlers (int id, char *name, void *handler, void *cleanup,
845 void *endian, void *print, int size, int traced)
847 vl_msg_api_msg_config_t cfg;
848 vl_msg_api_msg_config_t *c = &cfg;
850 clib_memset (c, 0, sizeof (*c));
854 c->handler = handler;
855 c->cleanup = cleanup;
860 c->message_bounce = 0;
862 c->is_autoendian = 0;
863 vl_msg_api_config (c);
867 vl_msg_api_clean_handlers (int msg_id)
869 vl_msg_api_msg_config_t cfg;
870 vl_msg_api_msg_config_t *c = &cfg;
872 clib_memset (c, 0, sizeof (*c));
875 vl_msg_api_config (c);
879 vl_msg_api_set_cleanup_handler (int msg_id, void *fp)
881 api_main_t *am = vlibapi_get_main ();
884 vec_validate (am->msg_cleanup_handlers, msg_id);
885 am->msg_cleanup_handlers[msg_id] = fp;
889 vl_msg_api_queue_handler (svm_queue_t * q)
893 while (!svm_queue_sub (q, (u8 *) & msg, SVM_Q_WAIT, 0))
894 vl_msg_api_handler ((void *) msg);
898 vl_msg_api_max_length (void *mp)
903 /* Work out the maximum sane message length, and return it */
904 if (PREDICT_TRUE (mp != 0))
906 mb = (msgbuf_t *) (((u8 *) mp) - offsetof (msgbuf_t, data));
907 data_len = clib_net_to_host_u32 (mb->data_len);
913 vl_msg_api_trace_get (api_main_t * am, vl_api_trace_which_t which)
917 case VL_API_TRACE_RX:
919 case VL_API_TRACE_TX:
927 vl_noop_handler (void *mp)
932 static u8 post_mortem_dump_enabled;
935 vl_msg_api_post_mortem_dump_enable_disable (int enable)
937 post_mortem_dump_enabled = enable;
941 vl_msg_api_post_mortem_dump (void)
943 api_main_t *am = vlibapi_get_main ();
948 if (post_mortem_dump_enabled == 0)
951 snprintf (filename, sizeof (filename), "/tmp/api_post_mortem.%d",
954 fp = fopen (filename, "w");
957 rv = write (2, "Couldn't create ", 16);
958 rv = write (2, filename, strlen (filename));
959 rv = write (2, "\n", 1);
962 rv = vl_msg_api_trace_save (am, VL_API_TRACE_RX, fp);
966 rv = write (2, "Failed to save post-mortem API trace to ", 40);
967 rv = write (2, filename, strlen (filename));
968 rv = write (2, "\n", 1);
973 /* Layered message handling support */
976 vl_msg_api_register_pd_handler (void *fp, u16 msg_id_host_byte_order)
978 api_main_t *am = vlibapi_get_main ();
980 /* Mild idiot proofing */
981 if (msg_id_host_byte_order > 10000)
982 clib_warning ("msg_id_host_byte_order endian issue? %d arg vs %d",
983 msg_id_host_byte_order,
984 clib_net_to_host_u16 (msg_id_host_byte_order));
985 vec_validate (am->pd_msg_handlers, msg_id_host_byte_order);
986 am->pd_msg_handlers[msg_id_host_byte_order] = fp;
990 vl_msg_api_pd_handler (void *mp, int rv)
992 api_main_t *am = vlibapi_get_main ();
993 int (*fp) (void *, int);
996 if (clib_arch_is_little_endian)
997 msg_id = clib_net_to_host_u16 (*((u16 *) mp));
999 msg_id = *((u16 *) mp);
1001 if (msg_id >= vec_len (am->pd_msg_handlers)
1002 || am->pd_msg_handlers[msg_id] == 0)
1005 fp = am->pd_msg_handlers[msg_id];
1006 rv = (*fp) (mp, rv);
1011 vl_msg_api_set_first_available_msg_id (u16 first_avail)
1013 api_main_t *am = vlibapi_get_main ();
1015 am->first_available_msg_id = first_avail;
1019 vl_msg_api_get_msg_ids (const char *name, int n)
1021 api_main_t *am = vlibapi_get_main ();
1023 vl_api_msg_range_t *rp;
1027 if (am->msg_range_by_name == 0)
1028 am->msg_range_by_name = hash_create_string (0, sizeof (uword));
1030 name_copy = format (0, "%s%c", name, 0);
1032 p = hash_get_mem (am->msg_range_by_name, name_copy);
1035 clib_warning ("WARNING: duplicate message range registration for '%s'",
1037 vec_free (name_copy);
1041 if (n < 0 || n > 1024)
1044 ("WARNING: bad number of message-IDs (%d) requested by '%s'",
1046 vec_free (name_copy);
1050 vec_add2 (am->msg_ranges, rp, 1);
1052 rv = rp->first_msg_id = am->first_available_msg_id;
1053 am->first_available_msg_id += n;
1054 rp->last_msg_id = am->first_available_msg_id - 1;
1055 rp->name = name_copy;
1057 hash_set_mem (am->msg_range_by_name, name_copy, rp - am->msg_ranges);
1063 vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string, u32 id)
1067 if (am->msg_index_by_name_and_crc == 0)
1068 am->msg_index_by_name_and_crc = hash_create_string (0, sizeof (uword));
1070 p = hash_get_mem (am->msg_index_by_name_and_crc, string);
1073 clib_warning ("attempt to redefine '%s' ignored...", string);
1077 hash_set_mem (am->msg_index_by_name_and_crc, string, id);
1081 vl_msg_api_add_version (api_main_t * am, const char *string,
1082 u32 major, u32 minor, u32 patch)
1084 api_version_t version = {.major = major,.minor = minor,.patch = patch };
1085 ASSERT (strlen (string) < 64);
1086 strncpy (version.name, string, 64 - 1);
1087 vec_add1 (am->api_version_list, version);
1091 vl_msg_api_get_msg_index (u8 * name_and_crc)
1093 api_main_t *am = vlibapi_get_main ();
1096 if (am->msg_index_by_name_and_crc)
1098 p = hash_get_mem (am->msg_index_by_name_and_crc, name_and_crc);
1106 vl_msg_push_heap_w_region (svm_region_t * vlib_rp)
1108 pthread_mutex_lock (&vlib_rp->mutex);
1109 return svm_push_data_heap (vlib_rp);
1113 vl_msg_push_heap (void)
1115 api_main_t *am = vlibapi_get_main ();
1116 return vl_msg_push_heap_w_region (am->vlib_rp);
1120 vl_msg_pop_heap_w_region (svm_region_t * vlib_rp, void *oldheap)
1122 svm_pop_heap (oldheap);
1123 pthread_mutex_unlock (&vlib_rp->mutex);
1127 vl_msg_pop_heap (void *oldheap)
1129 api_main_t *am = vlibapi_get_main ();
1130 vl_msg_pop_heap_w_region (am->vlib_rp, oldheap);
1133 /* Must be nul terminated */
1135 vl_api_c_string_to_api_string (const char *buf, vl_api_string_t * str)
1137 /* copy without nul terminator */
1138 u32 len = strlen (buf);
1140 clib_memcpy_fast (str->buf, buf, len);
1141 str->length = htonl (len);
1142 return len + sizeof (u32);
1145 /* Must NOT be nul terminated */
1147 vl_api_vec_to_api_string (const u8 * vec, vl_api_string_t * str)
1149 u32 len = vec_len (vec);
1150 clib_memcpy (str->buf, vec, len);
1151 str->length = htonl (len);
1152 return len + sizeof (u32);
1156 vl_api_string_len (vl_api_string_t * astr)
1158 return clib_net_to_host_u32 (astr->length);
1162 vl_api_format_string (u8 * s, va_list * args)
1164 vl_api_string_t *a = va_arg (*args, vl_api_string_t *);
1165 vec_add (s, a->buf, clib_net_to_host_u32 (a->length));
1170 * Returns a new vector. Remember to free it after use.
1171 * NOT nul terminated.
1174 vl_api_from_api_to_new_vec (void *mp, vl_api_string_t * astr)
1178 if (vl_msg_api_max_length (mp) < clib_net_to_host_u32 (astr->length))
1179 return format (0, "insane astr->length %u%c",
1180 clib_net_to_host_u32 (astr->length), 0);
1181 vec_add (v, astr->buf, clib_net_to_host_u32 (astr->length));
1186 * Returns a new vector. Remember to free it after use.
1190 vl_api_from_api_to_new_c_string (vl_api_string_t * astr)
1193 if (clib_net_to_host_u32 (astr->length) > 0)
1195 vec_add (v, astr->buf, clib_net_to_host_u32 (astr->length));
1202 vl_api_set_elog_main (elog_main_t * m)
1204 api_main_t *am = vlibapi_get_main ();
1209 vl_api_set_elog_trace_api_messages (int enable)
1212 api_main_t *am = vlibapi_get_main ();
1214 rv = am->elog_trace_api_messages;
1215 am->elog_trace_api_messages = enable;
1220 vl_api_get_elog_trace_api_messages (void)
1222 api_main_t *am = vlibapi_get_main ();
1224 return am->elog_trace_api_messages;
1228 * fd.io coding-style-patch-verification: ON
1231 * eval: (c-set-style "gnu")