interface: shmemioerror while getting name_filter arg
[vpp.git] / src / vnet / interface_api.c
index 687f599..3b0c515 100644 (file)
@@ -68,6 +68,7 @@ _(SW_INTERFACE_GET_TABLE, sw_interface_get_table)               \
 _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered)     \
 _(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats)           \
 _(SW_INTERFACE_TAG_ADD_DEL, sw_interface_tag_add_del)           \
+_(SW_INTERFACE_ADD_DEL_MAC_ADDRESS, sw_interface_add_del_mac_address) \
 _(SW_INTERFACE_SET_MAC_ADDRESS, sw_interface_set_mac_address)   \
 _(SW_INTERFACE_GET_MAC_ADDRESS, sw_interface_get_mac_address)   \
 _(CREATE_VLAN_SUBIF, create_vlan_subif)                         \
@@ -201,6 +202,8 @@ send_sw_interface_details (vpe_api_main_t * am,
 {
   vnet_hw_interface_t *hi =
     vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
+  vnet_device_class_t *dev_class =
+    vnet_get_device_class (am->vnet_main, hi->dev_class_index);
 
   vl_api_sw_interface_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
   clib_memset (mp, 0, sizeof (*mp));
@@ -244,6 +247,10 @@ send_sw_interface_details (vpe_api_main_t * am,
   strncpy ((char *) mp->interface_name,
           (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
 
+  if (dev_class && dev_class->name)
+    strncpy ((char *) mp->interface_dev_type, (char *) dev_class->name,
+            ARRAY_LEN (mp->interface_dev_type) - 1);
+
   /* Send the L2 address for ethernet physical intfcs */
   if (swif->sup_sw_if_index == swif->sw_if_index
       && hi->hw_class_index == ethernet_hw_interface_class.index)
@@ -351,9 +358,8 @@ vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
 
   if (mp->name_filter_valid)
     {
-      filter =
-       format (0, ".*%s", vl_api_string_len (&mp->name_filter),
-               vl_api_from_api_string (&mp->name_filter), 0);
+      filter = vl_api_from_api_to_vec (&mp->name_filter);
+      vec_add1 (filter, 0);    /* Ensure it's a C string for strcasecmp() */
     }
 
   char *strcasestr (char *, char *);   /* lnx hdr file botch */
@@ -899,6 +905,34 @@ out:
   REPLY_MACRO (VL_API_SW_INTERFACE_TAG_ADD_DEL_REPLY);
 }
 
+static void vl_api_sw_interface_add_del_mac_address_t_handler
+  (vl_api_sw_interface_add_del_mac_address_t * mp)
+{
+  vl_api_sw_interface_add_del_mac_address_reply_t *rmp;
+  vnet_main_t *vnm = vnet_get_main ();
+  u32 sw_if_index = ntohl (mp->sw_if_index);
+  vnet_hw_interface_t *hi;
+  clib_error_t *error;
+  int rv = 0;
+
+  VALIDATE_SW_IF_INDEX (mp);
+
+  /* for subifs, the MAC should be changed on the actual hw if */
+  hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
+  error = vnet_hw_interface_add_del_mac_address (vnm, hi->hw_if_index,
+                                                mp->addr, mp->is_add);
+  if (error)
+    {
+      rv = VNET_API_ERROR_UNIMPLEMENTED;
+      clib_error_report (error);
+      goto out;
+    }
+
+  BAD_SW_IF_INDEX_LABEL;
+out:
+  REPLY_MACRO (VL_API_SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY);
+}
+
 static void vl_api_sw_interface_set_mac_address_t_handler
   (vl_api_sw_interface_set_mac_address_t * mp)
 {
@@ -1208,74 +1242,30 @@ vl_api_create_subif_t_handler (vl_api_create_subif_t * mp)
 {
   vl_api_create_subif_reply_t *rmp;
   vnet_main_t *vnm = vnet_get_main ();
-  u32 sw_if_index = ~0;
-  int rv = 0;
-  u32 sub_id;
-  vnet_sw_interface_t *si;
+  u32 sub_sw_if_index = ~0;
   vnet_hw_interface_t *hi;
-  vnet_sw_interface_t template;
-  uword *p;
-  vnet_interface_main_t *im = &vnm->interface_main;
-  u64 sup_and_sub_key;
-  clib_error_t *error;
+  int rv = 0;
 
   VALIDATE_SW_IF_INDEX (mp);
 
-  si = vnet_get_sup_sw_interface (vnm, ntohl (mp->sw_if_index));
   hi = vnet_get_sup_hw_interface (vnm, ntohl (mp->sw_if_index));
 
   if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
-    {
-      rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
-      goto out;
-    }
-
-  sw_if_index = si->sw_if_index;
-  sub_id = ntohl (mp->sub_id);
-
-  sup_and_sub_key = ((u64) (sw_if_index) << 32) | (u64) sub_id;
-
-  p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
-  if (p)
-    {
-      if (CLIB_DEBUG > 0)
-       clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
-                     sw_if_index, sub_id);
-      rv = VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
-      goto out;
-    }
-
-  clib_memset (&template, 0, sizeof (template));
-  template.type = VNET_SW_INTERFACE_TYPE_SUB;
-  template.flood_class = VNET_FLOOD_CLASS_NORMAL;
-  template.sup_sw_if_index = sw_if_index;
-  template.sub.id = sub_id;
-  template.sub.eth.raw_flags = ntohl (mp->sub_if_flags);
-  template.sub.eth.outer_vlan_id = ntohs (mp->outer_vlan_id);
-  template.sub.eth.inner_vlan_id = ntohs (mp->inner_vlan_id);
-
-  error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
-  if (error)
-    {
-      clib_error_report (error);
-      rv = VNET_API_ERROR_SUBIF_CREATE_FAILED;
-      goto out;
-    }
-
-  u64 *kp = clib_mem_alloc (sizeof (*kp));
-  *kp = sup_and_sub_key;
-
-  hash_set (hi->sub_interface_sw_if_index_by_id, sub_id, sw_if_index);
-  hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
+    rv = VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;
+  else
+    rv = vnet_create_sub_interface (ntohl (mp->sw_if_index),
+                                   ntohl (mp->sub_id),
+                                   ntohl (mp->sub_if_flags),
+                                   ntohs (mp->inner_vlan_id),
+                                   ntohs (mp->outer_vlan_id),
+                                   &sub_sw_if_index);
 
   BAD_SW_IF_INDEX_LABEL;
 
-out:
-
   /* *INDENT-OFF* */
   REPLY_MACRO2(VL_API_CREATE_SUBIF_REPLY,
   ({
-    rmp->sw_if_index = ntohl(sw_if_index);
+    rmp->sw_if_index = ntohl(sub_sw_if_index);
   }));
   /* *INDENT-ON* */
 }