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>
33 #include <vppinfra/callback.h>
36 static 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_write_one (api_main_t *am, u8 *msg, FILE *fp)
230 cJSON *(*tojson_fn) (void *);
232 u32 msg_length = vec_len (msg);
233 vec_validate (tmpmem, msg_length - 1);
234 clib_memcpy_fast (tmpmem, msg, msg_length);
235 u16 id = clib_net_to_host_u16 (*((u16 *) msg));
237 void (*endian_fp) (void *);
238 endian_fp = am->msg_endian_handlers[id];
239 (*endian_fp) (tmpmem);
241 if (id < vec_len (am->msg_tojson_handlers) && am->msg_tojson_handlers[id])
243 tojson_fn = am->msg_tojson_handlers[id];
244 cJSON *o = tojson_fn (tmpmem);
245 char *s = cJSON_Print (o);
247 tlen = fwrite (s, 1, slen, fp);
253 fformat (stderr, "writing to file error\n");
258 fformat (stderr, " [no registered tojson fn]\n");
263 #define vl_msg_fwrite(_s, _f) fwrite (_s, 1, sizeof (_s) - 1, _f)
270 } vl_msg_write_json_args_t;
273 vl_msg_write_json_fn (u8 *msg, void *ctx)
275 vl_msg_write_json_args_t *arg = ctx;
277 api_main_t *am = vlibapi_get_main ();
278 int rc = vl_msg_api_trace_write_one (am, msg, fp);
282 if (arg->i < arg->n_traces - 1)
283 vl_msg_fwrite (",\n", fp);
289 vl_msg_api_trace_write_json (api_main_t *am, vl_api_trace_t *tp, FILE *fp)
291 vl_msg_write_json_args_t args;
292 clib_memset (&args, 0, sizeof (args));
294 args.n_traces = vec_len (tp->traces);
295 vl_msg_fwrite ("[\n", fp);
297 int rv = vl_msg_traverse_trace (tp, vl_msg_write_json_fn, &args);
301 vl_msg_fwrite ("]", fp);
306 vl_msg_traverse_trace (vl_api_trace_t *tp, vl_msg_traverse_trace_fn fn,
314 if (tp->wrapped == 0)
316 for (i = 0; i < vec_len (tp->traces); i++)
318 /*sa_ignore NO_NULL_CHK */
330 /* Wrap case: write oldest -> end of buffer */
331 for (i = tp->curindex; i < vec_len (tp->traces); i++)
341 /* write beginning of buffer -> oldest-1 */
342 for (i = 0; i < tp->curindex; i++)
344 /*sa_ignore NO_NULL_CHK */
358 vl_api_msg_write_fn (u8 *msg, void *ctx)
361 u32 msg_length = clib_host_to_net_u32 (vec_len (msg));
362 if (fwrite (&msg_length, 1, sizeof (msg_length), fp) != sizeof (msg_length))
366 if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
374 vl_msg_api_trace_save (api_main_t *am, vl_api_trace_which_t which, FILE *fp,
378 vl_api_trace_file_header_t fh;
382 case VL_API_TRACE_TX:
386 case VL_API_TRACE_RX:
395 /* Configured, data present? */
396 if (tp == 0 || tp->nitems == 0 || vec_len (tp->traces) == 0)
399 /* "Dare to be stupid" check */
406 return vl_msg_api_trace_write_json (am, tp, fp);
408 /* Write the file header */
409 fh.wrapped = tp->wrapped;
410 fh.nitems = clib_host_to_net_u32 (vec_len (tp->traces));
412 u8 *m = vl_api_serialize_message_table (am, 0);
413 fh.msgtbl_size = clib_host_to_net_u32 (vec_len (m));
415 if (fwrite (&fh, sizeof (fh), 1, fp) != 1)
420 /* Write the message table */
421 if (fwrite (m, vec_len (m), 1, fp) != 1)
427 return vl_msg_traverse_trace (tp, vl_api_msg_write_fn, fp);
431 vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which,
439 case VL_API_TRACE_TX:
443 vec_validate (am->tx_trace, 0);
448 case VL_API_TRACE_RX:
452 vec_validate (am->rx_trace, 0);
465 was_on = vl_msg_api_trace_onoff (am, which, 0);
469 vl_msg_api_trace_free (am, which);
472 clib_memset (tp, 0, sizeof (*tp));
474 if (clib_arch_is_big_endian)
476 tp->endian = VL_API_BIG_ENDIAN;
480 tp->endian = VL_API_LITTLE_ENDIAN;
486 (void) vl_msg_api_trace_onoff (am, which, was_on);
492 vl_msg_api_barrier_sync (void)
497 vl_msg_api_barrier_release (void)
502 msg_handler_internal (api_main_t *am, void *the_msg, uword msg_len,
503 int trace_it, int do_it, int free_it)
505 u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
506 u8 *(*print_fp) (void *, void *);
508 if (PREDICT_FALSE (am->elog_trace_api_messages))
511 ELOG_TYPE_DECLARE (e) =
513 .format = "api-msg: %s",
521 ed = ELOG_DATA (am->elog_main, e);
522 if (id < vec_len (am->msg_names) && am->msg_names[id])
523 ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
525 ed->c = elog_string (am->elog_main, "BOGUS");
528 if (id < vec_len (am->msg_handlers) && am->msg_handlers[id])
531 vl_msg_api_trace (am, am->rx_trace, the_msg);
533 if (am->msg_print_flag)
535 fformat (stdout, "[%d]: %s\n", id, am->msg_names[id]);
536 print_fp = (void *) am->msg_print_handlers[id];
539 fformat (stdout, " [no registered print fn]\n");
543 (*print_fp) (the_msg, stdout);
548 uword (*calc_size_fp) (void *);
549 calc_size_fp = am->msg_calc_size_funcs[id];
550 ASSERT (NULL != calc_size_fp);
553 calc_size = (*calc_size_fp) (the_msg);
554 ASSERT (calc_size <= msg_len);
555 if (calc_size > msg_len)
558 "Truncated message '%s' (id %u) received, calculated size "
559 "%lu is bigger than actual size %llu, message dropped.",
560 am->msg_names[id], id, calc_size, msg_len);
565 clib_warning ("Message '%s' (id %u) has NULL calc_size_func, cannot "
566 "verify message size is correct",
567 am->msg_names[id], id);
570 /* don't process message if it's truncated, otherwise byte swaps
571 * and stuff could corrupt memory even beyond message if it's malicious
572 * e.g. VLA length field set to 1M elements, but VLA empty */
573 if (do_it && calc_size <= msg_len)
576 if (!am->is_mp_safe[id])
578 vl_msg_api_barrier_trace_context (am->msg_names[id]);
579 vl_msg_api_barrier_sync ();
582 if (am->is_autoendian[id])
584 void (*endian_fp) (void *);
585 endian_fp = am->msg_endian_handlers[id];
586 (*endian_fp) (the_msg);
589 if (PREDICT_FALSE (vec_len (am->perf_counter_cbs) != 0))
590 clib_call_callbacks (am->perf_counter_cbs, am, id,
593 (*am->msg_handlers[id]) (the_msg);
595 if (PREDICT_FALSE (vec_len (am->perf_counter_cbs) != 0))
596 clib_call_callbacks (am->perf_counter_cbs, am, id,
599 if (!am->is_mp_safe[id])
600 vl_msg_api_barrier_release ();
605 clib_warning ("no handler for msg id %d", id);
609 vl_msg_api_free (the_msg);
611 if (PREDICT_FALSE (am->elog_trace_api_messages))
614 ELOG_TYPE_DECLARE (e) =
616 .format = "api-msg-done(%s): %s",
617 .format_args = "t4T4",
632 ed = ELOG_DATA (am->elog_main, e);
633 if (id < vec_len (am->msg_names) && am->msg_names[id])
635 ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
636 ed->barrier = !am->is_mp_safe[id];
640 ed->c = elog_string (am->elog_main, "BOGUS");
647 vl_msg_api_handler (void *the_msg, uword msg_len)
649 api_main_t *am = vlibapi_get_main ();
651 msg_handler_internal (am, the_msg, msg_len,
652 (am->rx_trace && am->rx_trace->enabled) /* trace_it */,
653 1 /* do_it */, 1 /* free_it */);
657 vl_msg_api_handler_no_free (void *the_msg, uword msg_len)
659 api_main_t *am = vlibapi_get_main ();
660 msg_handler_internal (am, the_msg, msg_len,
661 (am->rx_trace && am->rx_trace->enabled) /* trace_it */,
662 1 /* do_it */, 0 /* free_it */);
666 vl_msg_api_handler_no_trace_no_free (void *the_msg, uword msg_len)
668 api_main_t *am = vlibapi_get_main ();
669 msg_handler_internal (am, the_msg, msg_len, 0 /* trace_it */, 1 /* do_it */,
674 * Add a trace record to the API message trace buffer, if
675 * API message tracing is enabled. Handy for adding sufficient
676 * data to the trace to reproduce autonomous state, as opposed to
677 * state downloaded via control-plane API messages. Example: the NAT
678 * application creates database entries based on packet traffic, not
679 * control-plane messages.
683 vl_msg_api_trace_only (void *the_msg, uword msg_len)
685 api_main_t *am = vlibapi_get_main ();
687 msg_handler_internal (am, the_msg, msg_len,
688 (am->rx_trace && am->rx_trace->enabled) /* trace_it */,
689 0 /* do_it */, 0 /* free_it */);
693 vl_msg_api_cleanup_handler (void *the_msg)
695 api_main_t *am = vlibapi_get_main ();
696 u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
698 if (PREDICT_FALSE (id >= vec_len (am->msg_cleanup_handlers)))
700 clib_warning ("_vl_msg_id too large: %d\n", id);
703 if (am->msg_cleanup_handlers[id])
704 (*am->msg_cleanup_handlers[id]) (the_msg);
706 vl_msg_api_free (the_msg);
710 * vl_msg_api_replay_handler
713 vl_msg_api_replay_handler (void *the_msg)
715 api_main_t *am = vlibapi_get_main ();
717 u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
719 if (PREDICT_FALSE (id >= vec_len (am->msg_handlers)))
721 clib_warning ("_vl_msg_id too large: %d\n", id);
724 /* do NOT trace the message... */
725 if (am->msg_handlers[id])
726 (*am->msg_handlers[id]) (the_msg);
727 /* do NOT free the message buffer... */
731 vl_msg_api_get_msg_length (void *msg_arg)
733 return vl_msg_api_get_msg_length_inline (msg_arg);
737 * vl_msg_api_socket_handler
740 vl_msg_api_socket_handler (void *the_msg, uword msg_len)
742 api_main_t *am = vlibapi_get_main ();
744 msg_handler_internal (am, the_msg, msg_len,
745 (am->rx_trace && am->rx_trace->enabled) /* trace_it */,
746 1 /* do_it */, 0 /* free_it */);
749 #define foreach_msg_api_vector \
752 _ (msg_cleanup_handlers) \
753 _ (msg_endian_handlers) \
754 _ (msg_print_handlers) \
755 _ (msg_print_json_handlers) \
756 _ (msg_tojson_handlers) \
757 _ (msg_fromjson_handlers) \
758 _ (msg_calc_size_funcs) \
765 vl_msg_api_config (vl_msg_api_msg_config_t * c)
767 api_main_t *am = vlibapi_get_main ();
770 * This happens during the java core tests if the message
771 * dictionary is missing newly added xxx_reply_t messages.
772 * Should never happen, but since I shot myself in the foot once
773 * this way, I thought I'd make it easy to debug if I ever do
774 * it again... (;-)...
779 clib_warning ("Trying to register %s with a NULL msg id!", c->name);
781 clib_warning ("Trying to register a NULL msg with a NULL msg id!");
782 clib_warning ("Did you forget to call setup_message_id_table?");
786 #define _(a) vec_validate (am->a, c->id);
787 foreach_msg_api_vector;
790 if (am->msg_handlers[c->id] && am->msg_handlers[c->id] != c->handler)
792 ("BUG: re-registering 'vl_api_%s_t_handler'."
793 "Handler was %llx, replaced by %llx",
794 c->name, am->msg_handlers[c->id], c->handler);
796 am->msg_names[c->id] = c->name;
797 am->msg_handlers[c->id] = c->handler;
798 am->msg_cleanup_handlers[c->id] = c->cleanup;
799 am->msg_endian_handlers[c->id] = c->endian;
800 am->msg_print_handlers[c->id] = c->print;
801 am->msg_print_json_handlers[c->id] = c->print_json;
802 am->msg_tojson_handlers[c->id] = c->tojson;
803 am->msg_fromjson_handlers[c->id] = c->fromjson;
804 am->msg_calc_size_funcs[c->id] = c->calc_size;
805 am->message_bounce[c->id] = c->message_bounce;
806 am->is_mp_safe[c->id] = c->is_mp_safe;
807 am->is_autoendian[c->id] = c->is_autoendian;
809 am->api_trace_cfg[c->id].size = c->size;
810 am->api_trace_cfg[c->id].trace_enable = c->traced;
811 am->api_trace_cfg[c->id].replay_enable = c->replay;
813 if (!am->msg_id_by_name)
814 am->msg_id_by_name = hash_create_string (0, sizeof (uword));
816 hash_set_mem (am->msg_id_by_name, c->name, c->id);
820 * vl_msg_api_set_handlers
821 * preserve the old API for a while
824 vl_msg_api_set_handlers (int id, char *name, void *handler, void *cleanup,
825 void *endian, void *print, int size, int traced,
826 void *print_json, void *tojson, void *fromjson,
829 vl_msg_api_msg_config_t cfg;
830 vl_msg_api_msg_config_t *c = &cfg;
832 clib_memset (c, 0, sizeof (*c));
836 c->handler = handler;
837 c->cleanup = cleanup;
842 c->message_bounce = 0;
844 c->is_autoendian = 0;
846 c->fromjson = fromjson;
847 c->print_json = print_json;
848 c->calc_size = calc_size;
849 vl_msg_api_config (c);
853 vl_msg_api_clean_handlers (int msg_id)
855 vl_msg_api_msg_config_t cfg;
856 vl_msg_api_msg_config_t *c = &cfg;
858 clib_memset (c, 0, sizeof (*c));
861 vl_msg_api_config (c);
865 vl_msg_api_set_cleanup_handler (int msg_id, void *fp)
867 api_main_t *am = vlibapi_get_main ();
870 vec_validate (am->msg_cleanup_handlers, msg_id);
871 am->msg_cleanup_handlers[msg_id] = fp;
875 vl_msg_api_queue_handler (svm_queue_t * q)
879 while (!svm_queue_sub (q, (u8 *) &msg, SVM_Q_WAIT, 0))
881 msgbuf_t *msgbuf = (msgbuf_t *) ((u8 *) msg - offsetof (msgbuf_t, data));
882 vl_msg_api_handler ((void *) msg, ntohl (msgbuf->data_len));
887 vl_msg_api_max_length (void *mp)
892 /* Work out the maximum sane message length, and return it */
893 if (PREDICT_TRUE (mp != 0))
895 mb = (msgbuf_t *) (((u8 *) mp) - offsetof (msgbuf_t, data));
896 data_len = clib_net_to_host_u32 (mb->data_len);
902 vl_msg_api_trace_get (api_main_t * am, vl_api_trace_which_t which)
906 case VL_API_TRACE_RX:
908 case VL_API_TRACE_TX:
916 vl_noop_handler (void *mp)
921 static u8 post_mortem_dump_enabled;
924 vl_msg_api_post_mortem_dump_enable_disable (int enable)
926 post_mortem_dump_enabled = enable;
930 vl_msg_api_post_mortem_dump (void)
932 api_main_t *am = vlibapi_get_main ();
937 if (post_mortem_dump_enabled == 0)
940 snprintf (filename, sizeof (filename), "/tmp/api_post_mortem.%d",
943 fp = fopen (filename, "w");
946 rv = write (2, "Couldn't create ", 16);
947 rv = write (2, filename, strlen (filename));
948 rv = write (2, "\n", 1);
951 rv = vl_msg_api_trace_save (am, VL_API_TRACE_RX, fp, 0);
955 rv = write (2, "Failed to save post-mortem API trace to ", 40);
956 rv = write (2, filename, strlen (filename));
957 rv = write (2, "\n", 1);
962 /* Layered message handling support */
965 vl_msg_api_set_first_available_msg_id (u16 first_avail)
967 api_main_t *am = vlibapi_get_main ();
969 am->first_available_msg_id = first_avail;
973 vl_msg_api_get_msg_ids (const char *name, int n)
975 api_main_t *am = vlibapi_get_main ();
977 vl_api_msg_range_t *rp;
981 if (am->msg_range_by_name == 0)
982 am->msg_range_by_name = hash_create_string (0, sizeof (uword));
984 name_copy = format (0, "%s%c", name, 0);
986 p = hash_get_mem (am->msg_range_by_name, name_copy);
989 clib_warning ("WARNING: duplicate message range registration for '%s'",
991 vec_free (name_copy);
995 if (n < 0 || n > 1024)
998 ("WARNING: bad number of message-IDs (%d) requested by '%s'",
1000 vec_free (name_copy);
1004 vec_add2 (am->msg_ranges, rp, 1);
1006 rv = rp->first_msg_id = am->first_available_msg_id;
1007 am->first_available_msg_id += n;
1008 rp->last_msg_id = am->first_available_msg_id - 1;
1009 rp->name = name_copy;
1011 hash_set_mem (am->msg_range_by_name, name_copy, rp - am->msg_ranges);
1017 vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string, u32 id)
1021 if (am->msg_index_by_name_and_crc == 0)
1022 am->msg_index_by_name_and_crc = hash_create_string (0, sizeof (uword));
1024 p = hash_get_mem (am->msg_index_by_name_and_crc, string);
1027 clib_warning ("attempt to redefine '%s' ignored...", string);
1031 hash_set_mem (am->msg_index_by_name_and_crc, string, id);
1035 vl_msg_api_add_version (api_main_t * am, const char *string,
1036 u32 major, u32 minor, u32 patch)
1038 api_version_t version = {.major = major,.minor = minor,.patch = patch };
1039 ASSERT (strlen (string) < 64);
1040 strncpy (version.name, string, 64 - 1);
1041 vec_add1 (am->api_version_list, version);
1045 vl_msg_api_get_msg_index (u8 * name_and_crc)
1047 api_main_t *am = vlibapi_get_main ();
1050 if (am->msg_index_by_name_and_crc)
1052 p = hash_get_mem (am->msg_index_by_name_and_crc, name_and_crc);
1060 vl_msg_push_heap_w_region (svm_region_t * vlib_rp)
1062 pthread_mutex_lock (&vlib_rp->mutex);
1063 return svm_push_data_heap (vlib_rp);
1067 vl_msg_push_heap (void)
1069 api_main_t *am = vlibapi_get_main ();
1070 return vl_msg_push_heap_w_region (am->vlib_rp);
1074 vl_msg_pop_heap_w_region (svm_region_t * vlib_rp, void *oldheap)
1076 svm_pop_heap (oldheap);
1077 pthread_mutex_unlock (&vlib_rp->mutex);
1081 vl_msg_pop_heap (void *oldheap)
1083 api_main_t *am = vlibapi_get_main ();
1084 vl_msg_pop_heap_w_region (am->vlib_rp, oldheap);
1087 /* Must be nul terminated */
1089 vl_api_c_string_to_api_string (const char *buf, vl_api_string_t * str)
1091 /* copy without nul terminator */
1092 u32 len = strlen (buf);
1094 clib_memcpy_fast (str->buf, buf, len);
1095 str->length = htonl (len);
1096 return len + sizeof (u32);
1099 /* Must NOT be nul terminated */
1101 vl_api_vec_to_api_string (const u8 * vec, vl_api_string_t * str)
1103 u32 len = vec_len (vec);
1104 clib_memcpy (str->buf, vec, len);
1105 str->length = htonl (len);
1106 return len + sizeof (u32);
1110 vl_api_string_len (vl_api_string_t * astr)
1112 return clib_net_to_host_u32 (astr->length);
1116 vl_api_format_string (u8 * s, va_list * args)
1118 vl_api_string_t *a = va_arg (*args, vl_api_string_t *);
1119 vec_add (s, a->buf, clib_net_to_host_u32 (a->length));
1124 * Returns a new vector. Remember to free it after use.
1125 * NOT nul terminated.
1128 vl_api_from_api_to_new_vec (void *mp, vl_api_string_t * astr)
1132 if (vl_msg_api_max_length (mp) < clib_net_to_host_u32 (astr->length))
1133 return format (0, "insane astr->length %u%c",
1134 clib_net_to_host_u32 (astr->length), 0);
1135 vec_add (v, astr->buf, clib_net_to_host_u32 (astr->length));
1140 * Returns a new vector. Remember to free it after use.
1144 vl_api_from_api_to_new_c_string (vl_api_string_t * astr)
1147 if (clib_net_to_host_u32 (astr->length) > 0)
1149 vec_add (v, astr->buf, clib_net_to_host_u32 (astr->length));
1156 vl_api_set_elog_main (elog_main_t * m)
1158 api_main_t *am = vlibapi_get_main ();
1163 vl_api_set_elog_trace_api_messages (int enable)
1166 api_main_t *am = vlibapi_get_main ();
1168 rv = am->elog_trace_api_messages;
1169 am->elog_trace_api_messages = enable;
1174 vl_api_get_elog_trace_api_messages (void)
1176 api_main_t *am = vlibapi_get_main ();
1178 return am->elog_trace_api_messages;
1182 * fd.io coding-style-patch-verification: ON
1185 * eval: (c-set-style "gnu")