vl_api_registration_t **regpp, *regp;
svm_queue_t *q;
char *health;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
u32 *confused_indices = 0;
if (!pool_elts (am->vl_clients))
vl_api_status_command (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cli_cmd)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
/* check if rx_trace and tx_trace are not null pointers */
if (am->rx_trace == 0)
unformat_input_t * input,
vlib_cli_command_t * cli_cmd)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
int i;
int verbose = 0;
unformat_input_t * input,
vlib_cli_command_t * cli_cmd)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
vl_api_msg_range_t *rp = 0;
int i;
struct stat statb;
size_t file_size;
u8 *msg;
- u8 endian_swap_needed = 0;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
u8 *tmpbuf = 0;
- u32 nitems;
+ u32 nitems, nitems_msgtbl;
void **saved_print_handlers = 0;
fd = open ((char *) filename, O_RDONLY);
}
file_size = statb.st_size;
- file_size = (file_size + 4095) & ~(4096);
+ file_size = (file_size + 4095) & ~(4095);
hp = mmap (0, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
}
close (fd);
- if ((clib_arch_is_little_endian && hp->endian == VL_API_BIG_ENDIAN)
- || (clib_arch_is_big_endian && hp->endian == VL_API_LITTLE_ENDIAN))
- endian_swap_needed = 1;
+ CLIB_MEM_UNPOISON (hp, file_size);
- if (endian_swap_needed)
- nitems = ntohl (hp->nitems);
- else
- nitems = hp->nitems;
+ nitems = ntohl (hp->nitems);
if (last_index == (u32) ~ 0)
{
vlib_cli_output (vm, "Range (%d, %d) outside file range (0, %d)\n",
first_index, last_index, nitems - 1);
munmap (hp, file_size);
+ CLIB_MEM_POISON (hp, file_size);
return;
}
if (hp->wrapped)
vl_msg_api_custom_dump_configure (am);
}
-
msg = (u8 *) (hp + 1);
+ u16 *msgid_vec = 0;
+ serialize_main_t _sm, *sm = &_sm;
+ u32 msgtbl_size = ntohl (hp->msgtbl_size);
+ u8 *name_and_crc;
+
+ unserialize_open_data (sm, msg, msgtbl_size);
+ unserialize_integer (sm, &nitems_msgtbl, sizeof (u32));
+
+ for (i = 0; i < nitems_msgtbl; i++)
+ {
+ u16 msg_index = unserialize_likely_small_unsigned_integer (sm);
+ unserialize_cstring (sm, (char **) &name_and_crc);
+ u16 msg_index2 = vl_msg_api_get_msg_index (name_and_crc);
+ vec_validate (msgid_vec, msg_index);
+ msgid_vec[msg_index] = msg_index2;
+ }
+
+ msg += msgtbl_size;
+
for (i = 0; i < first_index; i++)
{
trace_cfg_t *cfgp;
size = clib_host_to_net_u32 (*(u32 *) msg);
msg += sizeof (u32);
- if (clib_arch_is_little_endian)
- msg_id = ntohs (*((u16 *) msg));
- else
- msg_id = *((u16 *) msg);
-
+ msg_id = ntohs (*((u16 *) msg));
+ if (msg_id < vec_len (msgid_vec))
+ msg_id = msgid_vec[msg_id];
cfgp = am->api_trace_cfg + msg_id;
if (!cfgp)
{
vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
munmap (hp, file_size);
+ CLIB_MEM_POISON (hp, file_size);
return;
}
msg += size;
for (; i <= last_index; i++)
{
trace_cfg_t *cfgp;
- u16 *msg_idp;
u16 msg_id;
int size;
size = clib_host_to_net_u32 (*(u32 *) msg);
msg += sizeof (u32);
- if (clib_arch_is_little_endian)
- msg_id = ntohs (*((u16 *) msg));
- else
- msg_id = *((u16 *) msg);
+ msg_id = ntohs (*((u16 *) msg));
+ if (msg_id < vec_len (msgid_vec))
+ {
+ msg_id = msgid_vec[msg_id];
+ }
cfgp = am->api_trace_cfg + msg_id;
if (!cfgp)
{
vlib_cli_output (vm, "Ugh: msg id %d no trace config\n", msg_id);
munmap (hp, file_size);
+ CLIB_MEM_POISON (hp, file_size);
vec_free (tmpbuf);
am->replay_in_progress = 0;
return;
clib_memset (tmpbuf, 0xf, sizeof (uword));
/*
- * Endian swap if needed. All msg data is supposed to be
- * in network byte order. All msg handlers are supposed to
- * know that. The generic message dumpers don't know that.
- * One could fix apigen, I suppose.
+ * Endian swap if needed. All msg data is supposed to be in
+ * network byte order.
*/
- if ((which == DUMP && clib_arch_is_little_endian) || endian_swap_needed)
+ if (((which == DUMP || which == CUSTOM_DUMP)
+ && clib_arch_is_little_endian))
{
void (*endian_fp) (void *);
if (msg_id >= vec_len (am->msg_endian_handlers)
{
vlib_cli_output (vm, "Ugh: msg id %d no endian swap\n", msg_id);
munmap (hp, file_size);
+ CLIB_MEM_POISON (hp, file_size);
vec_free (tmpbuf);
am->replay_in_progress = 0;
return;
/* msg_id always in network byte order */
if (clib_arch_is_little_endian)
{
- msg_idp = (u16 *) (tmpbuf + sizeof (uword));
+ u16 *msg_idp = (u16 *) (tmpbuf + sizeof (uword));
*msg_idp = msg_id;
}
}
munmap (hp, file_size);
+ CLIB_MEM_POISON (hp, file_size);
vec_free (tmpbuf);
am->replay_in_progress = 0;
}
+/** api_trace_command_fn - control the binary API trace / replay feature
+
+ Note: this command MUST be marked thread-safe. Replay with
+ multiple worker threads depends in many cases on worker thread
+ graph replica maintenance. If we (implicitly) assert a worker
+ thread barrier at the debug CLI level, all graph replica changes
+ are deferred until the replay operation completes. If an interface
+ is deleted, the wheels fall off.
+ */
+
static clib_error_t *
api_trace_command_fn (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
u32 nitems = 256 << 10;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
vl_api_trace_which_t which = VL_API_TRACE_RX;
u8 *filename = 0;
u8 *chroot_filename = 0;
{
if (unformat (input, "nitems %d", &nitems))
;
+ vlib_worker_thread_barrier_sync (vm);
vl_msg_api_trace_configure (am, which, nitems);
vl_msg_api_trace_onoff (am, which, 1 /* on */ );
+ vlib_worker_thread_barrier_release (vm);
}
else if (unformat (input, "off"))
{
+ vlib_worker_thread_barrier_sync (vm);
vl_msg_api_trace_onoff (am, which, 0);
+ vlib_worker_thread_barrier_release (vm);
}
else if (unformat (input, "save %s", &filename))
{
vlib_cli_output (vm, "Couldn't create %s\n", chroot_filename);
goto out;
}
+ vlib_worker_thread_barrier_sync (vm);
rv = vl_msg_api_trace_save (am, which, fp);
+ vlib_worker_thread_barrier_release (vm);
fclose (fp);
if (rv == -1)
vlib_cli_output (vm, "API Trace data not present\n");
}
else if (unformat (input, "free"))
{
+ vlib_worker_thread_barrier_sync (vm);
vl_msg_api_trace_onoff (am, which, 0);
vl_msg_api_trace_free (am, which);
+ vlib_worker_thread_barrier_release (vm);
}
else if (unformat (input, "post-mortem-on"))
vl_msg_api_post_mortem_dump_enable_disable (1 /* enable */ );
{
.path = "api trace",
.short_help = "api trace [on|off][first <n>][last <n>][status][free]"
- "[post-mortem-on][dump|custom-dump|save|replay <file>]",
+ "[post-mortem-on][dump|custom-dump|save|replay <file>]",
.function = api_trace_command_fn,
+ .is_mp_safe = 1,
};
/* *INDENT-ON* */
{
u32 nitems = 1024;
vl_api_trace_which_t which = VL_API_TRACE_RX;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
{
u32 nitems = 256 << 10;
vl_api_trace_which_t which = VL_API_TRACE_RX;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
static clib_error_t *
api_queue_config_fn (vlib_main_t * vm, unformat_input_t * input)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
u32 nitems;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
vlib_cli_command_t * cmd)
{
u8 *filename = 0;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
serialize_main_t _sm, *sm = &_sm;
clib_error_t *error;
u32 nmsgs;
item->crc = extract_crc (name_and_crc);
item->which = 0; /* file */
}
- serialize_close (sm);
+ unserialize_close (sm);
/* Compare with the current image? */
if (compare_current)