API: Fix shared memory only action handlers. 85/18785/2
authorOle Troan <ot@cisco.com>
Wed, 10 Apr 2019 07:44:23 +0000 (09:44 +0200)
committerDave Wallace <dwallacelf@gmail.com>
Wed, 10 Apr 2019 13:06:45 +0000 (13:06 +0000)
Some API action handlers called vl_msg_ai_send_shmem()
directly. That breaks Unix domain socket API transport.

A couple (bond / vhost) also tried to send a sw_interface_event
directly, but did not send the message to all that had
registred interest. That scheme never worked correctly.
Refactored and improved the interface event code.

Change-Id: Idb90edfd8703c6ae593b36b4eeb4d3ed7da5c808
Signed-off-by: Ole Troan <ot@cisco.com>
18 files changed:
src/plugins/abf/abf_api.c
src/plugins/acl/acl.c
src/plugins/igmp/igmp_api.c
src/plugins/ioam/lib-trace/trace_api.c
src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c
src/plugins/nat/nat_api.c
src/plugins/nsh/nsh_api.c
src/plugins/svs/svs_api.c
src/vlibmemory/memory_client.c
src/vlibmemory/memory_shared.h
src/vnet/bonding/bond_api.c
src/vnet/devices/tap/tapv2_api.c
src/vnet/devices/virtio/vhost_user_api.c
src/vnet/devices/virtio/virtio_api.c
src/vnet/interface_api.c
src/vnet/ip/ip_api.c
test/framework.py
test/test_vhost.py

index bf25669..9da0839 100644 (file)
@@ -72,24 +72,20 @@ static void
 vl_api_abf_plugin_get_version_t_handler (vl_api_abf_plugin_get_version_t * mp)
 {
   vl_api_abf_plugin_get_version_reply_t *rmp;
-  int msg_size = sizeof (*rmp);
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
+    return;
 
-  rmp = vl_msg_api_alloc (msg_size);
-  clib_memset (rmp, 0, msg_size);
+  rmp = vl_msg_api_alloc (sizeof (*rmp));
   rmp->_vl_msg_id =
     ntohs (VL_API_ABF_PLUGIN_GET_VERSION_REPLY + abf_base_msg_id);
   rmp->context = mp->context;
   rmp->major = htonl (ABF_PLUGIN_VERSION_MAJOR);
   rmp->minor = htonl (ABF_PLUGIN_VERSION_MINOR);
 
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  vl_api_send_msg (rp, (u8 *) rmp);
 }
 
 static void
@@ -155,7 +151,7 @@ vl_api_abf_itf_attach_add_del_t_handler (vl_api_abf_itf_attach_add_del_t * mp)
 
 typedef struct abf_dump_walk_ctx_t_
 {
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
   u32 context;
 } abf_dump_walk_ctx_t;
 
@@ -194,7 +190,7 @@ abf_policy_send_details (u32 api, void *args)
     fp++;
   }
 
-  vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
+  vl_api_send_msg (ctx->rp, (u8 *) mp);
 
   return (1);
 }
@@ -202,16 +198,14 @@ abf_policy_send_details (u32 api, void *args)
 static void
 vl_api_abf_policy_dump_t_handler (vl_api_abf_policy_dump_t * mp)
 {
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
+    return;
 
   abf_dump_walk_ctx_t ctx = {
-    .q = q,
+    .rp = rp,
     .context = mp->context,
   };
 
@@ -239,7 +233,7 @@ abf_itf_attach_send_details (u32 aiai, void *args)
   mp->attach.priority = htonl (aia->aia_prio);
   mp->attach.is_ipv6 = (aia->aia_proto == FIB_PROTOCOL_IP6);
 
-  vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
+  vl_api_send_msg (ctx->rp, (u8 *) mp);
 
   return (1);
 }
@@ -247,16 +241,14 @@ abf_itf_attach_send_details (u32 aiai, void *args)
 static void
 vl_api_abf_itf_attach_dump_t_handler (vl_api_abf_itf_attach_dump_t * mp)
 {
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
+    return;
 
   abf_dump_walk_ctx_t ctx = {
-    .q = q,
+    .rp = rp,
     .context = mp->context,
   };
 
index 396fe1f..63aafec 100644 (file)
@@ -305,13 +305,11 @@ static void
   acl_main_t *am = &acl_main;
   vl_api_acl_plugin_get_conn_table_max_entries_reply_t *rmp;
   int msg_size = sizeof (*rmp);
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
+    return;
 
   rmp = vl_msg_api_alloc (msg_size);
   memset (rmp, 0, msg_size);
@@ -321,7 +319,7 @@ static void
   rmp->context = mp->context;
   rmp->conn_table_max_entries = __bswap_64 (am->fa_conn_table_max_entries);
 
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  vl_api_send_msg (rp, (u8 *) rmp);
 }
 
 static void
index 0149b2a..d619abd 100644 (file)
@@ -160,7 +160,7 @@ static void
 }
 
 static void
