diff options
author | Michael Brown <mcb30@ipxe.org> | 2010-06-04 22:24:45 +0300 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2010-06-07 15:21:04 +0100 |
commit | 75333f464e9f7c810a9c756b0553a02dbcb39d57 (patch) | |
tree | 2a2dde5871ca7ba96d97cf2184e50016d9ac8947 /src/include/ipxe/ethernet.h | |
parent | 3fc4fd32133de89c46405a2d10762b965ad6525b (diff) | |
download | ipxe-75333f464e9f7c810a9c756b0553a02dbcb39d57.zip ipxe-75333f464e9f7c810a9c756b0553a02dbcb39d57.tar.gz ipxe-75333f464e9f7c810a9c756b0553a02dbcb39d57.tar.bz2 |
[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>
Diffstat (limited to 'src/include/ipxe/ethernet.h')
-rw-r--r-- | src/include/ipxe/ethernet.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/include/ipxe/ethernet.h b/src/include/ipxe/ethernet.h index 5799092..7e49655 100644 --- a/src/include/ipxe/ethernet.h +++ b/src/include/ipxe/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, |