aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/devices/tap/tap.c12
-rw-r--r--src/vnet/ethernet/mac_address.h11
2 files changed, 13 insertions, 10 deletions
diff --git a/src/vnet/devices/tap/tap.c b/src/vnet/devices/tap/tap.c
index 0b2ebd6b5e3..2649f68713e 100644
--- a/src/vnet/devices/tap/tap.c
+++ b/src/vnet/devices/tap/tap.c
@@ -347,16 +347,8 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args)
}
if (!args->mac_addr_set)
- {
- f64 now = vlib_time_now (vm);
- u32 rnd;
- rnd = (u32) (now * 1e6);
- rnd = random_u32 (&rnd);
-
- memcpy (args->mac_addr + 2, &rnd, sizeof (rnd));
- args->mac_addr[0] = 2;
- args->mac_addr[1] = 0xfe;
- }
+ ethernet_mac_address_generate (args->mac_addr);
+
vif->rx_ring_sz = args->rx_ring_sz != 0 ? args->rx_ring_sz : 256;
vif->tx_ring_sz = args->tx_ring_sz != 0 ? args->tx_ring_sz : 256;
clib_memcpy (vif->mac_addr, args->mac_addr, 6);
diff --git a/src/vnet/ethernet/mac_address.h b/src/vnet/ethernet/mac_address.h
index 87a66a242be..01fb76e002b 100644
--- a/src/vnet/ethernet/mac_address.h
+++ b/src/vnet/ethernet/mac_address.h
@@ -70,6 +70,17 @@ ethernet_mac_address_is_zero (const u8 * mac)
return ((*((u32 *) mac) == 0) && (*((u16 *) (mac + 4)) == 0));
}
+static inline void
+ethernet_mac_address_generate (u8 * mac)
+{
+ u32 rnd = clib_cpu_time_now ();
+ rnd = random_u32 (&rnd);
+
+ memcpy (mac + 2, &rnd, sizeof (rnd));
+ mac[0] = 2;
+ mac[1] = 0xfe;
+}
+
static inline int
ethernet_mac_address_equal (const u8 * a, const u8 * b)
{