-send_igmp_details (unix_shared_memory_queue_t * q, igmp_main_t * im,
+send_igmp_details (vl_api_registration_t * rp, igmp_main_t * im,
                   igmp_config_t * config, igmp_group_t * group,
                   igmp_src_t * src, u32 context)
 {
@@ -175,12 +175,12 @@ send_igmp_details (unix_shared_memory_queue_t * q, igmp_main_t * im,
   clib_memcpy (&mp->saddr, &src->key->ip4, sizeof (src->key->ip4));
   clib_memcpy (&mp->gaddr, &group->key->ip4, sizeof (group->key->ip4));
 
-  vl_msg_api_send_shmem (q, (u8 *) & mp);
+  vl_api_send_msg (rp, (u8 *) mp);
 }
 
 static void
 igmp_config_dump (igmp_main_t * im,
-                 unix_shared_memory_queue_t * q,
+                 vl_api_registration_t * rp,
                  u32 context, igmp_config_t * config)
 {
   igmp_group_t *group;
@@ -191,7 +191,7 @@ igmp_config_dump (igmp_main_t * im,
     ({
       FOR_EACH_SRC (src, group, IGMP_FILTER_MODE_INCLUDE,
         ({
-          send_igmp_details (q, im, config, group, src, context);
+          send_igmp_details (rp, im, config, group, src, context);
         }));
     }));
   /* *INDENT-ON* */
@@ -200,13 +200,13 @@ igmp_config_dump (igmp_main_t * im,
 static void
 vl_api_igmp_dump_t_handler (vl_api_igmp_dump_t * mp)
 {
-  unix_shared_memory_queue_t *q;
   igmp_main_t *im = &igmp_main;
   igmp_config_t *config;
   u32 sw_if_index;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
     return;
 
   sw_if_index = ntohl (mp->sw_if_index);
@@ -215,7 +215,7 @@ vl_api_igmp_dump_t_handler (vl_api_igmp_dump_t * mp)
       /* *INDENT-OFF* */
       pool_foreach (config, im->configs,
         ({
-          igmp_config_dump(im, q, mp->context, config);
+          igmp_config_dump(im, rp, mp->context, config);
         }));
       /* *INDENT-ON* */
     }
@@ -224,7 +224,7 @@ vl_api_igmp_dump_t_handler (vl_api_igmp_dump_t * mp)
       config = igmp_config_lookup (sw_if_index);
       if (config)
        {
-         igmp_config_dump (im, q, mp->context, config);
+         igmp_config_dump (im, rp, mp->context, config);
        }
     }
 }
@@ -286,7 +286,7 @@ vl_api_igmp_group_prefix_set_t_handler (vl_api_igmp_group_prefix_set_t * mp)
 
 typedef struct igmp_ssm_range_walk_ctx_t_
 {
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
   u32 context;
 } igmp_ssm_range_walk_ctx_t;
 
@@ -305,7 +305,7 @@ igmp_ssm_range_walk_dump (const fib_prefix_t * pfx,
   mp->gp.type = igmp_group_type_int_to_api (type);
   ip_prefix_encode (pfx, &mp->gp.prefix);
 
-  vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
+  vl_api_send_msg (ctx->rp, (u8 *) mp);
 
   return (WALK_CONTINUE);
 }
@@ -313,14 +313,14 @@ igmp_ssm_range_walk_dump (const fib_prefix_t * pfx,
 static void
 vl_api_igmp_group_prefix_dump_t_handler (vl_api_igmp_dump_t * mp)
 {
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
     return;
 
   igmp_ssm_range_walk_ctx_t ctx = {
-    .q = q,
+    .rp = rp,
     .context = mp->context,
   };
 
@@ -398,7 +398,7 @@ want_igmp_events_reaper (u32 client_index)
 VL_MSG_API_REAPER_FUNCTION (want_igmp_events_reaper);
 
 void
-send_igmp_event (unix_shared_memory_queue_t * q,
+send_igmp_event (vl_api_registration_t * rp,
                 u32 context,
                 igmp_filter_mode_t filter,
                 u32 sw_if_index,
@@ -414,7 +414,7 @@ send_igmp_event (unix_shared_memory_queue_t * q,
   clib_memcpy (&mp->saddr, &saddr->ip4, sizeof (ip4_address_t));
   clib_memcpy (&mp->gaddr, &gaddr->ip4, sizeof (ip4_address_t));
 
-  vl_msg_api_send_shmem (q, (u8 *) & mp);
+  vl_api_send_msg (rp, (u8 *) mp);
 }
 
 void
@@ -423,7 +423,7 @@ igmp_event (igmp_filter_mode_t filter,
            const ip46_address_t * saddr, const ip46_address_t * gaddr)
 {
   vpe_client_registration_t *api_client;
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
   igmp_main_t *im;
 
   im = &igmp_main;
@@ -438,9 +438,9 @@ igmp_event (igmp_filter_mode_t filter,
   /* *INDENT-OFF* */
   pool_foreach (api_client, im->api_clients,
     ({
-      q = vl_api_client_index_to_input_queue (api_client->client_index);
-      if (q)
-        send_igmp_event (q, 0, filter, sw_if_index, saddr, gaddr);
+      rp = vl_api_client_index_to_registration (api_client->client_index);
+      if (rp)
+        send_igmp_event (rp, 0, filter, sw_if_index, saddr, gaddr);
     }));
   /* *INDENT-ON* */
 }
index bb043f7..f74d4e7 100644 (file)
@@ -23,7 +23,7 @@
 #include <vnet/plugin/plugin.h>
 #include <ioam/lib-trace/trace_util.h>
 #include <ioam/lib-trace/trace_config.h>
-
+#include <vlibapi/api_helper_macros.h>
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
 
 #include <ioam/lib-trace/trace_all_api_h.h>
 #undef vl_api_version
 
-/*
- * A handy macro to set up a message reply.
- * Assumes that the following variables are available:
- * mp - pointer to request message
- * rmp - pointer to reply message type
- * rv - return value
- */
-
-#define TRACE_REPLY_MACRO(t)                                          \
-do {                                                            \
-    svm_queue_t * q =                            \
-    vl_api_client_index_to_input_queue (mp->client_index);      \
-    if (!q)                                                     \
-        return;                                                 \
-                                                                \
-    rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
-    rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-                                                                \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-
-/* *INDENT-OFF* */
-#define TRACE_REPLY_MACRO2(t, body)                                   \
-do {                                                            \
-    svm_queue_t * q;                             \
-    rv = vl_msg_api_pd_handler (mp, rv);                        \
-    q = vl_api_client_index_to_input_queue (mp->client_index);  \
-    if (!q)                                                     \
-        return;                                                 \
-                                                                \
-    rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
-    rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-    do {body;} while (0);                                       \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-/* *INDENT-ON* */
-
 /* List of message types that this plugin understands */
 
 #define foreach_trace_plugin_api_msg                                      \
@@ -103,7 +62,6 @@ _(TRACE_PROFILE_SHOW_CONFIG, trace_profile_show_config)
 static void vl_api_trace_profile_add_t_handler
   (vl_api_trace_profile_add_t * mp)
 {
-  trace_main_t *sm = &trace_main;
   int rv = 0;
   vl_api_trace_profile_add_reply_t *rmp;
   trace_profile *profile = NULL;
@@ -123,45 +81,43 @@ static void vl_api_trace_profile_add_t_handler
       rv = -3;
     }
 ERROROUT:
-  TRACE_REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
+  REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
 }
 
 
 static void vl_api_trace_profile_del_t_handler
   (vl_api_trace_profile_del_t * mp)
 {
-  trace_main_t *sm = &trace_main;
   int rv = 0;
   vl_api_trace_profile_del_reply_t *rmp;
 
   clear_trace_profiles ();
 
-  TRACE_REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
+  REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
 }
 
 static void vl_api_trace_profile_show_config_t_handler
   (vl_api_trace_profile_show_config_t * mp)
 {
-  trace_main_t *sm = &trace_main;
   vl_api_trace_profile_show_config_reply_t *rmp;
   int rv = 0;
   trace_profile *profile = trace_profile_find ();
   if (profile->valid)
     {
-      TRACE_REPLY_MACRO2 (VL_API_TRACE_PROFILE_SHOW_CONFIG_REPLY,
-                         rmp->trace_type = profile->trace_type;
-                         rmp->num_elts = profile->num_elts;
-                         rmp->trace_tsp = profile->trace_tsp;
-                         rmp->node_id = htonl (profile->node_id);
-                         rmp->app_data = htonl (profile->app_data);
+      REPLY_MACRO2 (VL_API_TRACE_PROFILE_SHOW_CONFIG_REPLY,
+                   rmp->trace_type = profile->trace_type;
+                   rmp->num_elts = profile->num_elts;
+                   rmp->trace_tsp = profile->trace_tsp;
+                   rmp->node_id = htonl (profile->node_id);
+                   rmp->app_data = htonl (profile->app_data);
        );
     }
   else
     {
-      TRACE_REPLY_MACRO2 (VL_API_TRACE_PROFILE_SHOW_CONFIG_REPLY,
-                         rmp->trace_type = 0;
-                         rmp->num_elts = 0; rmp->trace_tsp = 0;
-                         rmp->node_id = 0; rmp->app_data = 0;
+      REPLY_MACRO2 (VL_API_TRACE_PROFILE_SHOW_CONFIG_REPLY,
+                   rmp->trace_type = 0;
+                   rmp->num_elts = 0; rmp->trace_tsp = 0;
+                   rmp->node_id = 0; rmp->app_data = 0;
        );
     }
 }
index 2d9c6bf..e46d0fb 100644 (file)
@@ -22,7 +22,7 @@
 #include <vnet/vnet.h>
 #include <vnet/plugin/plugin.h>
 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
-
+#include <vlibapi/api_helper_macros.h>
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
 
 #include <ioam/lib-vxlan-gpe/vxlan_gpe_all_api_h.h>
 #undef vl_api_version
 
-/*
- * A handy macro to set up a message reply.
- * Assumes that the following variables are available:
- * mp - pointer to request message
- * rmp - pointer to reply message type
- * rv - return value
- */
-
-#define VXLAN_GPE_REPLY_MACRO(t)                                \
-do {                                                            \
-    svm_queue_t * q =                            \
-    vl_api_client_index_to_input_queue (mp->client_index);      \
-    if (!q)                                                     \
-        return;                                                 \
-                                                                \
-    rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
-    rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base);               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-                                                                \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-
-/* *INDENT-OFF* */
-#define VXLAN_GPE_REPLY_MACRO2(t, body)                         \
-do {                                                            \
-    svm_queue_t * q;                             \
-    rv = vl_msg_api_pd_handler (mp, rv);                        \
-    q = vl_api_client_index_to_input_queue (mp->client_index);  \
-    if (!q)                                                     \
-        return;                                                 \
-                                                                \
-    rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
-    rmp->_vl_msg_id = ntohs((t));                               \
-    rmp->context = mp->context;                                 \
-    rmp->retval = ntohl(rv);                                    \
-    do {body;} while (0);                                       \
-    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-} while(0);
-/* *INDENT-ON* */
-
 /* List of message types that this plugin understands */
 
 #define foreach_vxlan_gpe_plugin_api_msg                               \
@@ -109,7 +68,6 @@ static void vl_api_vxlan_gpe_ioam_enable_t_handler
   int rv = 0;
   vl_api_vxlan_gpe_ioam_enable_reply_t *rmp;
   clib_error_t *error;
-  vxlan_gpe_ioam_main_t *sm = &vxlan_gpe_ioam_main;
 
   /* Ignoring the profile id as currently a single profile
    * is supported */
@@ -121,7 +79,7 @@ static void vl_api_vxlan_gpe_ioam_enable_t_handler
       rv = clib_error_get_code (error);
     }
 
-  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_ENABLE_REPLY);
+  REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_ENABLE_REPLY);
 }
 
 static void vl_api_vxlan_gpe_ioam_disable_t_handler
@@ -130,7 +88,6 @@ static void vl_api_vxlan_gpe_ioam_disable_t_handler
   int rv = 0;
   vl_api_vxlan_gpe_ioam_disable_reply_t *rmp;
   clib_error_t *error;
-  vxlan_gpe_ioam_main_t *sm = &vxlan_gpe_ioam_main;
 
   /* Ignoring the profile id as currently a single profile
    * is supported */
@@ -141,7 +98,7 @@ static void vl_api_vxlan_gpe_ioam_disable_t_handler
       rv = clib_error_get_code (error);
     }
 
-  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_DISABLE_REPLY);
+  REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_DISABLE_REPLY);
 }
 
 static void vl_api_vxlan_gpe_ioam_vni_enable_t_handler
@@ -150,7 +107,6 @@ static void vl_api_vxlan_gpe_ioam_vni_enable_t_handler
   int rv = 0;
   vl_api_vxlan_gpe_ioam_vni_enable_reply_t *rmp;
   clib_error_t *error;
-  vxlan_gpe_ioam_main_t *sm = &vxlan_gpe_ioam_main;
   vxlan4_gpe_tunnel_key_t key4;
   uword *p = NULL;
   vxlan_gpe_main_t *gm = &vxlan_gpe_main;
@@ -190,7 +146,7 @@ static void vl_api_vxlan_gpe_ioam_vni_enable_t_handler
       rv = clib_error_get_code (error);
     }
 
-  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_VNI_ENABLE_REPLY);
+  REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_VNI_ENABLE_REPLY);
 }
 
 
