#include <vlibmemory/memory_client.h>
#include <vapi/memclnt.api.vapi.h>
+#include <vapi/vlib.api.vapi.h>
/* we need to use control pings for some stuff and because we're forced to put
* the code in headers, we need a way to be able to grab the ids of these
vapi_msg_id_t vapi_msg_id_control_ping_reply = 0;
DEFINE_VAPI_MSG_IDS_MEMCLNT_API_JSON;
-DEFINE_VAPI_MSG_IDS_VPE_API_JSON;
+DEFINE_VAPI_MSG_IDS_VLIB_API_JSON;
struct
{
return NULL;
}
void *rv = vl_msg_api_alloc_or_null (size);
+ if (rv)
+ {
+ clib_memset (rv, 0, size);
+ }
return rv;
}
goto out;
}
int tmp;
- svm_queue_t *q = api_main.shmem_hdr->vl_input_queue;
+ svm_queue_t *q = vlibapi_get_main ()->shmem_hdr->vl_input_queue;
#if VAPI_DEBUG
unsigned msgid = be16toh (*(u16 *) msg);
if (msgid <= ctx->vl_msg_id_max)
rv = VAPI_EINVAL;
goto out;
}
- svm_queue_t *q = api_main.shmem_hdr->vl_input_queue;
+ svm_queue_t *q = vlibapi_get_main ()->shmem_hdr->vl_input_queue;
#if VAPI_DEBUG
unsigned msgid1 = be16toh (*(u16 *) msg1);
unsigned msgid2 = be16toh (*(u16 *) msg2);
return VAPI_EINVAL;
}
vapi_error_e rv = VAPI_OK;
- api_main_t *am = &api_main;
+ api_main_t *am = vlibapi_get_main ();
uword data;
if (am->our_pid == 0)
return __vapi_metadata.msgs[id]->has_context;
}
+static int
+vapi_verify_msg_size (vapi_msg_id_t id, void *buf, uword buf_size)
+{
+ assert (id < __vapi_metadata.count);
+ return __vapi_metadata.msgs[id]->verify_msg_size (buf, buf_size);
+}
+
vapi_error_e
vapi_dispatch_one (vapi_ctx_t ctx)
{
VAPI_DBG ("vapi_dispatch_one()");
void *msg;
- size_t size;
+ uword size;
vapi_error_e rv = vapi_recv (ctx, &msg, &size, SVM_Q_WAIT, 0);
if (VAPI_OK != rv)
{
return VAPI_EINVAL;
}
const vapi_msg_id_t id = ctx->vl_msg_id_to_vapi_msg_t[vpp_id];
- const size_t expect_size = vapi_get_message_size (id);
- if (size < expect_size)
+ if (vapi_verify_msg_size (id, msg, size))
{
- VAPI_ERR
- ("Invalid msg received, unexpected size `%zu' < expected min `%zu'",
- size, expect_size);
vapi_msg_free (ctx, msg);
return VAPI_EINVAL;
}
int
vapi_get_client_index (vapi_ctx_t ctx)
{
- return api_main.my_client_index;
+ return vlibapi_get_main ()->my_client_index;
}
bool
return __vapi_metadata.msgs[id]->swap_to_be;
}
-size_t
-vapi_get_message_size (vapi_msg_id_t id)
-{
- assert (id < __vapi_metadata.count);
- return __vapi_metadata.msgs[id]->size;
-}
-
size_t
vapi_get_context_offset (vapi_msg_id_t id)
{