X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=inline;f=lib%2Flibrte_ether%2Frte_ether.h;h=71dc7884f78eceb06fe779fa57a0171536aad5fd;hb=57f0ba5f8b8588dfa6ffcd001447ef6337afa6cd;hp=e038592c4f2cf14da2845aa3c62a6a0a7d80586a;hpb=88ac4396ad290a0287f6c533bd022d0cebcd8374;p=dpdk.git diff --git a/lib/librte_ether/rte_ether.h b/lib/librte_ether/rte_ether.h index e038592c4f..71dc7884f7 100644 --- a/lib/librte_ether/rte_ether.h +++ b/lib/librte_ether/rte_ether.h @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2013 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -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. *