@@ -200,7 +156,6 @@ static void vl_api_vxlan_gpe_ioam_vni_disable_t_handler
   int rv = 0;
   vl_api_vxlan_gpe_ioam_vni_enable_reply_t *rmp;
   clib_error_t *error;
-  vxlan_gpe_ioam_main_t *sm = &vxlan_gpe_ioam_main;
   vxlan4_gpe_tunnel_key_t key4;
   uword *p = NULL;
   vxlan_gpe_main_t *gm = &vxlan_gpe_main;
@@ -238,7 +193,7 @@ static void vl_api_vxlan_gpe_ioam_vni_disable_t_handler
     }
 
 
-  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_VNI_DISABLE_REPLY);
+  REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_VNI_DISABLE_REPLY);
 }
 
 static void vl_api_vxlan_gpe_ioam_transit_enable_t_handler
@@ -260,7 +215,7 @@ static void vl_api_vxlan_gpe_ioam_transit_enable_t_handler
                                               mp->is_ipv6 ? 0 : 1,
                                               1 /* is_add */ );
 
-  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_TRANSIT_ENABLE_REPLY);
+  REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_TRANSIT_ENABLE_REPLY);
 }
 
 static void vl_api_vxlan_gpe_ioam_transit_disable_t_handler
@@ -281,7 +236,7 @@ static void vl_api_vxlan_gpe_ioam_transit_disable_t_handler
                                        dst_addr,
                                        ntohl (mp->outer_fib_index),
                                        mp->is_ipv6 ? 0 : 1);
