|
@@ -11,6 +11,72 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
11
|
11
|
|
12
|
12
|
#include <stdint.h>
|
13
|
13
|
|
|
14
|
+/**
|
|
15
|
+ * Check if Ethernet address is all zeroes
|
|
16
|
+ *
|
|
17
|
+ * @v addr Ethernet address
|
|
18
|
+ * @ret is_zero Address is all zeroes
|
|
19
|
+ */
|
|
20
|
+static inline int is_zero_ether_addr ( const void *addr ) {
|
|
21
|
+ const uint8_t *addr_bytes = addr;
|
|
22
|
+
|
|
23
|
+ return ( ! ( addr_bytes[0] | addr_bytes[1] | addr_bytes[2] |
|
|
24
|
+ addr_bytes[3] | addr_bytes[4] | addr_bytes[5] ) );
|
|
25
|
+}
|
|
26
|
+
|
|
27
|
+/**
|
|
28
|
+ * Check if Ethernet address is a multicast address
|
|
29
|
+ *
|
|
30
|
+ * @v addr Ethernet address
|
|
31
|
+ * @ret is_mcast Address is a multicast address
|
|
32
|
+ *
|
|
33
|
+ * Note that the broadcast address is also a multicast address.
|
|
34
|
+ */
|
|
35
|
+static inline int is_multicast_ether_addr ( const void *addr ) {
|
|
36
|
+ const uint8_t *addr_bytes = addr;
|
|
37
|
+
|
|
38
|
+ return ( addr_bytes[0] & 0x01 );
|
|
39
|
+}
|
|
40
|
+
|
|
41
|
+/**
|
|
42
|
+ * Check if Ethernet address is locally assigned
|
|
43
|
+ *
|
|
44
|
+ * @v addr Ethernet address
|
|
45
|
+ * @ret is_local Address is locally assigned
|
|
46
|
+ */
|
|
47
|
+static inline int is_local_ether_addr ( const void *addr ) {
|
|
48
|
+ const uint8_t *addr_bytes = addr;
|
|
49
|
+
|
|
50
|
+ return ( addr_bytes[0] & 0x02 );
|
|
51
|
+}
|
|
52
|
+
|
|
53
|
+/**
|
|
54
|
+ * Check if Ethernet address is the broadcast address
|
|
55
|
+ *
|
|
56
|
+ * @v addr Ethernet address
|
|
57
|
+ * @ret is_bcast Address is the broadcast address
|
|
58
|
+ */
|
|
59
|
+static inline int is_broadcast_ether_addr ( const void *addr ) {
|
|
60
|
+ const uint8_t *addr_bytes = addr;
|
|
61
|
+
|
|
62
|
+ return ( ( addr_bytes[0] & addr_bytes[1] & addr_bytes[2] &
|
|
63
|
+ addr_bytes[3] & addr_bytes[4] & addr_bytes[5] ) == 0xff );
|
|
64
|
+}
|
|
65
|
+
|
|
66
|
+/**
|
|
67
|
+ * Check if Ethernet address is valid
|
|
68
|
+ *
|
|
69
|
+ * @v addr Ethernet address
|
|
70
|
+ * @ret is_valid Address is valid
|
|
71
|
+ *
|
|
72
|
+ * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is
|
|
73
|
+ * not a multicast address, and is not ff:ff:ff:ff:ff:ff.
|
|
74
|
+ */
|
|
75
|
+static inline int is_valid_ether_addr ( const void *addr ) {
|
|
76
|
+ return ( ( ! is_multicast_ether_addr ( addr ) ) &&
|
|
77
|
+ ( ! is_zero_ether_addr ( addr ) ) );
|
|
78
|
+}
|
|
79
|
+
|
14
|
80
|
extern void eth_init_addr ( const void *hw_addr, void *ll_addr );
|
15
|
81
|
extern const char * eth_ntoa ( const void *ll_addr );
|
16
|
82
|
extern int eth_mc_hash ( unsigned int af, const void *net_addr,
|