vam->my_client_index = (u32) ~ 0;
/* Ensure that vam->inbuf is never NULL */
vec_validate (vam->inbuf, 0);
+ vec_validate (vam->cmd_reply, 0);
+ vec_reset_length (vam->cmd_reply);
init_error_string_table (vam);
rv = vat_plugin_init (vam);
if (rv)
clib_warning ("vat_plugin_init returned %d", rv);
+
return 0;
}
-VLIB_INIT_FUNCTION (api_main_init);
+VLIB_MAIN_LOOP_ENTER_FUNCTION (api_main_init);
void
vat_plugin_hash_create (void)
vam->help_by_name = hash_create_string (0, sizeof (uword));
}
+static void
+maybe_register_api_client (vat_main_t * vam)
+{
+ vl_api_registration_t **regpp;
+ vl_api_registration_t *regp;
+ void *oldheap;
+ api_main_t *am = vlibapi_get_main ();
+
+ if (vam->my_client_index != ~0)
+ return;
+
+ pool_get (am->vl_clients, regpp);
+
+ oldheap = vl_msg_push_heap ();
+
+ *regpp = clib_mem_alloc (sizeof (vl_api_registration_t));
+
+ regp = *regpp;
+ clib_memset (regp, 0, sizeof (*regp));
+ regp->registration_type = REGISTRATION_TYPE_SHMEM;
+ regp->vl_api_registration_pool_index = regpp - am->vl_clients;
+ regp->vlib_rp = am->vlib_rp;
+ regp->shmem_hdr = am->shmem_hdr;
+
+ /* Loopback connection */
+ regp->vl_input_queue = am->shmem_hdr->vl_input_queue;
+
+ regp->name = format (0, "%s", "vpp-internal");
+ vec_add1 (regp->name, 0);
+
+ vl_msg_pop_heap (oldheap);
+
+ vam->my_client_index = vl_msg_api_handle_from_index_and_epoch
+ (regp->vl_api_registration_pool_index,
+ am->shmem_hdr->application_restarts);
+
+ vam->vl_input_queue = am->shmem_hdr->vl_input_queue;
+ api_sw_interface_dump (vam);
+}
+
static clib_error_t *
api_command_fn (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
u32 arg_len;
int rv;
int (*fp) (vat_main_t *);
- api_main_t *am = &api_main;
- vam->vl_input_queue = am->shmem_hdr->vl_input_queue;
+ maybe_register_api_client (vam);
/* vec_validated in the init routine */
_vec_len (vam->inbuf) = 0;
.path = "binary-api",
.short_help = "binary-api [help] <name> [<args>]",
.function = api_command_fn,
+ .is_mp_safe = 1,
};
/* *INDENT-ON* */
u16
vl_client_get_first_plugin_msg_id (const char *plugin_name)
{
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
vl_api_msg_range_t *rp;
uword *p;
uword
unformat_sw_if_index (unformat_input_t * input, va_list * args)
{
+ void *vam_unused = va_arg (*args, void *);
+ (void) (vam_unused);
u32 *result = va_arg (*args, u32 *);
vnet_main_t *vnm = vnet_get_main ();
u32 sw_if_index = ~0;
- u8 *if_name;
- uword *p;
if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
{