-  VXLAN_GPE_REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_TRANSIT_DISABLE_REPLY);
+  REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_TRANSIT_DISABLE_REPLY);
 }
 
 /* Set up the API message handling tables */
index 516b27f..21b2cd4 100644 (file)
@@ -3267,7 +3267,7 @@ static void *vl_api_nat66_add_del_static_mapping_t_print
 
 typedef struct nat66_api_walk_ctx_t_
 {
-  svm_queue_t *q;
+  vl_api_registration_t *rp;
   u32 context;
 } nat66_api_walk_ctx_t;
 
@@ -3285,7 +3285,7 @@ nat66_api_interface_walk (snat_interface_t * i, void *arg)
   rmp->is_inside = nat_interface_is_inside (i);
   rmp->context = ctx->context;
 
-  vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
+  vl_api_send_msg (ctx->rp, (u8 *) rmp);
 
   return 0;
 }
@@ -3293,14 +3293,14 @@ nat66_api_interface_walk (snat_interface_t * i, void *arg)
 static void
 vl_api_nat66_interface_dump_t_handler (vl_api_nat66_interface_dump_t * mp)
 {
-  svm_queue_t *q;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
     return;
 
   nat66_api_walk_ctx_t ctx = {
-    .q = q,
+    .rp = rp,
     .context = mp->context,
   };
 
@@ -3345,7 +3345,7 @@ nat66_api_static_mapping_walk (nat66_static_mapping_t * m, void *arg)
   rmp->total_pkts = clib_host_to_net_u64 (vc.packets);
   rmp->context = ctx->context;
 
-  vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
+  vl_api_send_msg (ctx->rp, (u8 *) rmp);
 
   return 0;
 }
