~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/vnet/vnet-module/varp.h

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2004, 2005 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
 
 
20
#ifndef _VNET_VARP_H
 
21
#define _VNET_VARP_H
 
22
 
 
23
#ifdef __KERNEL__
 
24
 
 
25
#else
 
26
 
 
27
#include "sys_kernel.h"
 
28
 
 
29
#endif
 
30
 
 
31
#include "hash_table.h"
 
32
#include "if_varp.h"
 
33
#include "varp_util.h"
 
34
 
 
35
#define CONFIG_VARP_GRATUITOUS 1
 
36
 
 
37
struct net_device;
 
38
struct sk_buff;
 
39
struct Vif;
 
40
 
 
41
enum {
 
42
    VARP_UPDATE_CREATE = 1,
 
43
    VARP_UPDATE_QUEUE  = 2,
 
44
};
 
45
 
 
46
extern int vnet_get_device(const char *name, struct net_device **dev);
 
47
extern int vnet_get_device_address(struct net_device *dev, u32 *addr);
 
48
 
 
49
extern int varp_remove_vnet(struct VnetId *vnet);
 
50
extern int varp_handle_message(struct sk_buff *skb);
 
51
extern int varp_output(struct sk_buff *skb, struct VnetId *vnet);
 
52
extern int varp_update(struct VnetId *vnet, unsigned char *vmac,
 
53
                       struct VarpAddr *addr);
 
54
 
 
55
extern int varp_init(void);
 
56
extern void varp_exit(void);
 
57
 
 
58
extern int varp_open(u32 mcaddr, u16 port);
 
59
extern void varp_close(void);
 
60
extern int varp_set_mcast_addr(u32 addr);
 
61
 
 
62
extern void varp_print(struct IOStream *io);
 
63
extern void varp_flush(void);
 
64
 
 
65
extern int varp_announce_vif(struct net_device *dev, struct Vif *vif);
 
66
 
 
67
extern u32 varp_mcast_addr;
 
68
extern u16 varp_port;
 
69
 
 
70
/* MAC broadcast addr is ff-ff-ff-ff-ff-ff (all 1's).
 
71
 * MAC multicast addr has low bit 1, i.e. 01-00-00-00-00-00.
 
72
 */
 
73
 
 
74
/** Test if a MAC address is a multicast or broadcast address.
 
75
 *
 
76
 * @param mac address
 
77
 * @return 1 if it is, 0 if not
 
78
 */
 
79
static inline int mac_is_multicast(u8 mac[ETH_ALEN]){
 
80
    return mac[0] & 1;
 
81
}
 
82
 
 
83
/** Test if a MAC address is the broadcast address.
 
84
 *
 
85
 * @param mac address
 
86
 * @return 1 if it is, 0 if not
 
87
 */
 
88
static inline int mac_is_broadcast(u8 mac[ETH_ALEN]){
 
89
    u8 mac_bcast_val[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
90
    return memcmp(mac, mac_bcast_val, ETH_ALEN) == 0;
 
91
}
 
92
 
 
93
/** Test if a MAC address is the all-zero address.
 
94
 *
 
95
 * @param mac address
 
96
 * @return 1 if it is, 0 if not
 
97
 */
 
98
static inline int mac_is_zero(u8 mac[ETH_ALEN]){
 
99
    u8 mac_zero_val[ETH_ALEN] = {};
 
100
    return memcmp(mac, mac_zero_val, ETH_ALEN) == 0;
 
101
}
 
102
 
 
103
/** Print format for a mac address. */
 
104
#define MACFMT "%02x:%02x:%02x:%02x:%02x:%02x"
 
105
 
 
106
#define MAC6TUPLE(_mac) (_mac)[0], (_mac)[1], (_mac)[2], (_mac)[3], (_mac)[4], (_mac)[5]
 
107
 
 
108
/** Get the subnet defined by a netmask and addr.
 
109
 *
 
110
 * @param netmask subnet netmask
 
111
 * @param addr    subnet address
 
112
 * @return subnet
 
113
 */
 
114
static inline u32 subnet_net(u32 netmask, u32 addr){
 
115
    return netmask & addr;
 
116
}
 
117
 
 
118
/** Get the address within a subnet.
 
119
 *
 
120
 * @param netmask subnet netmask
 
121
 * @param addr    address
 
122
 * @return address within the subnet
 
123
 */
 
124
static inline u32 subnet_addr(u32 netmask, u32 addr){
 
125
    return ~netmask & addr;
 
126
}
 
127
 
 
128
/** Get the broadcast address for a subnet.
 
129
 *
 
130
 * @param netmask subnet netmask
 
131
 * @param netaddr subnet address
 
132
 * @return subnet broadcast address
 
133
 */
 
134
static inline u32 subnet_broadcast_addr(u32 netmask, u32 netaddr){
 
135
    return subnet_net(netmask, netaddr) | ~netmask;
 
136
}
 
137
 
 
138
/** Test if an address corresponds to a subnet broadcast.
 
139
 * True if the address within the subnet is all 1's (in binary).
 
140
 * (even if the address is not in the subnet).
 
141
 *
 
142
 * @param netmask subnet mask
 
143
 * @param add     address
 
144
 * @return 1 if it does, 0 otherwise
 
145
 */
 
146
static inline int subnet_broadcast(u32 netmask, u32 addr){
 
147
    return subnet_addr(netmask, INADDR_ANY) == subnet_addr(netmask, addr);
 
148
}
 
149
 
 
150
/** Test if an address is in a subnet.
 
151
 *
 
152
 * @param netmask subnet mask
 
153
 * @param netaddr subnet address
 
154
 * @param addr    address
 
155
 * @return 1 if it is, 0 otherwise
 
156
 */
 
157
static inline int subnet_local(u32 netmask, u32 netaddr, u32 addr){
 
158
    return subnet_net(netmask, netaddr) == subnet_net(netmask, addr);
 
159
}
 
160
 
 
161
#endif /* ! _VNET_VARP_H */