Browse Source

[ethernet] Move Ethernet MAC address checking routines to ethernet.h

Originally-fixed-by: Faur Andrei <da3drus@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
75333f464e
3 changed files with 67 additions and 16 deletions
  1. 1
    0
      src/drivers/net/vxge/vxge_config.c
  2. 0
    16
      src/drivers/net/vxge/vxge_main.h
  3. 66
    0
      src/include/ipxe/ethernet.h

+ 1
- 0
src/drivers/net/vxge/vxge_config.c View File

@@ -18,6 +18,7 @@ FILE_LICENCE(GPL2_ONLY);
18 18
 #include <stdio.h>
19 19
 #include <ipxe/malloc.h>
20 20
 #include <ipxe/iobuf.h>
21
+#include <ipxe/ethernet.h>
21 22
 #include <byteswap.h>
22 23
 
23 24
 #include "vxge_traffic.h"

+ 0
- 16
src/drivers/net/vxge/vxge_main.h View File

@@ -211,22 +211,6 @@ struct vxgedev {
211 211
 	char			fw_version[VXGE_HW_FW_STRLEN];
212 212
 };
213 213
 
214
-static inline int is_zero_ether_addr(const u8 *addr)
215
-{
216
-	return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
217
-}
218
-
219
-static inline int is_multicast_ether_addr(const u8 *addr)
220
-{
221
-	return (0x01 & addr[0]);
222
-}
223
-
224
-/* checks the ethernet address @addr is a valid unicast */
225
-static inline int is_valid_ether_addr(const u8 *addr)
226
-{
227
-	return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
228
-}
229
-
230 214
 void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id);
231 215
 
232 216
 void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id);

+ 66
- 0
src/include/ipxe/ethernet.h View File

@@ -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,

Loading…
Cancel
Save