Add an API call to set interface MAC addresses.
[vpp.git] / src / vnet / interface_api.c
index 44798c8..ab0b255 100644 (file)
@@ -46,6 +46,7 @@
 #undef vl_printfun
 
 #include <vlibapi/api_helper_macros.h>
+vpe_api_main_t vpe_api_main;
 
 #define foreach_vpe_api_msg                                     \
 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags)               \
@@ -57,7 +58,8 @@ _(SW_INTERFACE_SET_TABLE, sw_interface_set_table)               \
 _(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_TAG_ADD_DEL, sw_interface_tag_add_del)           \
+_(SW_INTERFACE_SET_MAC_ADDRESS, sw_interface_set_mac_address)
 
 static void
 vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp)
@@ -433,6 +435,7 @@ static void vl_api_sw_interface_set_unnumbered_t_handler
   vnet_main_t *vnm = vnet_get_main ();
   u32 sw_if_index = ntohl (mp->sw_if_index);
   u32 unnumbered_sw_if_index = ntohl (mp->unnumbered_sw_if_index);
+  u32 was_unnum;
 
   /*
    * The API message field names are backwards from
@@ -454,6 +457,7 @@ static void vl_api_sw_interface_set_unnumbered_t_handler
 
   vnet_sw_interface_t *si =
     vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
+  was_unnum = (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED);
 
   if (mp->is_add)
     {
@@ -480,8 +484,12 @@ static void vl_api_sw_interface_set_unnumbered_t_handler
       ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
        [unnumbered_sw_if_index] = ~0;
     }
-  ip4_sw_interface_enable_disable (unnumbered_sw_if_index, mp->is_add);
-  ip6_sw_interface_enable_disable (unnumbered_sw_if_index, mp->is_add);
+
+  if (was_unnum != (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
+    {
+      ip4_sw_interface_enable_disable (unnumbered_sw_if_index, mp->is_add);
+      ip6_sw_interface_enable_disable (unnumbered_sw_if_index, mp->is_add);
+    }
 
 done:
   REPLY_MACRO (VL_API_SW_INTERFACE_SET_UNNUMBERED_REPLY);
@@ -719,6 +727,38 @@ out:
   REPLY_MACRO (VL_API_SW_INTERFACE_TAG_ADD_DEL_REPLY);
 }
 
+static void vl_api_sw_interface_set_mac_address_t_handler
+  (vl_api_sw_interface_set_mac_address_t * mp)
+{
+  vl_api_sw_interface_set_mac_address_reply_t *rmp;
+  vnet_main_t *vnm = vnet_get_main ();
+  u32 sw_if_index = ntohl (mp->sw_if_index);
+  u64 mac;
+  clib_error_t *error;
+  int rv = 0;
+
+  VALIDATE_SW_IF_INDEX (mp);
+
+  mac = ((u64) mp->mac_address[0] << (8 * 0)
+        | (u64) mp->mac_address[1] << (8 * 1)
+        | (u64) mp->mac_address[2] << (8 * 2)
+        | (u64) mp->mac_address[3] << (8 * 3)
+        | (u64) mp->mac_address[4] << (8 * 4)
+        | (u64) mp->mac_address[5] << (8 * 5));
+
+  error = vnet_hw_interface_change_mac_address (vnm, sw_if_index, mac);
+  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_SET_MAC_ADDRESS_REPLY);
+}
+
 /*
  * vpe_api_hookup
  * Add vpe's API message handlers to the table.