@@ -3354,14 +3354,14 @@ static void
 vl_api_nat66_static_mapping_dump_t_handler (vl_api_nat66_static_mapping_dump_t
                                            * mp)
 {
-  svm_queue_t *q;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
     return;
 
   nat66_api_walk_ctx_t ctx = {
-    .q = q,
+    .rp = rp,
     .context = mp->context,
   };
 
index cf9fd57..e541301 100644 (file)
@@ -124,7 +124,7 @@ VNET_DEVICE_CLASS (nsh_device_class, static) = {
 /* *INDENT-ON* */
 
 static void send_nsh_entry_details
-  (nsh_entry_t * t, unix_shared_memory_queue_t * q, u32 context)
+  (nsh_entry_t * t, vl_api_registration_t * rp, u32 context)
 {
   vl_api_nsh_entry_details_t *rmp;
   nsh_main_t *nm = &nsh_main;
@@ -157,11 +157,11 @@ static void send_nsh_entry_details
 
   rmp->context = context;
 
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  vl_api_send_msg (rp, (u8 *) rmp);
 }
 
 static void send_nsh_map_details
-  (nsh_map_t * t, unix_shared_memory_queue_t * q, u32 context)
+  (nsh_map_t * t, vl_api_registration_t * rp, u32 context)
 {
   vl_api_nsh_map_details_t *rmp;
   nsh_main_t *nm = &nsh_main;
@@ -179,22 +179,20 @@ static void send_nsh_map_details
 
   rmp->context = context;
 
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  vl_api_send_msg (rp, (u8 *) rmp);
 }
 
 static void
 vl_api_nsh_map_dump_t_handler (vl_api_nsh_map_dump_t * mp)
 {
-  unix_shared_memory_queue_t *q;
   nsh_main_t *nm = &nsh_main;
   nsh_map_t *t;
   u32 map_index;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
+    return;
 
   map_index = ntohl (mp->map_index);
 
@@ -202,7 +200,7 @@ vl_api_nsh_map_dump_t_handler (vl_api_nsh_map_dump_t * mp)
     {
       pool_foreach (t, nm->nsh_mappings, (
                                           {
-                                          send_nsh_map_details (t, q,
+                                          send_nsh_map_details (t, rp,
                                                                 mp->context);
                                           }
                    ));
@@ -214,7 +212,7 @@ vl_api_nsh_map_dump_t_handler (vl_api_nsh_map_dump_t * mp)
          return;
        }
       t = &nm->nsh_mappings[map_index];
-      send_nsh_map_details (t, q, mp->context);
+      send_nsh_map_details (t, rp, mp->context);
     }
 }
 
@@ -650,16 +648,14 @@ static void vl_api_nsh_add_del_entry_t_handler
 static void
 vl_api_nsh_entry_dump_t_handler (vl_api_nsh_entry_dump_t * mp)
 {
-  unix_shared_memory_queue_t *q;
   nsh_main_t *nm = &nsh_main;
   nsh_entry_t *t;
   u32 entry_index;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
+    return;
 
   entry_index = ntohl (mp->entry_index);
 
@@ -667,7 +663,7 @@ vl_api_nsh_entry_dump_t_handler (vl_api_nsh_entry_dump_t * mp)
     {
       pool_foreach (t, nm->nsh_entries, (
                                          {
-                                         send_nsh_entry_details (t, q,
+                                         send_nsh_entry_details (t, rp,
                                                                  mp->context);
                                          }
                    ));
@@ -679,7 +675,7 @@ vl_api_nsh_entry_dump_t_handler (vl_api_nsh_entry_dump_t * mp)
          return;
        }
       t = &nm->nsh_entries[entry_index];
-      send_nsh_entry_details (t, q, mp->context);
+      send_nsh_entry_details (t, rp, mp->context);
     }
 }
 
index 03941fe..068d2fa 100644 (file)
@@ -54,7 +54,6 @@
  * Base message ID fot the plugin
  */
 static u32 svs_base_msg_id;
-
 #include <vlibapi/api_helper_macros.h>
 
 /* List of message types that this plugin understands */
@@ -71,13 +70,11 @@ vl_api_svs_plugin_get_version_t_handler (vl_api_svs_plugin_get_version_t * mp)
 {
   vl_api_svs_plugin_get_version_reply_t *rmp;
   int msg_size = sizeof (*rmp);
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
+    return;
 
   rmp = vl_msg_api_alloc (msg_size);
   clib_memset (rmp, 0, msg_size);
@@ -87,7 +84,7 @@ vl_api_svs_plugin_get_version_t_handler (vl_api_svs_plugin_get_version_t * mp)
   rmp->major = htonl (SVS_PLUGIN_VERSION_MAJOR);
   rmp->minor = htonl (SVS_PLUGIN_VERSION_MINOR);
 
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  vl_api_send_msg (rp, (u8 *) rmp);
 }
 
 static void
@@ -160,7 +157,7 @@ vl_api_svs_enable_disable_t_handler (vl_api_svs_enable_disable_t * mp)
 
 typedef struct svs_dump_walk_ctx_t_
 {
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
   u32 context;
 } svs_dump_walk_ctx_t;
 
@@ -182,7 +179,7 @@ svs_send_details (fib_protocol_t fproto,
   mp->table_id = htonl (table_id);
   mp->af = fib_proto_to_api_address_family (fproto);
 
-  vl_msg_api_send_shmem (ctx->q, (u8 *) & mp);
+  vl_api_send_msg (ctx->rp, (u8 *) mp);
 
   return (WALK_CONTINUE);
 }
@@ -190,16 +187,14 @@ svs_send_details (fib_protocol_t fproto,
 static void
 vl_api_svs_dump_t_handler (vl_api_svs_dump_t * mp)
 {
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (q == 0)
-    {
-      return;
-    }
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
+    return;
 
   svs_dump_walk_ctx_t ctx = {
-    .q = q,
+    .rp = rp,
     .context = mp->context,
   };
 
index fb11734..383d742 100644 (file)
@@ -164,6 +164,7 @@ noop_handler (void *notused)
 {
 }
 
+void vl_msg_api_send_shmem (svm_queue_t * q, u8 * elem);
 int
 vl_client_connect (const char *name, int ctx_quota, int input_queue_size)
 {
index 67ead7d..662eaf9 100644 (file)
@@ -120,7 +120,6 @@ void vl_unmap_shmem (void);
 void vl_unmap_shmem_client (void);
 void vl_register_mapped_shmem_region (svm_region_t * rp);
 void vl_msg_api_send_shmem (svm_queue_t * q, u8 * elem);
-void vl_msg_api_send_shmem_nolock (svm_queue_t * q, u8 * elem);
 int vl_mem_api_can_send (svm_queue_t * q);
 void vl_set_memory_region_name (const char *name);
 void vl_set_memory_root_path (const char *root_path);
index 50bae5d..07c2cbc 100644 (file)
@@ -51,49 +51,17 @@ _(BOND_DETACH_SLAVE, bond_detach_slave)          \
 _(SW_INTERFACE_BOND_DUMP, sw_interface_bond_dump)\
 _(SW_INTERFACE_SLAVE_DUMP, sw_interface_slave_dump)
 
-static void
-bond_send_sw_interface_event_deleted (vpe_api_main_t * am,
-                                     unix_shared_memory_queue_t * q,
-                                     u32 sw_if_index)
-{
-  vl_api_sw_interface_event_t *mp;
-
-  mp = vl_msg_api_alloc (sizeof (*mp));
-  clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_EVENT);
-  mp->sw_if_index = ntohl (sw_if_index);
-
-  mp->admin_up_down = 0;
-  mp->link_up_down = 0;
-  mp->deleted = 1;
-  vl_msg_api_send_shmem (q, (u8 *) & mp);
-}
-
 static void
 vl_api_bond_delete_t_handler (vl_api_bond_delete_t * mp)
 {
   vlib_main_t *vm = vlib_get_main ();
   int rv;
-  vpe_api_main_t *vam = &vpe_api_main;
   vl_api_bond_delete_reply_t *rmp;
-  unix_shared_memory_queue_t *q;
   u32 sw_if_index = ntohl (mp->sw_if_index);
 
   rv = bond_delete_if (vm, sw_if_index);
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
-    return;
-
-  rmp = vl_msg_api_alloc (sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_BOND_DELETE_REPLY);
-  rmp->context = mp->context;
-  rmp->retval = ntohl (rv);
-
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
-
-  if (!rv)
-    bond_send_sw_interface_event_deleted (vam, q, sw_if_index);
+  REPLY_MACRO (VL_API_BOND_DELETE_REPLY);
 }
 
 static void
@@ -101,7 +69,6 @@ vl_api_bond_create_t_handler (vl_api_bond_create_t * mp)
 {
   vlib_main_t *vm = vlib_get_main ();
   vl_api_bond_create_reply_t *rmp;
-  unix_shared_memory_queue_t *q;
   bond_create_if_args_t _a, *ap = &_a;
 
   clib_memset (ap, 0, sizeof (*ap));
@@ -118,19 +85,14 @@ vl_api_bond_create_t_handler (vl_api_bond_create_t * mp)
   ap->lb = mp->lb;
   bond_create_if (vm, ap);
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
-    return;
+  int rv = ap->rv;
 
-  if (ap->rv != 0)
-    return;
-  rmp = vl_msg_api_alloc (sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_BOND_CREATE_REPLY);
-  rmp->context = mp->context;
-  rmp->retval = ntohl (ap->rv);
-  rmp->sw_if_index = ntohl (ap->sw_if_index);
-
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  /* *INDENT-OFF* */
+  REPLY_MACRO2(VL_API_BOND_CREATE_REPLY,
+  ({
+    rmp->sw_if_index = ntohl (ap->sw_if_index);
+  }));
+  /* *INDENT-ON* */
 }
 
 static void
@@ -138,8 +100,8 @@ vl_api_bond_enslave_t_handler (vl_api_bond_enslave_t * mp)
 {
   vlib_main_t *vm = vlib_get_main ();
   vl_api_bond_enslave_reply_t *rmp;
-  unix_shared_memory_queue_t *q;
   bond_enslave_args_t _a, *ap = &_a;
+  int rv = 0;
 
   clib_memset (ap, 0, sizeof (*ap));
 
@@ -150,16 +112,7 @@ vl_api_bond_enslave_t_handler (vl_api_bond_enslave_t * mp)
 
   bond_enslave (vm, ap);
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
-    return;
-
-  rmp = vl_msg_api_alloc (sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_BOND_ENSLAVE_REPLY);
-  rmp->context = mp->context;
-  rmp->retval = ntohl (ap->rv);
-
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  REPLY_MACRO (VL_API_BOND_ENSLAVE_REPLY);
 }
 
 static void
@@ -167,24 +120,15 @@ vl_api_bond_detach_slave_t_handler (vl_api_bond_detach_slave_t * mp)
 {
   vlib_main_t *vm = vlib_get_main ();
   vl_api_bond_detach_slave_reply_t *rmp;
-  unix_shared_memory_queue_t *q;
   bond_detach_slave_args_t _a, *ap = &_a;
+  int rv = 0;
 
   clib_memset (ap, 0, sizeof (*ap));
 
   ap->slave = ntohl (mp->sw_if_index);
   bond_detach_slave (vm, ap);
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
-    return;
-
-  rmp = vl_msg_api_alloc (sizeof (*rmp));
-  rmp->_vl_msg_id = ntohs (VL_API_BOND_DETACH_SLAVE_REPLY);
-  rmp->context = mp->context;
-  rmp->retval = htonl (ap->rv);
-
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  REPLY_MACRO (VL_API_BOND_DETACH_SLAVE_REPLY);
 }
 
 static void
index 1260afd..40ff22e 100644 (file)
@@ -136,31 +136,12 @@ vl_api_tap_create_v2_t_handler (vl_api_tap_create_v2_t * mp)
   vl_api_send_msg (reg, (u8 *) rmp);
 }
 
-static void
-tap_send_sw_interface_event_deleted (vpe_api_main_t * am,
-                                    vl_api_registration_t * reg,
-                                    u32 sw_if_index)
-{
-  vl_api_sw_interface_event_t *mp;
-
-  mp = vl_msg_api_alloc (sizeof (*mp));
-  clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_EVENT);
-  mp->sw_if_index = ntohl (sw_if_index);
-
-  mp->admin_up_down = 0;
-  mp->link_up_down = 0;
-  mp->deleted = 1;
-  vl_api_send_msg (reg, (u8 *) mp);
-}
-
 static void
 vl_api_tap_delete_v2_t_handler (vl_api_tap_delete_v2_t * mp)
 {
   vnet_main_t *vnm = vnet_get_main ();
   vlib_main_t *vm = vlib_get_main ();
   int rv;
-  vpe_api_main_t *vam = &vpe_api_main;
   vl_api_tap_delete_v2_reply_t *rmp;
   vl_api_registration_t *reg;
   u32 sw_if_index = ntohl (mp->sw_if_index);
@@ -179,10 +160,7 @@ vl_api_tap_delete_v2_t_handler (vl_api_tap_delete_v2_t * mp)
   vl_api_send_msg (reg, (u8 *) rmp);
 
   if (!rv)
-    {
-      vnet_clear_sw_interface_tag (vnm, sw_if_index);
-      tap_send_sw_interface_event_deleted (vam, reg, sw_if_index);
-    }
+    vnet_clear_sw_interface_tag (vnm, sw_if_index);
 }
 
 static void
index 8142cf3..4c765f3 100644 (file)
@@ -48,26 +48,6 @@ _(MODIFY_VHOST_USER_IF, modify_vhost_user_if)                           \
 _(DELETE_VHOST_USER_IF, delete_vhost_user_if)                           \
 _(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump)
 
-/*
- * WARNING: replicated pending api refactor completion
- */
-static void
-send_sw_interface_event_deleted (vpe_api_main_t * am,
-                                vl_api_registration_t * reg, u32 sw_if_index)
-{
-  vl_api_sw_interface_event_t *mp;
-
-  mp = vl_msg_api_alloc (sizeof (*mp));
-  clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_EVENT);
-  mp->sw_if_index = ntohl (sw_if_index);
-
-  mp->admin_up_down = 0;
-  mp->link_up_down = 0;
-  mp->deleted = 1;
-  vl_api_send_msg (reg, (u8 *) mp);
-}
-
 static void
 vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp)
 {
@@ -135,7 +115,6 @@ vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
 {
   int rv = 0;
   vl_api_delete_vhost_user_if_reply_t *rmp;
-  vpe_api_main_t *vam = &vpe_api_main;
   u32 sw_if_index = ntohl (mp->sw_if_index);
   vl_api_registration_t *reg;
 
@@ -152,7 +131,6 @@ vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp)
        return;
 
       vnet_clear_sw_interface_tag (vnm, sw_if_index);
-      send_sw_interface_event_deleted (vam, reg, sw_if_index);
     }
 }
 
