2
* Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
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.
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
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
27
#include "sys_kernel.h"
31
#include "hash_table.h"
33
#include "varp_util.h"
35
#define CONFIG_VARP_GRATUITOUS 1
42
VARP_UPDATE_CREATE = 1,
43
VARP_UPDATE_QUEUE = 2,
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);
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);
55
extern int varp_init(void);
56
extern void varp_exit(void);
58
extern int varp_open(u32 mcaddr, u16 port);
59
extern void varp_close(void);
60
extern int varp_set_mcast_addr(u32 addr);
62
extern void varp_print(struct IOStream *io);
63
extern void varp_flush(void);
65
extern int varp_announce_vif(struct net_device *dev, struct Vif *vif);
67
extern u32 varp_mcast_addr;
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.
74
/** Test if a MAC address is a multicast or broadcast address.
77
* @return 1 if it is, 0 if not
79
static inline int mac_is_multicast(u8 mac[ETH_ALEN]){
83
/** Test if a MAC address is the broadcast address.
86
* @return 1 if it is, 0 if not
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;
93
/** Test if a MAC address is the all-zero address.
96
* @return 1 if it is, 0 if not
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;
103
/** Print format for a mac address. */
104
#define MACFMT "%02x:%02x:%02x:%02x:%02x:%02x"
106
#define MAC6TUPLE(_mac) (_mac)[0], (_mac)[1], (_mac)[2], (_mac)[3], (_mac)[4], (_mac)[5]
108
/** Get the subnet defined by a netmask and addr.
110
* @param netmask subnet netmask
111
* @param addr subnet address
114
static inline u32 subnet_net(u32 netmask, u32 addr){
115
return netmask & addr;
118
/** Get the address within a subnet.
120
* @param netmask subnet netmask
121
* @param addr address
122
* @return address within the subnet
124
static inline u32 subnet_addr(u32 netmask, u32 addr){
125
return ~netmask & addr;
128
/** Get the broadcast address for a subnet.
130
* @param netmask subnet netmask
131
* @param netaddr subnet address
132
* @return subnet broadcast address
134
static inline u32 subnet_broadcast_addr(u32 netmask, u32 netaddr){
135
return subnet_net(netmask, netaddr) | ~netmask;
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).
142
* @param netmask subnet mask
144
* @return 1 if it does, 0 otherwise
146
static inline int subnet_broadcast(u32 netmask, u32 addr){
147
return subnet_addr(netmask, INADDR_ANY) == subnet_addr(netmask, addr);
150
/** Test if an address is in a subnet.
152
* @param netmask subnet mask
153
* @param netaddr subnet address
154
* @param addr address
155
* @return 1 if it is, 0 otherwise
157
static inline int subnet_local(u32 netmask, u32 netaddr, u32 addr){
158
return subnet_net(netmask, netaddr) == subnet_net(netmask, addr);
161
#endif /* ! _VNET_VARP_H */