X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Finclude%2Fpalacios%2Fvmm_ethernet.h;h=f5e98227ee4446ae5a1f4667bd09b4ba33a224cd;hb=9381e554546d0f27197bf20f53bd05e95169b21a;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..f5e9822 100644 --- a/palacios/include/palacios/vmm_ethernet.h +++ b/palacios/include/palacios/vmm_ethernet.h @@ -30,6 +30,19 @@ #include + +struct nic_statistics { + uint64_t tx_pkts; + uint64_t tx_bytes; + uint64_t tx_dropped; + + uint64_t rx_pkts; + uint64_t rx_bytes; + uint64_t rx_dropped; + + uint32_t interrupts; +}; + static inline int is_multicast_ethaddr(const uint8_t * addr) { V3_ASSERT(ETH_ALEN == 6); @@ -66,6 +79,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