Fix set interface mac address API to be endian neutral

Store and pass MAC address as 6 byte u8 array instead of u64 to
make MAC address handling in set interface MAC endian neutral.
The previous API handler only works for little endian.

Change-Id: Ie4ec33a840bc5122ab1f17e25977e58f3466253b
Signed-off-by: John Lo <loj@cisco.com>
This commit is contained in:
John Lo
2017-10-31 14:31:10 -04:00
committed by Dave Barach
parent ca3b6f1b41
commit 62fcc0ac61
4 changed files with 10 additions and 16 deletions
+5 -4
View File
@@ -1334,7 +1334,8 @@ vnet_rename_interface (vnet_main_t * vnm, u32 hw_if_index, char *new_name)
static clib_error_t *
vnet_hw_interface_change_mac_address_helper (vnet_main_t * vnm,
u32 hw_if_index, u64 mac_address)
u32 hw_if_index,
u8 * mac_address)
{
clib_error_t *error = 0;
vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
@@ -1346,7 +1347,7 @@ vnet_hw_interface_change_mac_address_helper (vnet_main_t * vnm,
if (dev_class->mac_addr_change_function)
{
error =
dev_class->mac_addr_change_function (hi, (char *) &mac_address);
dev_class->mac_addr_change_function (hi, (char *) mac_address);
}
if (!error)
{
@@ -1355,7 +1356,7 @@ vnet_hw_interface_change_mac_address_helper (vnet_main_t * vnm,
hw_class = vnet_get_hw_interface_class (vnm, hi->hw_class_index);
if (NULL != hw_class->mac_addr_change_function)
hw_class->mac_addr_change_function (hi, (char *) &mac_address);
hw_class->mac_addr_change_function (hi, (char *) mac_address);
}
else
{
@@ -1376,7 +1377,7 @@ vnet_hw_interface_change_mac_address_helper (vnet_main_t * vnm,
clib_error_t *
vnet_hw_interface_change_mac_address (vnet_main_t * vnm, u32 hw_if_index,
u64 mac_address)
u8 * mac_address)
{
return vnet_hw_interface_change_mac_address_helper
(vnm, hw_if_index, mac_address);
+2 -9
View File
@@ -881,21 +881,14 @@ static void vl_api_sw_interface_set_mac_address_t_handler
vnet_main_t *vnm = vnet_get_main ();
u32 sw_if_index = ntohl (mp->sw_if_index);
vnet_sw_interface_t *si;
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));
si = vnet_get_sw_interface (vnm, sw_if_index);
error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index,
mp->mac_address);
if (error)
{
rv = VNET_API_ERROR_UNIMPLEMENTED;
+2 -2
View File
@@ -1201,7 +1201,7 @@ set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
vnet_sw_interface_t *si = NULL;
clib_error_t *error = 0;
u32 sw_if_index = ~0;
u64 mac = 0;
u8 mac[6] = { 0 };
if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
{
@@ -1209,7 +1209,7 @@ set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
format_unformat_error, input);
goto done;
}
if (!unformat_user (input, unformat_ethernet_address, &mac))
if (!unformat_user (input, unformat_ethernet_address, mac))
{
error = clib_error_return (0, "expected mac address `%U'",
format_unformat_error, input);
+1 -1
View File
@@ -274,7 +274,7 @@ clib_error_t *vnet_rename_interface (vnet_main_t * vnm, u32 hw_if_index,
/* Change interface mac address*/
clib_error_t *vnet_hw_interface_change_mac_address (vnet_main_t * vnm,
u32 hw_if_index,
u64 mac_address);
u8 * mac_address);
/* Change rx-mode */
clib_error_t *set_hw_interface_change_rx_mode (vnet_main_t * vnm,