From 90d8e2c4c3bc3a12dab88320040c1718a1aafcfd Mon Sep 17 00:00:00 2001 From: Mohsin KAZMI Date: Mon, 18 Jul 2016 16:57:40 +0200 Subject: Tap: Fix hardware address assignment [VPP-200]: Previously, VPP set the same hardware address to tap interface as of Linux side tap interface, if neither hardware address nor 'random' keyword were given explicitly on VPP command line during tap creation or modification, which was default case. This patch makes sure to set the different hardware addresses randomly as default case. While one can set unique hardware address or similar to one at Linux side using VPP tap command line. Change-Id: Ie0a82f3706834e87426d66c6e869ec4edfefe932 Signed-off-by: Mohsin KAZMI --- vnet/vnet/unix/tapcli.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) (limited to 'vnet') diff --git a/vnet/vnet/unix/tapcli.c b/vnet/vnet/unix/tapcli.c index bb280db9140..c1548fd1a29 100644 --- a/vnet/vnet/unix/tapcli.c +++ b/vnet/vnet/unix/tapcli.c @@ -756,24 +756,28 @@ int vnet_tap_connect (vlib_main_t * vm, u8 * intfc_name, u8 *hwaddr_arg, goto error; } - if (ioctl (dev_tap_fd, SIOCGIFHWADDR, &ifr) < 0) - { - rv = VNET_API_ERROR_SYSCALL_ERROR_1; - goto error; - } - ti = tapcli_get_new_tapif(); ti->per_interface_next_index = ~0; if (hwaddr_arg != 0) clib_memcpy(hwaddr, hwaddr_arg, 6); + else + { + f64 now = vlib_time_now(vm); + u32 rnd; + rnd = (u32) (now * 1e6); + rnd = random_u32 (&rnd); + + memcpy (hwaddr+2, &rnd, sizeof(rnd)); + hwaddr[0] = 2; + hwaddr[1] = 0xfe; + } error = ethernet_register_interface (tm->vnet_main, tapcli_dev_class.index, ti - tm->tapcli_interfaces /* device instance */, - hwaddr_arg != 0 ? hwaddr : - (u8 *) ifr.ifr_hwaddr.sa_data /* ethernet address */, + hwaddr /* ethernet address */, &ti->hw_if_index, tapcli_flag_change); @@ -995,7 +999,7 @@ tap_modify_command_fn (vlib_main_t * vm, VLIB_CLI_COMMAND (tap_modify_command, static) = { .path = "tap modify", - .short_help = "tap modify [hwaddr [ | random]]", + .short_help = "tap modify [hwaddr ]", .function = tap_modify_command_fn, }; @@ -1006,7 +1010,6 @@ tap_connect_command_fn (vlib_main_t * vm, { u8 * intfc_name; tapcli_main_t * tm = &tapcli_main; - int user_hwaddr = 0; u8 hwaddr[6]; u8 *hwaddr_arg = 0; u32 sw_if_index; @@ -1024,21 +1027,11 @@ tap_connect_command_fn (vlib_main_t * vm, if (unformat(input, "hwaddr %U", unformat_ethernet_address, &hwaddr)) - user_hwaddr = 1; + hwaddr_arg = hwaddr; + /* It is here for backward compatibility */ if (unformat(input, "hwaddr random")) - { - f64 now = vlib_time_now(vm); - u32 rnd; - rnd = (u32) (now * 1e6); - rnd = random_u32 (&rnd); - - clib_memcpy (hwaddr+2, &rnd, sizeof(rnd)); - hwaddr[0] = 2; - hwaddr[1] = 0xfe; - user_hwaddr = 1; - } - if (user_hwaddr) hwaddr_arg = hwaddr; + ; int rv = vnet_tap_connect(vm, intfc_name, hwaddr_arg, &sw_if_index); if (rv) { @@ -1095,7 +1088,7 @@ tap_connect_command_fn (vlib_main_t * vm, VLIB_CLI_COMMAND (tap_connect_command, static) = { .path = "tap connect", - .short_help = "tap connect [hwaddr [ | random]]", + .short_help = "tap connect [hwaddr ]", .function = tap_connect_command_fn, }; -- cgit 1.2.3-korg