Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Add MAC address configure support on Virtio NIC
[palacios.git] / palacios / include / palacios / vmm_ethernet.h
1 /* 
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.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2011, Lei Xia <lxia@northwestern.edu> 
11  * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Lei Xia <lxia@northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #ifndef __ETHERNET_H__
21 #define __ETHERNET_H__
22
23 #define ETHERNET_HEADER_LEN 14
24 #define ETHERNET_MTU   1500
25 #define ETHERNET_PACKET_LEN (ETHERNET_HEADER_LEN + ETHERNET_MTU)
26 #define ETH_ALEN 6
27
28
29 #ifdef __V3VEE__
30
31 #include <palacios/vmm.h>
32
33 static inline int is_multicast_ethaddr(const uint8_t * addr)
34 {
35     V3_ASSERT(ETH_ALEN == 6);
36         
37     return (0x01 & addr[0]);
38 }
39
40 static inline int is_broadcast_ethaddr(const uint8_t * addr)
41 {
42     V3_ASSERT(ETH_ALEN == 6);
43         
44     return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;
45 }
46
47
48 static inline int compare_ethaddr(const uint8_t * addr1, const uint8_t * addr2)
49 {
50     const uint16_t *a = (const uint16_t *) addr1;
51     const uint16_t *b = (const uint16_t *) addr2;
52
53     V3_ASSERT(ETH_ALEN == 6);
54     return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;
55 }
56
57
58 static inline int compare_ether_hdr(const uint8_t * hdr1, const uint8_t * hdr2)
59 {
60     uint32_t *a32 = (uint32_t *)(hdr1 + 2);
61     uint32_t *b32 = (uint32_t *)(hdr2 + 2);
62
63     V3_ASSERT(ETHERNET_HEADER_LEN == 14);
64
65     return (*(uint16_t *)hdr1 ^ *(uint16_t *)hdr2) | (a32[0] ^ b32[0]) |
66              (a32[1] ^ b32[1]) | (a32[2] ^ b32[2]);
67 }
68
69 #endif
70
71 #endif
72
73