X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Finclude%2Fpalacios%2Fvmm_ethernet.h;h=ddd14357025d7041d012976d2c2adfc8993be586;hb=22dbf90548cb2ea56a9057a706e3da411dc1b57b;hp=f7405fcd940fd78887b371446e3f3d2eba280cbe;hpb=e49df33562b190c348b3a117044136c704442c6b;p=palacios-OLD.git diff --git a/palacios/include/palacios/vmm_ethernet.h b/palacios/include/palacios/vmm_ethernet.h index f7405fc..ddd1435 100644 --- a/palacios/include/palacios/vmm_ethernet.h +++ b/palacios/include/palacios/vmm_ethernet.h @@ -66,6 +66,37 @@ static inline int compare_ether_hdr(const uint8_t * hdr1, const uint8_t * hdr2) (a32[1] ^ b32[1]) | (a32[2] ^ b32[2]); } +/* AA:BB:CC:DD:EE:FF */ +static inline int str2mac(char * macstr, uint8_t * mac){ + char hex[2], *s = macstr; + int i = 0; + + while(s){ + memcpy(hex, s, 2); + mac[i++] = (char)atox(hex); + if (i == ETH_ALEN) return 0; + s=strchr(s, ':'); + if(s) s++; + } + + return -1; +} + + +/* generate random ethernet address */ +static inline void random_ethaddr(uint8_t * addr) +{ + uint64_t val; + + /* using current rdtsc as random number */ + rdtscll(val); + *(uint64_t *)addr = val; + + addr [0] &= 0xfe; /* clear multicast bit */ + addr [0] |= 0x02; /* set local assignment bit (IEEE802) */ +} + + #endif #endif