From: Intel Date: Wed, 18 Sep 2013 10:00:00 +0000 (+0200) Subject: ethdev: random MAC address X-Git-Tag: spdx-start~11134 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=7ef007291004de0bb2a5d298cb11d07a9f9d088e;p=dpdk.git ethdev: random MAC address Factorize code by moving random_addr() function in only place. It will be reused for virtio. Signed-off-by: Intel --- diff --git a/lib/librte_ether/rte_ether.h b/lib/librte_ether/rte_ether.h index e038592c4f..c6782b85bc 100644 --- a/lib/librte_ether/rte_ether.h +++ b/lib/librte_ether/rte_ether.h @@ -46,6 +46,9 @@ extern "C" { #include +#include +#include + #define ETHER_ADDR_LEN 6 /**< Length of Ethernet address. */ #define ETHER_TYPE_LEN 2 /**< Length of Ethernet type field. */ #define ETHER_CRC_LEN 4 /**< Length of Ethernet CRC. */ @@ -195,6 +198,22 @@ static inline int is_valid_assigned_ether_addr(const struct ether_addr *ea) return (is_unicast_ether_addr(ea) && (! is_zero_ether_addr(ea))); } +/** + * Generate a random Ethernet address that is locally administered + * and not multicast. + * @param addr + * A pointer to Ethernet address. + */ +static inline void eth_random_addr(uint8_t *addr) +{ + uint64_t rand = rte_rand(); + uint8_t *p = (uint8_t*)&rand; + + rte_memcpy(addr, p, ETHER_ADDR_LEN); + addr[0] &= ~ETHER_GROUP_ADDR; /* clear multicast bit */ + addr[0] |= ETHER_LOCAL_ADMIN_ADDR; /* set local assignment bit */ +} + /** * Fast copy an Ethernet address. * diff --git a/lib/librte_pmd_e1000/igb_pf.c b/lib/librte_pmd_e1000/igb_pf.c index 68f7c69c53..9c1c9dcd0a 100644 --- a/lib/librte_pmd_e1000/igb_pf.c +++ b/lib/librte_pmd_e1000/igb_pf.c @@ -54,17 +54,6 @@ #include "e1000/e1000_hw.h" #include "e1000_ethdev.h" -static inline -void eth_random_addr(uint8_t *addr) -{ - uint64_t rand = rte_rand(); - uint8_t *p = (uint8_t*)&rand; - - rte_memcpy(addr, p, ETHER_ADDR_LEN); - addr[0] &= 0xfe; /* clear multicast bit */ - addr[0] |= 0x02; /* set local assignment bit (IEEE802) */ -} - static inline uint16_t dev_num_vf(struct rte_eth_dev *eth_dev) { diff --git a/lib/librte_pmd_ixgbe/ixgbe_pf.c b/lib/librte_pmd_ixgbe/ixgbe_pf.c index c61b7149f0..f1207c0c3a 100644 --- a/lib/librte_pmd_ixgbe/ixgbe_pf.c +++ b/lib/librte_pmd_ixgbe/ixgbe_pf.c @@ -54,17 +54,6 @@ #define IXGBE_MAX_VFTA (128) -static inline -void eth_random_addr(uint8_t *addr) -{ - uint64_t rand = rte_rand(); - uint8_t *p = (uint8_t*)&rand; - - rte_memcpy(addr, p, ETHER_ADDR_LEN); - addr[0] &= 0xfe; /* clear multicast bit */ - addr[0] |= 0x02; /* set local assignment bit (IEEE802) */ -} - static inline uint16_t dev_num_vf(struct rte_eth_dev *eth_dev) {