Hello, The first patch adds routines used by some drivers (including the new pcnet32) that check the validity of Ethernet MAC addresses.
The second patch removes this code from the vxge driver. -- Andrei Faur
From b5ee56fb2762ec3cd4219a252c3fcf8e48423776 Mon Sep 17 00:00:00 2001 From: Andrei Faur <[email protected]> Date: Fri, 4 Jun 2010 22:24:45 +0300 Subject: [PATCH 1/2] Add Ethernet MAC address checking routines --- src/include/gpxe/ethernet.h | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 64 insertions(+), 0 deletions(-) diff --git a/src/include/gpxe/ethernet.h b/src/include/gpxe/ethernet.h index 4dfc24d..e10b9eb 100644 --- a/src/include/gpxe/ethernet.h +++ b/src/include/gpxe/ethernet.h @@ -18,4 +18,68 @@ extern int eth_mc_hash ( unsigned int af, const void *net_addr, extern int eth_eth_addr ( const void *ll_addr, void *eth_addr ); extern struct net_device * alloc_etherdev ( size_t priv_size ); +/** + * is_zero_ether_addr - Determine if give Ethernet address is all zeros. + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is all zeroes. + */ +static inline int is_zero_ether_addr ( const u8 *addr ) +{ + return ! ( addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5] ); +} + +/** + * is_multicast_ether_addr - Determine if the Ethernet address is a multicast. + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is a multicast address. + * By definition the broadcast address is also a multicast address. + */ +static inline int is_multicast_ether_addr ( const u8 *addr ) +{ + return ( 0x01 & addr[0] ); +} + +/** + * is_local_ether_addr - Determine if the Ethernet address is + * locally-assigned one (IEEE 802). + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is a local address. + */ +static inline int is_local_ether_addr ( const u8 *addr ) +{ + return ( 0x02 & addr[0] ); +} + +/** + * is_broadcast_ether_addr - Determine if the Ethernet address is broadcast + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is the broadcast address. + */ +static inline int is_broadcast_ether_addr ( const u8 *addr ) +{ + return ( addr[0] & addr[1] & addr[2] & + addr[3] & addr[4] & addr[5] ) == 0xff; +} + +/** + * is_valid_ether_addr - Determine if the given Ethernet address is valid + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * 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. + * + * Return true if the address is valid. + */ +static inline int is_valid_ether_addr ( const u8 *addr ) +{ + /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to + * explicitly check for it here. */ + return ( ! is_multicast_ether_addr ( addr ) ) && + ( ! is_zero_ether_addr ( addr ) ); +} + #endif /* _GPXE_ETHERNET_H */ -- 1.6.3.3
From 84c13df7ebc0d89151fffa2e85dc5b9f4c6e9da6 Mon Sep 17 00:00:00 2001 From: Andrei Faur <[email protected]> Date: Fri, 4 Jun 2010 22:27:58 +0300 Subject: [PATCH 2/2] Remove vxge driver MAC address checking code --- src/drivers/net/vxge/vxge_config.c | 1 + src/drivers/net/vxge/vxge_main.h | 16 ---------------- 2 files changed, 1 insertions(+), 16 deletions(-) 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); -- 1.6.3.3
_______________________________________________ gPXE-devel mailing list [email protected] http://etherboot.org/mailman/listinfo/gpxe-devel