index 238c6ad..ff123ae 100644 (file)
@@ -85,24 +85,6 @@ vl_api_virtio_pci_create_t_handler (vl_api_virtio_pci_create_t * mp)
   vl_api_send_msg (reg, (u8 *) rmp);
 }
 
-static void
-virtio_pci_send_sw_interface_event_deleted (vpe_api_main_t * am,
-                                           vl_api_registration_t * reg,
-                                           u32 sw_if_index)
-{
-  vl_api_sw_interface_event_t *mp;
-
-  mp = vl_msg_api_alloc (sizeof (*mp));
-  clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_EVENT);
-  mp->sw_if_index = htonl (sw_if_index);
-
-  mp->admin_up_down = 0;
-  mp->link_up_down = 0;
-  mp->deleted = 1;
-  vl_api_send_msg (reg, (u8 *) mp);
-}
-
 static void
 vl_api_virtio_pci_delete_t_handler (vl_api_virtio_pci_delete_t * mp)
 {
@@ -112,10 +94,8 @@ vl_api_virtio_pci_delete_t_handler (vl_api_virtio_pci_delete_t * mp)
   int rv = 0;
   vnet_hw_interface_t *hw;
   virtio_if_t *vif;
-  vpe_api_main_t *vam = &vpe_api_main;
   vl_api_virtio_pci_delete_reply_t *rmp;
   vl_api_registration_t *reg;
-  u32 sw_if_index = ntohl (mp->sw_if_index);
 
   hw = vnet_get_sup_hw_interface (vnm, htonl (mp->sw_if_index));
   if (hw == NULL || virtio_device_class.index != hw->dev_class_index)
@@ -139,11 +119,6 @@ reply:
   rmp->retval = htonl (rv);
 
   vl_api_send_msg (reg, (u8 *) rmp);
-
-  if (!rv)
-    {
-      virtio_pci_send_sw_interface_event_deleted (vam, reg, sw_if_index);
-    }
 }
 
 static void
