Initial import
[openvswitch] / datapath / linux-2.4 / compat-2.4 / include / linux / etherdevice.h
1 #ifndef __LINUX_ETHERDEVICE_WRAPPER_H
2 #define __LINUX_ETHERDEVICE_WRAPPER_H 1
3
4 #include_next <linux/etherdevice.h>
5 #include <linux/random.h>
6
7 /**
8  * is_multicast_ether_addr - Determine if the Ethernet address is a multicast.
9  * @addr: Pointer to a six-byte array containing the Ethernet address
10  *
11  * Return true if the address is a multicast address.
12  * By definition the broadcast address is also a multicast address.
13  */
14 static inline int is_multicast_ether_addr(const u8 *addr)
15 {
16     return (0x01 & addr[0]);
17 }
18
19 /**
20  * is_local_ether_addr - Determine if the Ethernet address is locally-assigned
21  * one (IEEE 802).
22  * @addr: Pointer to a six-byte array containing the Ethernet address
23  *
24  * Return true if the address is a local address.
25  */
26 static inline int is_local_ether_addr(const u8 *addr)
27 {
28     return (0x02 & addr[0]);
29 }
30
31 /**
32  * is_broadcast_ether_addr - Determine if the Ethernet address is broadcast
33  * @addr: Pointer to a six-byte array containing the Ethernet address
34  *
35  * Return true if the address is the broadcast address.
36  */
37 static inline int is_broadcast_ether_addr(const u8 *addr)
38 {
39     return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;
40 }
41
42 /**
43  * random_ether_addr - Generate software assigned random Ethernet address
44  * @addr: Pointer to a six-byte array containing the Ethernet address
45  *
46  * Generate a random Ethernet address (MAC) that is not multicast
47  * and has the local assigned bit set.
48  */
49 static inline void random_ether_addr(u8 *addr)
50 {
51         get_random_bytes (addr, ETH_ALEN);
52         addr [0] &= 0xfe;       /* clear multicast bit */
53         addr [0] |= 0x02;       /* set local assignment bit (IEEE802) */
54 }
55
56 /**
57  * compare_ether_addr - Compare two Ethernet addresses
58  * @addr1: Pointer to a six-byte array containing the Ethernet address
59  * @addr2: Pointer other six-byte array containing the Ethernet address
60  *
61  * Compare two ethernet addresses, returns 0 if equal
62  */
63 static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2)
64 {
65     const u16 *a = (const u16 *) addr1;
66     const u16 *b = (const u16 *) addr2;
67
68     return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;
69 }
70
71 #endif