2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2011, Lei Xia <lxia@northwestern.edu>
11 * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Lei Xia <lxia@northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #ifndef __ETHERNET_H__
21 #define __ETHERNET_H__
23 #define ETHERNET_HEADER_LEN 14
24 #define ETHERNET_MTU 1500
25 #define ETHERNET_PACKET_LEN (ETHERNET_HEADER_LEN + ETHERNET_MTU)
31 #include <palacios/vmm.h>
33 static inline int is_multicast_ethaddr(const uint8_t * addr)
35 V3_ASSERT(ETH_ALEN == 6);
37 return (0x01 & addr[0]);
40 static inline int is_broadcast_ethaddr(const uint8_t * addr)
42 V3_ASSERT(ETH_ALEN == 6);
44 return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;
48 static inline int compare_ethaddr(const uint8_t * addr1, const uint8_t * addr2)
50 const uint16_t *a = (const uint16_t *) addr1;
51 const uint16_t *b = (const uint16_t *) addr2;
53 V3_ASSERT(ETH_ALEN == 6);
54 return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;
58 static inline int compare_ether_hdr(const uint8_t * hdr1, const uint8_t * hdr2)
60 uint32_t *a32 = (uint32_t *)(hdr1 + 2);
61 uint32_t *b32 = (uint32_t *)(hdr2 + 2);
63 V3_ASSERT(ETHERNET_HEADER_LEN == 14);
65 return (*(uint16_t *)hdr1 ^ *(uint16_t *)hdr2) | (a32[0] ^ b32[0]) |
66 (a32[1] ^ b32[1]) | (a32[2] ^ b32[2]);