index bd5588e..f49af94 100644 (file)
@@ -694,38 +694,36 @@ vl_api_sw_interface_clear_stats_t_handler (vl_api_sw_interface_clear_stats_t *
   REPLY_MACRO (VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
 }
 
-#define API_LINK_STATE_EVENT 1
-#define API_ADMIN_UP_DOWN_EVENT 2
-
-static int
-event_data_cmp (void *a1, void *a2)
+/*
+ * Events used for sw_interface_events
+ */
+enum api_events
 {
-  uword *e1 = a1;
-  uword *e2 = a2;
-
-  return (word) e1[0] - (word) e2[0];
-}
+  API_LINK_STATE_UP_EVENT = 1 << 1,
+  API_LINK_STATE_DOWN_EVENT = 1 << 2,
+  API_ADMIN_UP_EVENT = 1 << 3,
+  API_ADMIN_DOWN_EVENT = 1 << 4,
+  API_SW_INTERFACE_ADD_EVENT = 1 << 5,
+  API_SW_INTERFACE_DEL_EVENT = 1 << 6,
+};
 
 static void
 send_sw_interface_event (vpe_api_main_t * am,
                         vpe_client_registration_t * reg,
                         vl_api_registration_t * vl_reg,
-                        vnet_sw_interface_t * swif)
+                        u32 sw_if_index, enum api_events events)
 {
   vl_api_sw_interface_event_t *mp;
-  vnet_main_t *vnm = am->vnet_main;
 
-  vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm,
-                                                      swif->sw_if_index);
   mp = vl_msg_api_alloc (sizeof (*mp));
   clib_memset (mp, 0, sizeof (*mp));
   mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_EVENT);
-  mp->sw_if_index = ntohl (swif->sw_if_index);
+  mp->sw_if_index = ntohl (sw_if_index);
   mp->client_index = reg->client_index;
   mp->pid = reg->client_pid;
-
-  mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
-  mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0;
+  mp->admin_up_down = events & API_ADMIN_UP_EVENT ? 1 : 0;
+  mp->link_up_down = events & API_LINK_STATE_UP_EVENT ? 1 : 0;
+  mp->deleted = events & API_SW_INTERFACE_DEL_EVENT ? 1 : 0;
   vl_api_send_msg (vl_reg, (u8 *) mp);
 }
 
