ia64/xen-unstable

view tools/vnet/vnet-module/varp.h @ 8740:3d7ea7972b39

Update patches for linux 2.6.15.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Feb 02 17:16:00 2006 +0000 (2006-02-02)
parents 06d84bf87159
children 71b0f00f6344
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 */
20 #ifndef _VNET_VARP_H
21 #define _VNET_VARP_H
22 #include "hash_table.h"
23 #include "if_varp.h"
24 #include "varp_util.h"
27 #define CONFIG_VARP_GRATUITOUS 1
29 struct net_device;
30 struct sk_buff;
31 struct Vif;
33 extern int vnet_get_device(const char *name, struct net_device **dev);
34 extern int vnet_get_device_address(struct net_device *dev, u32 *addr);
36 extern int varp_handle_message(struct sk_buff *skb);
37 extern int varp_output(struct sk_buff *skb, struct VnetId *vnet);
38 extern int varp_update(struct VnetId *vnet, unsigned char *vmac, struct VarpAddr *addr);
40 extern int varp_init(void);
41 extern void varp_exit(void);
43 extern int varp_open(u32 mcaddr, u16 port);
44 extern void varp_close(void);
45 extern int varp_set_mcast_addr(u32 addr);
47 extern void varp_print(void);
48 extern void varp_flush(void);
50 extern int varp_announce_vif(struct net_device *dev, struct Vif *vif);
52 extern u32 varp_mcast_addr;
54 /* MAC broadcast addr is ff-ff-ff-ff-ff-ff (all 1's).
55 * MAC multicast addr has low bit 1, i.e. 01-00-00-00-00-00.
56 */
58 /** Test if a MAC address is a multicast or broadcast address.
59 *
60 * @param mac address
61 * @return 1 if it is, 0 if not
62 */
63 static inline int mac_is_multicast(u8 mac[ETH_ALEN]){
64 return mac[0] & 1;
65 }
67 /** Test if a MAC address is the broadcast address.
68 *
69 * @param mac address
70 * @return 1 if it is, 0 if not
71 */
72 static inline int mac_is_broadcast(u8 mac[ETH_ALEN]){
73 u8 mac_bcast_val[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
74 return memcmp(mac, mac_bcast_val, ETH_ALEN) == 0;
75 }
77 /** Test if a MAC address is the all-zero address.
78 *
79 * @param mac address
80 * @return 1 if it is, 0 if not
81 */
82 static inline int mac_is_zero(u8 mac[ETH_ALEN]){
83 u8 mac_zero_val[ETH_ALEN] = {};
84 return memcmp(mac, mac_zero_val, ETH_ALEN) == 0;
85 }
87 /** Print format for a mac address. */
88 #define MACFMT "%02x:%02x:%02x:%02x:%02x:%02x"
90 #define MAC6TUPLE(_mac) (_mac)[0], (_mac)[1], (_mac)[2], (_mac)[3], (_mac)[4], (_mac)[5]
92 /** Get the subnet defined by a netmask and addr.
93 *
94 * @param netmask subnet netmask
95 * @param addr subnet address
96 * @return subnet
97 */
98 static inline u32 subnet_net(u32 netmask, u32 addr){
99 return netmask & addr;
100 }
102 /** Get the address within a subnet.
103 *
104 * @param netmask subnet netmask
105 * @param addr address
106 * @return address within the subnet
107 */
108 static inline u32 subnet_addr(u32 netmask, u32 addr){
109 return ~netmask & addr;
110 }
112 /** Get the broadcast address for a subnet.
113 *
114 * @param netmask subnet netmask
115 * @param netaddr subnet address
116 * @return subnet broadcast address
117 */
118 static inline u32 subnet_broadcast_addr(u32 netmask, u32 netaddr){
119 return subnet_net(netmask, netaddr) | ~netmask;
120 }
122 /** Test if an address corresponds to a subnet broadcast.
123 * True if the address within the subnet is all 1's (in binary).
124 * (even if the address is not in the subnet).
125 *
126 * @param netmask subnet mask
127 * @param add address
128 * @return 1 if it does, 0 otherwise
129 */
130 static inline int subnet_broadcast(u32 netmask, u32 addr){
131 return subnet_addr(netmask, INADDR_ANY) == subnet_addr(netmask, addr);
132 }
134 /** Test if an address is in a subnet.
135 *
136 * @param netmask subnet mask
137 * @param netaddr subnet address
138 * @param addr address
139 * @return 1 if it is, 0 otherwise
140 */
141 static inline int subnet_local(u32 netmask, u32 netaddr, u32 addr){
142 return subnet_net(netmask, netaddr) == subnet_net(netmask, addr);
143 }
145 #endif /* ! _VNET_VARP_H */