summaryrefslogtreecommitdiffstats
path: root/vnet
diff options
context:
space:
mode:
authorPierre Pfister <ppfister@cisco.com>2016-02-19 13:52:44 +0000
committerGerrit Code Review <gerrit@fd.io>2016-02-19 15:58:07 +0000
commitef65cb0696b3ee42834a72a35c1eb08da75eed99 (patch)
treef949c0aea6b0d3ffd9059287c94bb9e20522338a /vnet
parentb44e9bc90b634b07d5f93a731a95028adc73bcbc (diff)
Add custom mac address option to vhost interfaces.
Generating a new MAC address everytime vpp reboots can quickly become cumbersome (e.g. in test scenarios). This commit allows vhost mac addresses to be configured manually. Change-Id: Ic6d16a2d14cdf8e49dc29041bbafde39d9fc8370 Signed-off-by: Pierre Pfister <ppfister@cisco.com>
Diffstat (limited to 'vnet')
-rw-r--r--vnet/vnet/devices/dpdk/dpdk.h3
-rw-r--r--vnet/vnet/devices/dpdk/vhost_user.c21
-rw-r--r--vnet/vnet/devices/virtio/vhost-user.c17
-rw-r--r--vnet/vnet/devices/virtio/vhost-user.h2
4 files changed, 30 insertions, 13 deletions
diff --git a/vnet/vnet/devices/dpdk/dpdk.h b/vnet/vnet/devices/dpdk/dpdk.h
index 2a9d825e04d..3e287a9a166 100644
--- a/vnet/vnet/devices/dpdk/dpdk.h
+++ b/vnet/vnet/devices/dpdk/dpdk.h
@@ -511,7 +511,8 @@ int dpdk_vhost_user_create_if (vnet_main_t * vnm, vlib_main_t * vm,
u8 is_server,
u32 * sw_if_index,
u64 feature_mask,
- u8 renumber, u32 custom_dev_instance);
+ u8 renumber, u32 custom_dev_instance,
+ u8 *hwaddr);
int dpdk_vhost_user_modify_if (vnet_main_t * vnm, vlib_main_t * vm,
const char * sock_filename,
u8 is_server,
diff --git a/vnet/vnet/devices/dpdk/vhost_user.c b/vnet/vnet/devices/dpdk/vhost_user.c
index 0965456e0f9..a9b2082b4d4 100644
--- a/vnet/vnet/devices/dpdk/vhost_user.c
+++ b/vnet/vnet/devices/dpdk/vhost_user.c
@@ -187,7 +187,7 @@ static inline void * map_guest_mem(dpdk_device_t * xd, u64 addr)
}
static clib_error_t *
-dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id)
+dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id, u8 *hwaddr)
{
dpdk_main_t * dm = &dpdk_main;
vlib_main_t * vm = vlib_get_main();
@@ -332,6 +332,9 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id)
/*
* Generate random MAC address for the interface
*/
+ if (hwaddr) {
+ memcpy(addr, hwaddr, sizeof(addr));
+ } else {
f64 now = vlib_time_now(vm);
u32 rnd;
rnd = (u32) (now * 1e6);
@@ -340,6 +343,7 @@ dpdk_create_vhost_user_if_internal (u32 * hw_if_index, u32 if_id)
memcpy (addr+2, &rnd, sizeof(rnd));
addr[0] = 2;
addr[1] = 0xfe;
+ }
error = ethernet_register_interface
(dm->vnet_main,
@@ -1275,7 +1279,8 @@ int dpdk_vhost_user_create_if(vnet_main_t * vnm, vlib_main_t * vm,
u8 is_server,
u32 * sw_if_index,
u64 feature_mask,
- u8 renumber, u32 custom_dev_instance)
+ u8 renumber, u32 custom_dev_instance,
+ u8 *hwaddr)
{
dpdk_main_t * dm = &dpdk_main;
dpdk_device_t *xd;
@@ -1286,7 +1291,7 @@ int dpdk_vhost_user_create_if(vnet_main_t * vnm, vlib_main_t * vm,
// using virtio vhost user?
if (dm->use_virtio_vhost) {
return vhost_user_create_if(vnm, vm, sock_filename, is_server,
- sw_if_index, feature_mask, renumber, custom_dev_instance);
+ sw_if_index, feature_mask, renumber, custom_dev_instance, hwaddr);
}
if (is_server) {
@@ -1300,9 +1305,9 @@ int dpdk_vhost_user_create_if(vnet_main_t * vnm, vlib_main_t * vm,
if (custom_dev_instance >= dm->next_vu_if_id)
dm->next_vu_if_id = custom_dev_instance + 1;
- dpdk_create_vhost_user_if_internal(&hw_if_idx, custom_dev_instance);
+ dpdk_create_vhost_user_if_internal(&hw_if_idx, custom_dev_instance, hwaddr);
} else
- dpdk_create_vhost_user_if_internal(&hw_if_idx, (u32)~0);
+ dpdk_create_vhost_user_if_internal(&hw_if_idx, (u32)~0, hwaddr);
DBG_SOCK("dpdk vhost-user interface created hw_if_index %d", hw_if_idx);
xd = dpdk_vhost_user_device_from_hw_if_index(hw_if_idx);
@@ -1548,6 +1553,8 @@ dpdk_vhost_user_connect_command_fn (vlib_main_t * vm,
u64 feature_mask = (u64)~0;
u8 renumber = 0;
u32 custom_dev_instance = ~0;
+ u8 hwaddr[6];
+ u8 *hw = NULL;
if (dm->use_virtio_vhost) {
return vhost_user_connect_command_fn(vm, input, cmd);
@@ -1564,6 +1571,8 @@ dpdk_vhost_user_connect_command_fn (vlib_main_t * vm,
is_server = 1;
else if (unformat (line_input, "feature-mask 0x%llx", &feature_mask))
;
+ else if (unformat (line_input, "hwaddr %U", unformat_ethernet_address, hwaddr))
+ hw = hwaddr;
else if (unformat (line_input, "renumber %d", &custom_dev_instance)) {
renumber = 1;
}
@@ -1579,7 +1588,7 @@ dpdk_vhost_user_connect_command_fn (vlib_main_t * vm,
dpdk_vhost_user_create_if(vnm, vm, (char *)sock_filename,
is_server, &sw_if_index, feature_mask,
- renumber, custom_dev_instance);
+ renumber, custom_dev_instance, hw);
vec_free(sock_filename);
return 0;
diff --git a/vnet/vnet/devices/virtio/vhost-user.c b/vnet/vnet/devices/virtio/vhost-user.c
index 180393d4f7f..df09db87e57 100644
--- a/vnet/vnet/devices/virtio/vhost-user.c
+++ b/vnet/vnet/devices/virtio/vhost-user.c
@@ -1429,14 +1429,16 @@ static vhost_user_intf_t *vhost_user_vui_new()
// create ethernet interface for vhost user intf
static void vhost_user_create_ethernet(vnet_main_t * vnm, vlib_main_t * vm,
- vhost_user_intf_t *vui)
+ vhost_user_intf_t *vui, u8 *hwaddress)
{
vhost_user_main_t * vum = &vhost_user_main;
u8 hwaddr[6];
clib_error_t * error;
/* create hw and sw interface */
- {
+ if (hwaddress) {
+ memcpy(hwaddr, hwaddress, 6);
+ } else {
f64 now = vlib_time_now(vm);
u32 rnd;
rnd = (u32) (now * 1e6);
@@ -1529,7 +1531,8 @@ int vhost_user_create_if(vnet_main_t * vnm, vlib_main_t * vm,
u8 is_server,
u32 * sw_if_index,
u64 feature_mask,
- u8 renumber, u32 custom_dev_instance)
+ u8 renumber, u32 custom_dev_instance,
+ u8 *hwaddr)
{
vhost_user_intf_t * vui = NULL;
dpdk_main_t * dm = &dpdk_main;
@@ -1553,7 +1556,7 @@ int vhost_user_create_if(vnet_main_t * vnm, vlib_main_t * vm,
vui = vhost_user_vui_new ();
ASSERT(vui != NULL);
- vhost_user_create_ethernet (vnm, vm, vui);
+ vhost_user_create_ethernet (vnm, vm, vui, hwaddr);
vhost_user_vui_init (vnm, vui, sockfd, sock_filename, is_server,
feature_mask, &sw_if_idx);
@@ -1626,6 +1629,8 @@ vhost_user_connect_command_fn (vlib_main_t * vm,
u64 feature_mask = (u64)~0;
u8 renumber = 0;
u32 custom_dev_instance = ~0;
+ u8 hwaddr[6];
+ u8 *hw = NULL;
/* Get a line of input. */
if (! unformat_user (input, unformat_line_input, line_input))
@@ -1638,6 +1643,8 @@ vhost_user_connect_command_fn (vlib_main_t * vm,
is_server = 1;
else if (unformat (line_input, "feature-mask 0x%llx", &feature_mask))
;
+ else if (unformat (line_input, "hwaddr %U", unformat_ethernet_address, hwaddr))
+ hw = hwaddr;
else if (unformat (line_input, "renumber %d", &custom_dev_instance)) {
renumber = 1;
}
@@ -1651,7 +1658,7 @@ vhost_user_connect_command_fn (vlib_main_t * vm,
vhost_user_create_if(vnm, vm, (char *)sock_filename,
is_server, &sw_if_index, feature_mask,
- renumber, custom_dev_instance);
+ renumber, custom_dev_instance, hw);
vec_free(sock_filename);
diff --git a/vnet/vnet/devices/virtio/vhost-user.h b/vnet/vnet/devices/virtio/vhost-user.h
index 1fbc0f0bdd7..4eb4b81d753 100644
--- a/vnet/vnet/devices/virtio/vhost-user.h
+++ b/vnet/vnet/devices/virtio/vhost-user.h
@@ -50,7 +50,7 @@ typedef enum {
int vhost_user_create_if(vnet_main_t * vnm, vlib_main_t * vm,
const char * sock_filename, u8 is_server,
u32 * sw_if_index, u64 feature_mask,
- u8 renumber, u32 custom_dev_instance);
+ u8 renumber, u32 custom_dev_instance, u8 *hwaddr);
int vhost_user_modify_if(vnet_main_t * vnm, vlib_main_t * vm,
const char * sock_filename, u8 is_server,
u32 sw_if_index, u64 feature_mask,