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 api_main_t api_global_main =
38 .region_name = "/unset",
44 /* Please use vlibapi_get_main() to access my_api_main */
45 __thread api_main_t *my_api_main = &api_global_main;
48 vl_msg_api_set_global_main (void *am_arg)
51 my_api_main = (api_main_t *) am_arg;
55 vl_msg_api_increment_missing_client_counter (void)
57 api_main_t *am = vlibapi_get_main ();
58 am->missing_clients++;
62 vl_msg_api_rx_trace_enabled (api_main_t * am)
64 return (am->rx_trace && am->rx_trace->enabled);
68 vl_msg_api_tx_trace_enabled (api_main_t * am)
70 return (am->tx_trace && am->tx_trace->enabled);
77 vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg)
84 u16 msg_id = clib_net_to_host_u16 (*((u16 *) msg));
85 msgbuf_t *header = (msgbuf_t *) (((u8 *) msg) - offsetof (msgbuf_t, data));
87 cfgp = am->api_trace_cfg + msg_id;
89 if (!cfgp || !cfgp->trace_enable)
96 clib_warning ("tp->nitems is 0");
100 if (vec_len (tp->traces) < tp->nitems)
102 vec_add1 (tp->traces, 0);
103 this_trace = tp->traces + vec_len (tp->traces) - 1;
108 old_trace = tp->traces + tp->curindex++;
109 if (tp->curindex == tp->nitems)
111 /* Reuse the trace record, may save some memory allocator traffic */
112 msg_copy = *old_trace;
113 vec_reset_length (msg_copy);
114 this_trace = old_trace;
117 length = clib_net_to_host_u32 (header->data_len);
119 vec_validate (msg_copy, length - 1);
120 clib_memcpy_fast (msg_copy, msg, length);
121 *this_trace = msg_copy;
125 vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which,
133 case VL_API_TRACE_TX:
137 vl_msg_api_trace_configure (am, which, 1024);
142 case VL_API_TRACE_RX:
146 vl_msg_api_trace_configure (am, which, 1024);
157 if (tp == 0 || tp->nitems == 0)
167 vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which)
174 case VL_API_TRACE_TX:
178 case VL_API_TRACE_RX:
188 if (!tp || tp->nitems == 0)
194 for (i = 0; i < vec_len (tp->traces); i++)
196 vec_free (tp->traces[i]);
198 vec_free (tp->traces);
204 vl_api_serialize_message_table (api_main_t * am, u8 * vector)
206 serialize_main_t _sm, *sm = &_sm;
208 u32 nmsg = hash_elts (am->msg_index_by_name_and_crc);
210 serialize_open_vector (sm, vector);
212 /* serialize the count */
213 serialize_integer (sm, nmsg, sizeof (u32));
216 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
218 serialize_likely_small_unsigned_integer (sm, hp->value[0]);
219 serialize_cstring (sm, (char *) hp->key);
223 return serialize_close_vector (sm);
227 vl_msg_api_trace_save (api_main_t * am, vl_api_trace_which_t which, FILE * fp)
230 vl_api_trace_file_header_t fh;
236 case VL_API_TRACE_TX:
240 case VL_API_TRACE_RX:
249 /* Configured, data present? */
250 if (tp == 0 || tp->nitems == 0 || vec_len (tp->traces) == 0)
253 /* "Dare to be stupid" check */
259 /* Write the file header */
260 fh.wrapped = tp->wrapped;
261 fh.nitems = clib_host_to_net_u32 (vec_len (tp->traces));
262 u8 *m = vl_api_serialize_message_table (am, 0);
263 fh.msgtbl_size = clib_host_to_net_u32 (vec_len (m));
265 if (fwrite (&fh, sizeof (fh), 1, fp) != 1)
270 /* Write the message table */
271 if (fwrite (m, vec_len (m), 1, fp) != 1)
278 if (tp->wrapped == 0)
281 * Note: vec_len return 0 when fed a NULL pointer.
282 * Unfortunately, the static analysis tool doesn't
283 * figure it out, hence the suppressed warnings.
284 * What a great use of my time.
286 for (i = 0; i < vec_len (tp->traces); i++)
289 /*sa_ignore NO_NULL_CHK */
292 * This retarded check required to pass
298 msg_length = clib_host_to_net_u32 (vec_len (msg));
299 if (fwrite (&msg_length, 1, sizeof (msg_length), fp)
300 != sizeof (msg_length))
304 if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
312 /* Wrap case: write oldest -> end of buffer */
313 for (i = tp->curindex; i < vec_len (tp->traces); i++)
318 * This retarded check required to pass
324 msg_length = clib_host_to_net_u32 (vec_len (msg));
325 if (fwrite (&msg_length, 1, sizeof (msg_length), fp)
326 != sizeof (msg_length))
331 if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
336 /* write beginning of buffer -> oldest-1 */
337 for (i = 0; i < tp->curindex; i++)
340 /*sa_ignore NO_NULL_CHK */
343 * This retarded check required to pass
349 msg_length = clib_host_to_net_u32 (vec_len (msg));
350 if (fwrite (&msg_length, 1, sizeof (msg_length), fp)
351 != sizeof (msg_length))
356 if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg))
366 vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which,
374 case VL_API_TRACE_TX:
378 vec_validate (am->tx_trace, 0);
383 case VL_API_TRACE_RX:
387 vec_validate (am->rx_trace, 0);
400 was_on = vl_msg_api_trace_onoff (am, which, 0);
404 vl_msg_api_trace_free (am, which);
407 clib_memset (tp, 0, sizeof (*tp));
409 if (clib_arch_is_big_endian)
411 tp->endian = VL_API_BIG_ENDIAN;
415 tp->endian = VL_API_LITTLE_ENDIAN;
421 (void) vl_msg_api_trace_onoff (am, which, was_on);
427 vl_msg_api_barrier_sync (void)
432 vl_msg_api_barrier_release (void)
437 msg_handler_internal (api_main_t * am,
438 void *the_msg, int trace_it, int do_it, int free_it)
440 u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
441 u8 *(*print_fp) (void *, void *);
443 if (PREDICT_FALSE (am->elog_trace_api_messages))
446 ELOG_TYPE_DECLARE (e) =
448 .format = "api-msg: %s",
456 ed = ELOG_DATA (am->elog_main, e);
457 if (id < vec_len (am->msg_names))
458 ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
460 ed->c = elog_string (am->elog_main, "BOGUS");
463 if (id < vec_len (am->msg_handlers) && am->msg_handlers[id])
466 vl_msg_api_trace (am, am->rx_trace, the_msg);
468 if (am->msg_print_flag)
470 fformat (stdout, "[%d]: %s\n", id, am->msg_names[id]);
471 print_fp = (void *) am->msg_print_handlers[id];
474 fformat (stdout, " [no registered print fn]\n");
478 (*print_fp) (the_msg, stdout);
484 if (!am->is_mp_safe[id])
486 vl_msg_api_barrier_trace_context (am->msg_names[id]);
487 vl_msg_api_barrier_sync ();
490 if (am->is_autoendian[id])
492 void (*endian_fp) (void *);
493 endian_fp = am->msg_endian_handlers[id];
494 (*endian_fp) (the_msg);
497 if (PREDICT_FALSE (vec_len (am->perf_counter_cbs) != 0))
498 clib_call_callbacks (am->perf_counter_cbs, am, id,
501 (*am->msg_handlers[id]) (the_msg);
503 if (PREDICT_FALSE (vec_len (am->perf_counter_cbs) != 0))
504 clib_call_callbacks (am->perf_counter_cbs, am, id,
506 if (!am->is_mp_safe[id])
507 vl_msg_api_barrier_release ();
512 clib_warning ("no handler for msg id %d", id);
516 vl_msg_api_free (the_msg);
518 if (PREDICT_FALSE (am->elog_trace_api_messages))
521 ELOG_TYPE_DECLARE (e) =
523 .format = "api-msg-done(%s): %s",
524 .format_args = "t4T4",
539 ed = ELOG_DATA (am->elog_main, e);
540 if (id < vec_len (am->msg_names))
542 ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
543 ed->barrier = !am->is_mp_safe[id];
547 ed->c = elog_string (am->elog_main, "BOGUS");
553 void (*vl_msg_api_fuzz_hook) (u16, void *);
555 /* This is only to be called from a vlib/vnet app */
557 vl_msg_api_handler_with_vm_node (api_main_t * am, svm_region_t * vlib_rp,
558 void *the_msg, vlib_main_t * vm,
559 vlib_node_runtime_t * node, u8 is_private)
561 u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
562 u8 *(*handler) (void *, void *, void *);
563 u8 *(*print_fp) (void *, void *);
564 svm_region_t *old_vlib_rp;
565 void *save_shmem_hdr;
568 if (PREDICT_FALSE (am->elog_trace_api_messages))
571 ELOG_TYPE_DECLARE (e) =
573 .format = "api-msg: %s",
581 ed = ELOG_DATA (am->elog_main, e);
582 if (id < vec_len (am->msg_names))
583 ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
585 ed->c = elog_string (am->elog_main, "BOGUS");
588 if (id < vec_len (am->msg_handlers) && am->msg_handlers[id])
590 handler = (void *) am->msg_handlers[id];
592 if (PREDICT_FALSE (am->rx_trace && am->rx_trace->enabled))
593 vl_msg_api_trace (am, am->rx_trace, the_msg);
595 if (PREDICT_FALSE (am->msg_print_flag))
597 fformat (stdout, "[%d]: %s\n", id, am->msg_names[id]);
598 print_fp = (void *) am->msg_print_handlers[id];
601 fformat (stdout, " [no registered print fn for msg %d]\n", id);
605 (*print_fp) (the_msg, vm);
608 is_mp_safe = am->is_mp_safe[id];
612 vl_msg_api_barrier_trace_context (am->msg_names[id]);
613 vl_msg_api_barrier_sync ();
617 old_vlib_rp = am->vlib_rp;
618 save_shmem_hdr = am->shmem_hdr;
619 am->vlib_rp = vlib_rp;
620 am->shmem_hdr = (void *) vlib_rp->user_ctx;
623 if (PREDICT_FALSE (vl_msg_api_fuzz_hook != 0))
624 (*vl_msg_api_fuzz_hook) (id, the_msg);
626 if (am->is_autoendian[id])
628 void (*endian_fp) (void *);
629 endian_fp = am->msg_endian_handlers[id];
630 (*endian_fp) (the_msg);
632 if (PREDICT_FALSE (vec_len (am->perf_counter_cbs) != 0))
633 clib_call_callbacks (am->perf_counter_cbs, am, id, 0 /* before */ );
635 (*handler) (the_msg, vm, node);
637 if (PREDICT_FALSE (vec_len (am->perf_counter_cbs) != 0))
638 clib_call_callbacks (am->perf_counter_cbs, am, id, 1 /* after */ );
641 am->vlib_rp = old_vlib_rp;
642 am->shmem_hdr = save_shmem_hdr;
645 vl_msg_api_barrier_release ();
649 clib_warning ("no handler for msg id %d", id);
653 * Special-case, so we can e.g. bounce messages off the vnet
654 * main thread without copying them...
656 if (id >= vec_len (am->message_bounce) || !(am->message_bounce[id]))
657 vl_msg_api_free (the_msg);
659 if (PREDICT_FALSE (am->elog_trace_api_messages))
662 ELOG_TYPE_DECLARE (e) =
664 .format = "api-msg-done(%s): %s",
665 .format_args = "t4T4",
680 ed = ELOG_DATA (am->elog_main, e);
681 if (id < vec_len (am->msg_names))
682 ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
684 ed->c = elog_string (am->elog_main, "BOGUS");
685 ed->barrier = is_mp_safe;
690 vl_msg_api_handler (void *the_msg)
692 api_main_t *am = vlibapi_get_main ();
694 msg_handler_internal (am, the_msg,
696 && am->rx_trace->enabled) /* trace_it */ ,
697 1 /* do_it */ , 1 /* free_it */ );
701 vl_msg_api_handler_no_free (void *the_msg)
703 api_main_t *am = vlibapi_get_main ();
704 msg_handler_internal (am, the_msg,
706 && am->rx_trace->enabled) /* trace_it */ ,
707 1 /* do_it */ , 0 /* free_it */ );
711 vl_msg_api_handler_no_trace_no_free (void *the_msg)
713 api_main_t *am = vlibapi_get_main ();
714 msg_handler_internal (am, the_msg, 0 /* trace_it */ , 1 /* do_it */ ,
719 * Add a trace record to the API message trace buffer, if
720 * API message tracing is enabled. Handy for adding sufficient
721 * data to the trace to reproduce autonomous state, as opposed to
722 * state downloaded via control-plane API messages. Example: the NAT
723 * application creates database entries based on packet traffic, not
724 * control-plane messages.
728 vl_msg_api_trace_only (void *the_msg)
730 api_main_t *am = vlibapi_get_main ();
732 msg_handler_internal (am, the_msg,
734 && am->rx_trace->enabled) /* trace_it */ ,
735 0 /* do_it */ , 0 /* free_it */ );
739 vl_msg_api_cleanup_handler (void *the_msg)
741 api_main_t *am = vlibapi_get_main ();
742 u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
744 if (PREDICT_FALSE (id >= vec_len (am->msg_cleanup_handlers)))
746 clib_warning ("_vl_msg_id too large: %d\n", id);
749 if (am->msg_cleanup_handlers[id])
750 (*am->msg_cleanup_handlers[id]) (the_msg);
752 vl_msg_api_free (the_msg);
756 * vl_msg_api_replay_handler
759 vl_msg_api_replay_handler (void *the_msg)
761 api_main_t *am = vlibapi_get_main ();
763 u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
765 if (PREDICT_FALSE (id >= vec_len (am->msg_handlers)))
767 clib_warning ("_vl_msg_id too large: %d\n", id);
770 /* do NOT trace the message... */
771 if (am->msg_handlers[id])
772 (*am->msg_handlers[id]) (the_msg);
773 /* do NOT free the message buffer... */
777 vl_msg_api_get_msg_length (void *msg_arg)
779 return vl_msg_api_get_msg_length_inline (msg_arg);
783 * vl_msg_api_socket_handler
786 vl_msg_api_socket_handler (void *the_msg)
788 api_main_t *am = vlibapi_get_main ();
790 msg_handler_internal (am, the_msg,
792 && am->rx_trace->enabled) /* trace_it */ ,
793 1 /* do_it */ , 0 /* free_it */ );
796 #define foreach_msg_api_vector \
799 _(msg_cleanup_handlers) \
800 _(msg_endian_handlers) \
801 _(msg_print_handlers) \
808 vl_msg_api_config (vl_msg_api_msg_config_t * c)
810 api_main_t *am = vlibapi_get_main ();
813 * This happens during the java core tests if the message
814 * dictionary is missing newly added xxx_reply_t messages.
815 * Should never happen, but since I shot myself in the foot once
816 * this way, I thought I'd make it easy to debug if I ever do
817 * it again... (;-)...
822 clib_warning ("Trying to register %s with a NULL msg id!", c->name);
824 clib_warning ("Trying to register a NULL msg with a NULL msg id!");
825 clib_warning ("Did you forget to call setup_message_id_table?");
829 #define _(a) vec_validate (am->a, c->id);
830 foreach_msg_api_vector;
833 if (am->msg_handlers[c->id] && am->msg_handlers[c->id] != c->handler)
835 ("BUG: re-registering 'vl_api_%s_t_handler'."
836 "Handler was %llx, replaced by %llx",
837 c->name, am->msg_handlers[c->id], c->handler);
839 am->msg_names[c->id] = c->name;
840 am->msg_handlers[c->id] = c->handler;
841 am->msg_cleanup_handlers[c->id] = c->cleanup;
842 am->msg_endian_handlers[c->id] = c->endian;
843 am->msg_print_handlers[c->id] = c->print;
844 am->message_bounce[c->id] = c->message_bounce;
845 am->is_mp_safe[c->id] = c->is_mp_safe;
846 am->is_autoendian[c->id] = c->is_autoendian;
848 am->api_trace_cfg[c->id].size = c->size;
849 am->api_trace_cfg[c->id].trace_enable = c->traced;
850 am->api_trace_cfg[c->id].replay_enable = c->replay;
854 * vl_msg_api_set_handlers
855 * preserve the old API for a while
858 vl_msg_api_set_handlers (int id, char *name, void *handler, void *cleanup,
859 void *endian, void *print, int size, int traced)
861 vl_msg_api_msg_config_t cfg;
862 vl_msg_api_msg_config_t *c = &cfg;
864 clib_memset (c, 0, sizeof (*c));
868 c->handler = handler;
869 c->cleanup = cleanup;
874 c->message_bounce = 0;
876 c->is_autoendian = 0;
877 vl_msg_api_config (c);
881 vl_msg_api_clean_handlers (int msg_id)
883 vl_msg_api_msg_config_t cfg;
884 vl_msg_api_msg_config_t *c = &cfg;
886 clib_memset (c, 0, sizeof (*c));
889 vl_msg_api_config (c);
893 vl_msg_api_set_cleanup_handler (int msg_id, void *fp)
895 api_main_t *am = vlibapi_get_main ();
898 vec_validate (am->msg_cleanup_handlers, msg_id);
899 am->msg_cleanup_handlers[msg_id] = fp;
903 vl_msg_api_queue_handler (svm_queue_t * q)
907 while (!svm_queue_sub (q, (u8 *) & msg, SVM_Q_WAIT, 0))
908 vl_msg_api_handler ((void *) msg);
912 vl_msg_api_max_length (void *mp)
917 /* Work out the maximum sane message length, and return it */
918 if (PREDICT_TRUE (mp != 0))
920 mb = (msgbuf_t *) (((u8 *) mp) - offsetof (msgbuf_t, data));
921 data_len = clib_net_to_host_u32 (mb->data_len);
927 vl_msg_api_trace_get (api_main_t * am, vl_api_trace_which_t which)
931 case VL_API_TRACE_RX:
933 case VL_API_TRACE_TX:
941 vl_noop_handler (void *mp)
946 static u8 post_mortem_dump_enabled;
949 vl_msg_api_post_mortem_dump_enable_disable (int enable)
951 post_mortem_dump_enabled = enable;
955 vl_msg_api_post_mortem_dump (void)
957 api_main_t *am = vlibapi_get_main ();
962 if (post_mortem_dump_enabled == 0)
965 snprintf (filename, sizeof (filename), "/tmp/api_post_mortem.%d",
968 fp = fopen (filename, "w");
971 rv = write (2, "Couldn't create ", 16);
972 rv = write (2, filename, strlen (filename));
973 rv = write (2, "\n", 1);
976 rv = vl_msg_api_trace_save (am, VL_API_TRACE_RX, fp);
980 rv = write (2, "Failed to save post-mortem API trace to ", 40);
981 rv = write (2, filename, strlen (filename));
982 rv = write (2, "\n", 1);
987 /* Layered message handling support */
990 vl_msg_api_register_pd_handler (void *fp, u16 msg_id_host_byte_order)
992 api_main_t *am = vlibapi_get_main ();
994 /* Mild idiot proofing */
995 if (msg_id_host_byte_order > 10000)
996 clib_warning ("msg_id_host_byte_order endian issue? %d arg vs %d",
997 msg_id_host_byte_order,
998 clib_net_to_host_u16 (msg_id_host_byte_order));
999 vec_validate (am->pd_msg_handlers, msg_id_host_byte_order);
1000 am->pd_msg_handlers[msg_id_host_byte_order] = fp;
1004 vl_msg_api_pd_handler (void *mp, int rv)
1006 api_main_t *am = vlibapi_get_main ();
1007 int (*fp) (void *, int);
1010 if (clib_arch_is_little_endian)
1011 msg_id = clib_net_to_host_u16 (*((u16 *) mp));
1013 msg_id = *((u16 *) mp);
1015 if (msg_id >= vec_len (am->pd_msg_handlers)
1016 || am->pd_msg_handlers[msg_id] == 0)
1019 fp = am->pd_msg_handlers[msg_id];
1020 rv = (*fp) (mp, rv);
1025 vl_msg_api_set_first_available_msg_id (u16 first_avail)
1027 api_main_t *am = vlibapi_get_main ();
1029 am->first_available_msg_id = first_avail;
1033 vl_msg_api_get_msg_ids (const char *name, int n)
1035 api_main_t *am = vlibapi_get_main ();
1037 vl_api_msg_range_t *rp;
1041 if (am->msg_range_by_name == 0)
1042 am->msg_range_by_name = hash_create_string (0, sizeof (uword));
1044 name_copy = format (0, "%s%c", name, 0);
1046 p = hash_get_mem (am->msg_range_by_name, name_copy);
1049 clib_warning ("WARNING: duplicate message range registration for '%s'",
1051 vec_free (name_copy);
1055 if (n < 0 || n > 1024)
1058 ("WARNING: bad number of message-IDs (%d) requested by '%s'",
1060 vec_free (name_copy);
1064 vec_add2 (am->msg_ranges, rp, 1);
1066 rv = rp->first_msg_id = am->first_available_msg_id;
1067 am->first_available_msg_id += n;
1068 rp->last_msg_id = am->first_available_msg_id - 1;
1069 rp->name = name_copy;
1071 hash_set_mem (am->msg_range_by_name, name_copy, rp - am->msg_ranges);
1077 vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string, u32 id)
1081 if (am->msg_index_by_name_and_crc == 0)
1082 am->msg_index_by_name_and_crc = hash_create_string (0, sizeof (uword));
1084 p = hash_get_mem (am->msg_index_by_name_and_crc, string);
1087 clib_warning ("attempt to redefine '%s' ignored...", string);
1091 hash_set_mem (am->msg_index_by_name_and_crc, string, id);
1095 vl_msg_api_add_version (api_main_t * am, const char *string,
1096 u32 major, u32 minor, u32 patch)
1098 api_version_t version = {.major = major,.minor = minor,.patch = patch };
1099 ASSERT (strlen (string) < 64);
1100 strncpy (version.name, string, 64 - 1);
1101 vec_add1 (am->api_version_list, version);
1105 vl_msg_api_get_msg_index (u8 * name_and_crc)
1107 api_main_t *am = vlibapi_get_main ();
1110 if (am->msg_index_by_name_and_crc)
1112 p = hash_get_mem (am->msg_index_by_name_and_crc, name_and_crc);
1120 vl_msg_push_heap_w_region (svm_region_t * vlib_rp)
1122 pthread_mutex_lock (&vlib_rp->mutex);
1123 return svm_push_data_heap (vlib_rp);
1127 vl_msg_push_heap (void)
1129 api_main_t *am = vlibapi_get_main ();
1130 return vl_msg_push_heap_w_region (am->vlib_rp);
1134 vl_msg_pop_heap_w_region (svm_region_t * vlib_rp, void *oldheap)
1136 svm_pop_heap (oldheap);
1137 pthread_mutex_unlock (&vlib_rp->mutex);
1141 vl_msg_pop_heap (void *oldheap)
1143 api_main_t *am = vlibapi_get_main ();
1144 vl_msg_pop_heap_w_region (am->vlib_rp, oldheap);
1147 /* Must be nul terminated */
1149 vl_api_c_string_to_api_string (const char *buf, vl_api_string_t * str)
1151 /* copy without nul terminator */
1152 u32 len = strlen (buf);
1154 clib_memcpy_fast (str->buf, buf, len);
1155 str->length = htonl (len);
1156 return len + sizeof (u32);
1159 /* Must NOT be nul terminated */
1161 vl_api_vec_to_api_string (const u8 * vec, vl_api_string_t * str)
1163 u32 len = vec_len (vec);
1164 clib_memcpy (str->buf, vec, len);
1165 str->length = htonl (len);
1166 return len + sizeof (u32);
1170 vl_api_string_len (vl_api_string_t * astr)
1172 return clib_net_to_host_u32 (astr->length);
1176 vl_api_format_string (u8 * s, va_list * args)
1178 vl_api_string_t *a = va_arg (*args, vl_api_string_t *);
1179 vec_add (s, a->buf, clib_net_to_host_u32 (a->length));
1184 * Returns a new vector. Remember to free it after use.
1185 * NOT nul terminated.
1188 vl_api_from_api_to_new_vec (void *mp, vl_api_string_t * astr)
1192 if (vl_msg_api_max_length (mp) < clib_net_to_host_u32 (astr->length))
1193 return format (0, "insane astr->length %u%c",
1194 clib_net_to_host_u32 (astr->length), 0);
1195 vec_add (v, astr->buf, clib_net_to_host_u32 (astr->length));
1200 * Returns a new vector. Remember to free it after use.
1204 vl_api_from_api_to_new_c_string (vl_api_string_t * astr)
1207 if (clib_net_to_host_u32 (astr->length) > 0)
1209 vec_add (v, astr->buf, clib_net_to_host_u32 (astr->length));
1216 vl_api_set_elog_main (elog_main_t * m)
1218 api_main_t *am = vlibapi_get_main ();
1223 vl_api_set_elog_trace_api_messages (int enable)
1226 api_main_t *am = vlibapi_get_main ();
1228 rv = am->elog_trace_api_messages;
1229 am->elog_trace_api_messages = enable;
1234 vl_api_get_elog_trace_api_messages (void)
1236 api_main_t *am = vlibapi_get_main ();
1238 return am->elog_trace_api_messages;
1242 * fd.io coding-style-patch-verification: ON
1245 * eval: (c-set-style "gnu")