ip: add the missing offload check
[vpp.git] / src / vlibmemory / memory_api.c
index ecdcc72..01fe49b 100644 (file)
@@ -28,7 +28,6 @@
 #undef vl_typedefs
 
 /* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 #define vl_printfun
 #include <vlibmemory/vl_memory_api_h.h>
 #undef vl_printfun
@@ -504,18 +503,21 @@ vl_mem_api_init (const char *region_name)
   if ((rv = vl_map_shmem (region_name, 1 /* is_vlib */ )) < 0)
     return rv;
 
-#define _(N,n,t) do {                                            \
-    c->id = VL_API_##N;                                         \
-    c->name = #n;                                               \
-    c->handler = vl_api_##n##_t_handler;                        \
-    c->cleanup = vl_noop_handler;                               \
-    c->endian = vl_api_##n##_t_endian;                          \
-    c->print = vl_api_##n##_t_print;                            \
-    c->size = sizeof(vl_api_##n##_t);                           \
-    c->traced = t; /* trace, so these msgs print */             \
-    c->replay = 0; /* don't replay client create/delete msgs */ \
-    c->message_bounce = 0; /* don't bounce this message */     \
-    vl_msg_api_config(c);} while (0);
+#define _(N, n, t)                                                            \
+  do                                                                          \
+    {                                                                         \
+      c->id = VL_API_##N;                                                     \
+      c->name = #n;                                                           \
+      c->handler = vl_api_##n##_t_handler;                                    \
+      c->endian = vl_api_##n##_t_endian;                                      \
+      c->format_fn = vl_api_##n##_t_format;                                   \
+      c->size = sizeof (vl_api_##n##_t);                                      \
+      c->traced = t;        /* trace, so these msgs print */                 \
+      c->replay = 0;        /* don't replay client create/delete msgs */     \
+      c->message_bounce = 0; /* don't bounce this message */                  \
+      vl_msg_api_config (c);                                                  \
+    }                                                                         \
+  while (0);
 
   foreach_vlib_api_msg;
 #undef _
@@ -532,9 +534,9 @@ vl_mem_api_init (const char *region_name)
    * special-case freeing of memclnt_delete messages, so we can
    * simply munmap pairwise / private API segments...
    */
-  am->message_bounce[VL_API_MEMCLNT_DELETE] = 1;
-  am->is_mp_safe[VL_API_MEMCLNT_KEEPALIVE_REPLY] = 1;
-  am->is_mp_safe[VL_API_MEMCLNT_KEEPALIVE] = 1;
+  am->msg_data[VL_API_MEMCLNT_DELETE].bounce = 1;
+  vl_api_set_msg_thread_safe (am, VL_API_MEMCLNT_KEEPALIVE_REPLY, 1);
+  vl_api_set_msg_thread_safe (am, VL_API_MEMCLNT_KEEPALIVE, 1);
 
   vlib_set_queue_signal_callback (vm, memclnt_queue_callback);
 
@@ -768,8 +770,8 @@ vl_mem_api_handler_with_vm_node (api_main_t *am, svm_region_t *vlib_rp,
                                 vlib_node_runtime_t *node, u8 is_private)
 {
   u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
+  vl_api_msg_data_t *m = vl_api_get_msg_data (am, id);
   u8 *(*handler) (void *, void *, void *);
-  u8 *(*print_fp) (void *, void *);
   svm_region_t *old_vlib_rp;
   void *save_shmem_hdr;
   int is_mp_safe = 1;
@@ -785,37 +787,29 @@ vl_mem_api_handler_with_vm_node (api_main_t *am, svm_region_t *vlib_rp,
        u32 c;
       } * ed;
       ed = ELOG_DATA (am->elog_main, e);
-      if (id < vec_len (am->msg_names) && am->msg_names[id])
-       ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
+      if (m && m->name)
+       ed->c = elog_string (am->elog_main, (char *) m->name);
       else
        ed->c = elog_string (am->elog_main, "BOGUS");
     }
 
-  if (id < vec_len (am->msg_handlers) && am->msg_handlers[id])
+  if (m && m->handler)
     {
-      handler = (void *) am->msg_handlers[id];
+      handler = (void *) m->handler;
 
       if (PREDICT_FALSE (am->rx_trace && am->rx_trace->enabled))
        vl_msg_api_trace (am, am->rx_trace, the_msg);
 
       if (PREDICT_FALSE (am->msg_print_flag))
        {
-         fformat (stdout, "[%d]: %s\n", id, am->msg_names[id]);
-         print_fp = (void *) am->msg_print_handlers[id];
-         if (print_fp == 0)
-           {
-             fformat (stdout, "  [no registered print fn for msg %d]\n", id);
-           }
-         else
-           {
-             (*print_fp) (the_msg, vm);
-           }
+         fformat (stdout, "[%d]: %s\n", id, m->name);
+         fformat (stdout, "%U", format_vl_api_msg_text, am, id, the_msg);
        }
-      is_mp_safe = am->is_mp_safe[id];
+      is_mp_safe = am->msg_data[id].is_mp_safe;
 
       if (!is_mp_safe)
        {
-         vl_msg_api_barrier_trace_context (am->msg_names[id]);
+         vl_msg_api_barrier_trace_context (am->msg_data[id].name);
          vl_msg_api_barrier_sync ();
        }
       if (is_private)
@@ -829,10 +823,10 @@ vl_mem_api_handler_with_vm_node (api_main_t *am, svm_region_t *vlib_rp,
       if (PREDICT_FALSE (vl_mem_api_fuzz_hook != 0))
        (*vl_mem_api_fuzz_hook) (id, the_msg);
 
-      if (am->is_autoendian[id])
+      if (m->is_autoendian)
        {
          void (*endian_fp) (void *);
-         endian_fp = am->msg_endian_handlers[id];
+         endian_fp = am->msg_data[id].endian_handler;
          (*endian_fp) (the_msg);
        }
       if (PREDICT_FALSE (vec_len (am->perf_counter_cbs) != 0))
@@ -859,7 +853,7 @@ vl_mem_api_handler_with_vm_node (api_main_t *am, svm_region_t *vlib_rp,
    * Special-case, so we can e.g. bounce messages off the vnet
    * main thread without copying them...
    */
-  if (id >= vec_len (am->message_bounce) || !(am->message_bounce[id]))
+  if (!m || !m->bounce)
     {
       if (is_private)
        {
@@ -892,8 +886,8 @@ vl_mem_api_handler_with_vm_node (api_main_t *am, svm_region_t *vlib_rp,
        u32 c;
       } * ed;
       ed = ELOG_DATA (am->elog_main, e);
-      if (id < vec_len (am->msg_names) && am->msg_names[id])
-       ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]);
+      if (m && m->name)
+       ed->c = elog_string (am->elog_main, (char *) m->name);
       else
        ed->c = elog_string (am->elog_main, "BOGUS");
       ed->barrier = is_mp_safe;