Fix issues reported by coverity
[vpp.git] / vpp / vpp-api / api.c
index da2d3bb..330b915 100644 (file)
@@ -8628,6 +8628,9 @@ vl_api_sw_interface_span_dump_t_handler (vl_api_sw_interface_span_dump_t * mp)
   u32 src_sw_if_index = 0, *dst_sw_if_index;
 
   q = vl_api_client_index_to_input_queue (mp->client_index);
+  if (!q)
+    return;
+
   vec_foreach (dst_sw_if_index, sm->dst_by_src_sw_if_index)
   {
     if (*dst_sw_if_index > 0)
@@ -9184,7 +9187,6 @@ vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
 
   u8 *arc_name = format (0, "%s%c", mp->arc_name, 0);
   u8 *feature_name = format (0, "%s%c", mp->feature_name, 0);
-  u32 sw_if_index = ntohl (mp->sw_if_index);
 
   vnet_feature_registration_t *reg;
   reg =
@@ -9194,8 +9196,10 @@ vl_api_feature_enable_disable_t_handler (vl_api_feature_enable_disable_t * mp)
     rv = VNET_API_ERROR_INVALID_VALUE;
   else
     {
+      u32 sw_if_index;
       clib_error_t *error = 0;
 
+      sw_if_index = ntohl (mp->sw_if_index);
       if (reg->enable_disable_cb)
        error = reg->enable_disable_cb (sw_if_index, mp->enable);
       if (!error)
@@ -9245,6 +9249,8 @@ static void vl_api_##nn##_t_handler (                                   \
     vl_msg_api_free (mp);                                               \
 }
 
+static void setup_message_id_table (api_main_t * am);
+
 /*
  * vpe_api_hookup
  * Add vpe's API message handlers to the table.
@@ -9252,7 +9258,6 @@ static void vl_api_##nn##_t_handler (                                   \
  * added the client registration handlers.
  * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
  */
-
 static clib_error_t *
 vpe_api_hookup (vlib_main_t * vm)
 {
@@ -9306,6 +9311,11 @@ vpe_api_hookup (vlib_main_t * vm)
   am->is_mp_safe[VL_API_IP_ADD_DEL_ROUTE] = 1;
   am->is_mp_safe[VL_API_GET_NODE_GRAPH] = 1;
 
+  /*
+   * Set up the (msg_name, crc, message-id) table
+   */
+  setup_message_id_table (am);
+
   return 0;
 }
 
@@ -9459,24 +9469,6 @@ get_unformat_vnet_sw_interface (void)
   return (void *) &unformat_vnet_sw_interface;
 }
 
-#undef vl_api_version
-#define vl_api_version(n,v) static u32 vpe_api_version = v;
-#include <vpp-api/vpe.api.h>
-#undef vl_api_version
-
-int
-vl_msg_api_version_check (vl_api_memclnt_create_t * mp)
-{
-  if (clib_host_to_net_u32 (mp->api_versions[0]) != vpe_api_version)
-    {
-      clib_warning ("vpe API mismatch: 0x%08x instead of 0x%08x",
-                   clib_host_to_net_u32 (mp->api_versions[0]),
-                   vpe_api_version);
-      return -1;
-    }
-  return 0;
-}
-
 static u8 *
 format_arp_event (u8 * s, va_list * args)
 {
@@ -9540,6 +9532,20 @@ VLIB_CLI_COMMAND (show_ip_arp_nd_events, static) = {
 };
 /* *INDENT-ON* */
 
+#define vl_msg_name_crc_list
+#include <vpp-api/vpe_all_api_h.h>
+#undef vl_msg_name_crc_list
+
+static void
+setup_message_id_table (api_main_t * am)
+{
+#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
+  foreach_vl_msg_name_crc_memclnt;
+  foreach_vl_msg_name_crc_vpe;
+#undef _
+}
+
+
 /*
  * fd.io coding-style-patch-verification: ON
  *