@@ -734,13 +732,13 @@ link_state_process (vlib_main_t * vm,
                    vlib_node_runtime_t * rt, vlib_frame_t * f)
 {
   vpe_api_main_t *vam = &vpe_api_main;
-  vnet_main_t *vnm = vam->vnet_main;
-  vnet_sw_interface_t *swif;
-  uword *event_data = 0;
+  uword *event_by_sw_if_index = 0;
   vpe_client_registration_t *reg;
   int i;
-  u32 prev_sw_if_index;
   vl_api_registration_t *vl_reg;
+  uword event_type;
+  uword *event_data = 0;
+  u32 sw_if_index;
 
   vam->link_state_process_up = 1;
 
@@ -748,42 +746,33 @@ link_state_process (vlib_main_t * vm,
     {
       vlib_process_wait_for_event (vm);
 
-      /* Unified list of changed link or admin state sw_if_indices */
-      vlib_process_get_events_with_type
-       (vm, &event_data, API_LINK_STATE_EVENT);
-      vlib_process_get_events_with_type
-       (vm, &event_data, API_ADMIN_UP_DOWN_EVENT);
-
-      /* Sort, so we can eliminate duplicates */
-      vec_sort_with_function (event_data, event_data_cmp);
-
-      prev_sw_if_index = ~0;
+      /* Batch up events */
+      while ((event_type = vlib_process_get_events (vm, &event_data)) != ~0)
+       {
+         for (i = 0; i < vec_len (event_data); i++)
+           {
+             sw_if_index = event_data[i];
+             vec_validate_init_empty (event_by_sw_if_index, sw_if_index, 0);
+             event_by_sw_if_index[sw_if_index] |= event_type;
+           }
+         vec_reset_length (event_data);
+       }
 
-      for (i = 0; i < vec_len (event_data); i++)
+      for (i = 0; i < vec_len (event_by_sw_if_index); i++)
        {
-         /* Only one message per swif */
-         if (prev_sw_if_index == event_data[i])
+         if (event_by_sw_if_index[i] == 0)
            continue;
-         prev_sw_if_index = event_data[i];
 
           /* *INDENT-OFF* */
           pool_foreach(reg, vam->interface_events_registrations,
           ({
             vl_reg = vl_api_client_index_to_registration (reg->client_index);
             if (vl_reg)
-              {
-                /* sw_interface may be deleted already */
-                if (!pool_is_free_index (vnm->interface_main.sw_interfaces,
-                                         event_data[i]))
-                  {
-                    swif = vnet_get_sw_interface (vnm, event_data[i]);
-                    send_sw_interface_event (vam, reg, vl_reg, swif);
-                  }
-              }
+             send_sw_interface_event (vam, reg, vl_reg, i, event_by_sw_if_index[i]);
           }));
           /* *INDENT-ON* */
        }
-      vec_reset_length (event_data);
+      vec_reset_length (event_by_sw_if_index);
     }
 
   return 0;
@@ -793,6 +782,9 @@ static clib_error_t *link_up_down_function (vnet_main_t * vm, u32 hw_if_index,
                                            u32 flags);
 static clib_error_t *admin_up_down_function (vnet_main_t * vm,
                                             u32 hw_if_index, u32 flags);
+static clib_error_t *sw_interface_add_del_function (vnet_main_t * vm,
+                                                   u32 sw_if_index,
+                                                   u32 flags);
 
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (link_state_process_node,static) = {
@@ -804,6 +796,7 @@ VLIB_REGISTER_NODE (link_state_process_node,static) = {
 
 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (admin_up_down_function);
 VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (link_up_down_function);
+VNET_SW_INTERFACE_ADD_DEL_FUNCTION (sw_interface_add_del_function);
 
 static clib_error_t *
 link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
@@ -812,9 +805,13 @@ link_up_down_function (vnet_main_t * vm, u32 hw_if_index, u32 flags)
   vnet_hw_interface_t *hi = vnet_get_hw_interface (vm, hw_if_index);
 
   if (vam->link_state_process_up)
-    vlib_process_signal_event (vam->vlib_main,
-                              link_state_process_node.index,
-                              API_LINK_STATE_EVENT, hi->sw_if_index);
+    {
+      enum api_events event =
+       flags ? API_LINK_STATE_UP_EVENT : API_LINK_STATE_DOWN_EVENT;
+      vlib_process_signal_event (vam->vlib_main,
+                                link_state_process_node.index, event,
+                                hi->sw_if_index);
+    }
   return 0;
 }
 
@@ -829,9 +826,29 @@ admin_up_down_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
    * routine.
    */
   if (vam->link_state_process_up)
-    vlib_process_signal_event (vam->vlib_main,
-                              link_state_process_node.index,
-                              API_ADMIN_UP_DOWN_EVENT, sw_if_index);
+    {
+      enum api_events event =
+       flags ? API_ADMIN_UP_EVENT : API_ADMIN_DOWN_EVENT;
+      vlib_process_signal_event (vam->vlib_main,
+                                link_state_process_node.index, event,
+                                sw_if_index);
+    }
+  return 0;
+}
+
+static clib_error_t *
+sw_interface_add_del_function (vnet_main_t * vm, u32 sw_if_index, u32 flags)
+{
+  vpe_api_main_t *vam = &vpe_api_main;
+
+  if (vam->link_state_process_up)
+    {
+      enum api_events event =
+       flags ? API_SW_INTERFACE_ADD_EVENT : API_SW_INTERFACE_DEL_EVENT;
+      vlib_process_signal_event (vam->vlib_main,
+                                link_state_process_node.index, event,
+                                sw_if_index);
+    }
   return 0;
 }
 
index 9ecdfc8..ce3456d 100644 (file)
@@ -3343,11 +3343,10 @@ vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp)
 void
 vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
 {
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *rp;
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-
-  if (q == 0)
+  rp = vl_api_client_index_to_registration (mp->client_index);
+  if (rp == 0)
     return;
 
   vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp));
@@ -3371,7 +3370,7 @@ vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
   rmp->max_reassemblies = clib_host_to_net_u32 (rmp->max_reassemblies);
   rmp->expire_walk_interval_ms =
     clib_host_to_net_u32 (rmp->expire_walk_interval_ms);
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  vl_api_send_msg (rp, (u8 *) rmp);
 }
 
 void
index 004d2f6..22a4dd8 100644 (file)
@@ -316,6 +316,7 @@ class VppTestCase(unittest.TestCase):
                            "main-core", str(cpu_core_number), "}", "statseg",
                            "{", "socket-name", cls.stats_sock, "}", "plugins",
                            "{", "plugin", "dpdk_plugin.so", "{", "disable",
+                           "}", "plugin", "rdma_plugin.so", "{", "disable",
                            "}", "plugin", "unittest_plugin.so", "{", "enable",
                            "}"] + cls.extra_vpp_plugin_config + ["}", ]
         if cls.extra_vpp_punt_config is not None:
index 15eb070..c657da7 100644 (file)
@@ -92,8 +92,8 @@ class TesVhostInterface(VppTestCase):
         vhost_if.add_vpp_config()
         self.sleep(0.1)
         events = self.vapi.collect_events()
-        # creating interface doesn't currently create events
-        self.assert_equal(len(events), 0, "number of events")
+        # creating interface does now create events
+        self.assert_equal(len(events), 1, "number of events")
 
         vhost_if.admin_up()
         vhost_if.assert_interface_state(1, 0, expect_event=True)