[NET]: Add is_multicast_ether_addr() in include/linux/etherdevice.h

This patch adds is_multicast_ether_addr() to go along with
is_valid_ether_addr() and friends. It then changes
is_valid_ether_addr() to use the new macro, and fixes up the comment
on that function to move implementation details out of the API doco.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Michael Ellerman and committed by
David S. Miller
79165121 8f937c60

+18 -4
+18 -4
include/linux/etherdevice.h
··· 56 } 57 58 /** 59 * is_valid_ether_addr - Determine if the given Ethernet address is valid 60 * @addr: Pointer to a six-byte array containing the Ethernet address 61 * 62 * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not 63 - * a multicast address, and is not FF:FF:FF:FF:FF:FF. The multicast 64 - * and FF:FF:... tests are combined into the single test "!(addr[0]&1)". 65 * 66 * Return true if the address is valid. 67 */ 68 static inline int is_valid_ether_addr(const u8 *addr) 69 { 70 - return !(addr[0]&1) && !is_zero_ether_addr(addr); 71 } 72 73 /** ··· 97 addr [0] &= 0xfe; /* clear multicast bit */ 98 addr [0] |= 0x02; /* set local assignment bit (IEEE802) */ 99 } 100 - #endif 101 102 #endif /* _LINUX_ETHERDEVICE_H */
··· 56 } 57 58 /** 59 + * is_multicast_ether_addr - Determine if the given Ethernet address is a 60 + * multicast address. 61 + * 62 + * @addr: Pointer to a six-byte array containing the Ethernet address 63 + * 64 + * Return true if the address is a multicast address. 65 + */ 66 + static inline int is_multicast_ether_addr(const u8 *addr) 67 + { 68 + return addr[0] & 0x01; 69 + } 70 + 71 + /** 72 * is_valid_ether_addr - Determine if the given Ethernet address is valid 73 * @addr: Pointer to a six-byte array containing the Ethernet address 74 * 75 * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not 76 + * a multicast address, and is not FF:FF:FF:FF:FF:FF. 77 * 78 * Return true if the address is valid. 79 */ 80 static inline int is_valid_ether_addr(const u8 *addr) 81 { 82 + /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to 83 + * explicitly check for it here. */ 84 + return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr); 85 } 86 87 /** ··· 83 addr [0] &= 0xfe; /* clear multicast bit */ 84 addr [0] |= 0x02; /* set local assignment bit (IEEE802) */ 85 } 86 + #endif /* __KERNEL__ */ 87 88 #endif /* _LINUX_ETHERDEVICE_H */