[gPXE git] mainline commit to master: [ethernet] Move Ethernet MAC address checking routines to ethernet.h

git at etherboot.org git at etherboot.org
Wed Jun 16 04:36:58 EDT 2010


In the Main gPXE repository, branch master has been updated.
      adds  b97c7df [ethernet] Move Ethernet MAC address checking routines to ethernet.h
      from  af585ca [jme] Fix refill behavior

Summary of changes:
 src/drivers/net/vxge/vxge_config.c |    1 +
 src/drivers/net/vxge/vxge_main.h   |   16 ---------
 src/include/gpxe/ethernet.h        |   66 ++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 16 deletions(-)


- Log -----------------------------------------------------------------
------
commit b97c7df02afea7e8a311be9767c839a654717827
Author: Michael Brown <mcb30 at ipxe.org>
Date: Fri Jun 4 22:24:45 2010 +0300
Committer: Stefan Hajnoczi <stefanha at gmail.com>

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

Originally-fixed-by: Faur Andrei <da3drus at gmail.com>
Signed-off-by: Michael Brown <mcb30 at ipxe.org>
Signed-off-by: Stefan Hajnoczi <stefanha at gmail.com>

diff --git a/src/drivers/net/vxge/vxge_config.c b/src/drivers/net/vxge/vxge_config.c
index 2cbe453..6613cb2 100644
--- a/src/drivers/net/vxge/vxge_config.c
+++ b/src/drivers/net/vxge/vxge_config.c
@@ -18,6 +18,7 @@ FILE_LICENCE(GPL2_ONLY);
 #include <stdio.h>
 #include <gpxe/malloc.h>
 #include <gpxe/iobuf.h>
+#include <gpxe/ethernet.h>
 #include <byteswap.h>
 
 #include "vxge_traffic.h"
diff --git a/src/drivers/net/vxge/vxge_main.h b/src/drivers/net/vxge/vxge_main.h
index a384b49..b834c03 100644
--- a/src/drivers/net/vxge/vxge_main.h
+++ b/src/drivers/net/vxge/vxge_main.h
@@ -211,22 +211,6 @@ struct vxgedev {
 	char			fw_version[VXGE_HW_FW_STRLEN];
 };
 
-static inline int is_zero_ether_addr(const u8 *addr)
-{
-	return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
-}
-
-static inline int is_multicast_ether_addr(const u8 *addr)
-{
-	return (0x01 & addr[0]);
-}
-
-/* checks the ethernet address @addr is a valid unicast */
-static inline int is_valid_ether_addr(const u8 *addr)
-{
-	return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
-}
-
 void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id);
 
 void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id);
diff --git a/src/include/gpxe/ethernet.h b/src/include/gpxe/ethernet.h
index 4dfc24d..3e68a84 100644
--- a/src/include/gpxe/ethernet.h
+++ b/src/include/gpxe/ethernet.h
@@ -11,6 +11,72 @@ FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <stdint.h>
 
+/**
+ * Check if Ethernet address is all zeroes
+ *
+ * @v addr		Ethernet address
+ * @ret is_zero		Address is all zeroes
+ */
+static inline int is_zero_ether_addr ( const void *addr ) {
+	const uint8_t *addr_bytes = addr;
+
+	return ( ! ( addr_bytes[0] | addr_bytes[1] | addr_bytes[2] |
+		     addr_bytes[3] | addr_bytes[4] | addr_bytes[5] ) );
+}
+
+/**
+ * Check if Ethernet address is a multicast address
+ *
+ * @v addr		Ethernet address
+ * @ret is_mcast	Address is a multicast address
+ *
+ * Note that the broadcast address is also a multicast address.
+ */
+static inline int is_multicast_ether_addr ( const void *addr ) {
+	const uint8_t *addr_bytes = addr;
+
+	return ( addr_bytes[0] & 0x01 );
+}
+
+/**
+ * Check if Ethernet address is locally assigned
+ *
+ * @v addr		Ethernet address
+ * @ret is_local	Address is locally assigned
+ */
+static inline int is_local_ether_addr ( const void *addr ) {
+	const uint8_t *addr_bytes = addr;
+
+	return ( addr_bytes[0] & 0x02 );
+}
+
+/**
+ * Check if Ethernet address is the broadcast address
+ *
+ * @v addr		Ethernet address
+ * @ret is_bcast	Address is the broadcast address
+ */
+static inline int is_broadcast_ether_addr ( const void *addr ) {
+	const uint8_t *addr_bytes = addr;
+
+	return ( ( addr_bytes[0] & addr_bytes[1] & addr_bytes[2] &
+		   addr_bytes[3] & addr_bytes[4] & addr_bytes[5] ) == 0xff );
+}
+
+/**
+ * Check if Ethernet address is valid
+ *
+ * @v addr		Ethernet address
+ * @ret is_valid	Address is valid
+ *
+ * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is
+ * not a multicast address, and is not ff:ff:ff:ff:ff:ff.
+ */
+static inline int is_valid_ether_addr ( const void *addr ) {
+	return ( ( ! is_multicast_ether_addr ( addr ) ) &&
+		 ( ! is_zero_ether_addr ( addr ) ) );
+}
+
 extern void eth_init_addr ( const void *hw_addr, void *ll_addr );
 extern const char * eth_ntoa ( const void *ll_addr );
 extern int eth_mc_hash ( unsigned int af, const void *net_addr,
-----------------------------------------------------------------------


-- 
Main gPXE repository


More information about the gPXE-commits mailing list