ia64/xen-unstable

view tools/vnet/vnet-module/varp_util.h @ 6946:e703abaf6e3d

Add behaviour to the remove methods to remove the transaction's path itself. This allows us to write Remove(path) to remove the specified path rather than having to slice the path ourselves.
author emellor@ewan
date Sun Sep 18 14:42:13 2005 +0100 (2005-09-18)
parents 3233e7ecfa9f
children 06d84bf87159
line source
1 /*
2 * Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free software Foundation, Inc.,
16 * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19 #ifndef _VNET_VARP_UTIL_H
20 #define _VNET_VARP_UTIL_H
22 #include "hash_table.h"
24 /** Size of a string buffer to store a varp address. */
25 #define VARP_ADDR_BUF 56
27 /** Size of a string buffer to store a vnet id. */
28 #define VNET_ID_BUF 56
30 #ifndef NIPQUAD
31 #define NIPQUAD(addr) \
32 ((unsigned char *)&addr)[0], \
33 ((unsigned char *)&addr)[1], \
34 ((unsigned char *)&addr)[2], \
35 ((unsigned char *)&addr)[3]
36 #endif
38 #ifndef NIP6
39 #define NIP6(addr) \
40 ntohs((addr).s6_addr16[0]), \
41 ntohs((addr).s6_addr16[1]), \
42 ntohs((addr).s6_addr16[2]), \
43 ntohs((addr).s6_addr16[3]), \
44 ntohs((addr).s6_addr16[4]), \
45 ntohs((addr).s6_addr16[5]), \
46 ntohs((addr).s6_addr16[6]), \
47 ntohs((addr).s6_addr16[7])
48 #endif
51 static inline const char *VarpAddr_ntoa(VarpAddr *addr, char buf[VARP_ADDR_BUF])
52 {
53 switch(addr->family){
54 default:
55 case AF_INET:
56 sprintf(buf, "%u.%u.%u.%u",
57 NIPQUAD(addr->u.ip4));
58 break;
59 case AF_INET6:
60 sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
61 NIP6(addr->u.ip6));
62 break;
63 }
64 return buf;
65 }
67 static inline const char *VnetId_ntoa(VnetId *vnet, char buf[VNET_ID_BUF])
68 {
69 sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
70 ntohs(vnet->u.vnet16[0]), \
71 ntohs(vnet->u.vnet16[1]), \
72 ntohs(vnet->u.vnet16[2]), \
73 ntohs(vnet->u.vnet16[3]), \
74 ntohs(vnet->u.vnet16[4]), \
75 ntohs(vnet->u.vnet16[5]), \
76 ntohs(vnet->u.vnet16[6]), \
77 ntohs(vnet->u.vnet16[7]));
78 return buf;
79 }
81 extern int VnetId_aton(const char *s, VnetId *vnet);
83 /** Convert an unsigned in host order to a vnet id.
84 */
85 static inline struct VnetId toVnetId(uint32_t vnetid){
86 struct VnetId vnet = {};
87 vnet.u.vnet32[3] = htonl(vnetid);
88 return vnet;
89 }
91 static inline uint32_t VnetId_hash(uint32_t h, VnetId *vnet)
92 {
93 h = hash_hul(h, vnet->u.vnet32[0]);
94 h = hash_hul(h, vnet->u.vnet32[1]);
95 h = hash_hul(h, vnet->u.vnet32[2]);
96 h = hash_hul(h, vnet->u.vnet32[3]);
97 return h;
98 }
100 static inline int VnetId_eq(VnetId *vnet1, VnetId *vnet2)
101 {
102 return memcmp(vnet1, vnet2, sizeof(VnetId)) == 0;
103 }
105 static inline uint32_t VarpAddr_hash(uint32_t h, VarpAddr *addr)
106 {
107 h = hash_hul(h, addr->family);
108 if(addr->family == AF_INET6){
109 h = hash_hul(h, addr->u.ip6.s6_addr32[0]);
110 h = hash_hul(h, addr->u.ip6.s6_addr32[1]);
111 h = hash_hul(h, addr->u.ip6.s6_addr32[2]);
112 h = hash_hul(h, addr->u.ip6.s6_addr32[3]);
113 } else {
114 h = hash_hul(h, addr->u.ip4.s_addr);
115 }
116 return h;
117 }
119 static inline int VarpAddr_eq(VarpAddr *addr1, VarpAddr*addr2)
120 {
121 return memcmp(addr1, addr2, sizeof(VarpAddr)) == 0;
122 }
124 static inline uint32_t Vmac_hash(uint32_t h, Vmac *vmac)
125 {
126 h = hash_hul(h,
127 (vmac->mac[0] << 24) |
128 (vmac->mac[1] << 16) |
129 (vmac->mac[2] << 8) |
130 (vmac->mac[3] ));
131 h = hash_hul(h,
132 (vmac->mac[4] << 8) |
133 (vmac->mac[5] ));
134 return h;
135 }
137 static inline int Vmac_eq(Vmac *vmac1, Vmac *vmac2)
138 {
139 return memcmp(vmac1, vmac2, sizeof(Vmac)) == 0;
140 }
142 #endif /* _VNET_VARP_UTIL_H */