1273246Shselasky/*- 2270710Shselasky * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. 3270710Shselasky * Copyright (c) 2014 Mellanox Technologies, Ltd. All rights reserved. 4270710Shselasky * 5270710Shselasky * This software is available to you under a choice of one of two 6270710Shselasky * licenses. You may choose to be licensed under the terms of the GNU 7270710Shselasky * General Public License (GPL) Version 2, available from the file 8270710Shselasky * COPYING in the main directory of this source tree, or the 9270710Shselasky * OpenIB.org BSD license below: 10270710Shselasky * 11270710Shselasky * Redistribution and use in source and binary forms, with or 12270710Shselasky * without modification, are permitted provided that the following 13270710Shselasky * conditions are met: 14270710Shselasky * 15270710Shselasky * - Redistributions of source code must retain the above 16270710Shselasky * copyright notice, this list of conditions and the following 17270710Shselasky * disclaimer. 18270710Shselasky * 19270710Shselasky * - Redistributions in binary form must reproduce the above 20270710Shselasky * copyright notice, this list of conditions and the following 21270710Shselasky * disclaimer in the documentation and/or other materials 22270710Shselasky * provided with the distribution. 23270710Shselasky * 24270710Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25270710Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26270710Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27270710Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28270710Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29270710Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30270710Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31270710Shselasky * SOFTWARE. 32270710Shselasky */ 33270710Shselasky 34270710Shselasky 35270710Shselasky#ifndef _LINUX_ETHERDEVICE 36270710Shselasky#define _LINUX_ETHERDEVICE 37270710Shselasky 38270710Shselasky#include <linux/types.h> 39270710Shselasky 40270710Shselasky/** 41270710Shselasky * is_zero_ether_addr - Determine if give Ethernet address is all zeros. 42270710Shselasky * @addr: Pointer to a six-byte array containing the Ethernet address 43270710Shselasky * 44270710Shselasky * Return true if the address is all zeroes. 45270710Shselasky */ 46270710Shselaskystatic inline bool is_zero_ether_addr(const u8 *addr) 47270710Shselasky{ 48270710Shselasky return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); 49270710Shselasky} 50270710Shselasky 51270710Shselasky 52270710Shselasky 53270710Shselasky/** 54270710Shselasky * is_multicast_ether_addr - Determine if the Ethernet address is a multicast. 55270710Shselasky * @addr: Pointer to a six-byte array containing the Ethernet address 56270710Shselasky * 57270710Shselasky * Return true if the address is a multicast address. 58270710Shselasky * By definition the broadcast address is also a multicast address. 59270710Shselasky */ 60270710Shselaskystatic inline bool is_multicast_ether_addr(const u8 *addr) 61270710Shselasky{ 62270710Shselasky return (0x01 & addr[0]); 63270710Shselasky} 64270710Shselasky 65270710Shselasky/** 66270710Shselasky * is_broadcast_ether_addr - Determine if the Ethernet address is broadcast 67270710Shselasky * @addr: Pointer to a six-byte array containing the Ethernet address 68270710Shselasky * 69270710Shselasky * Return true if the address is the broadcast address. 70270710Shselasky */ 71270710Shselaskystatic inline bool is_broadcast_ether_addr(const u8 *addr) 72270710Shselasky{ 73270710Shselasky return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff; 74270710Shselasky} 75270710Shselasky 76270710Shselasky/** 77270710Shselasky * is_valid_ether_addr - Determine if the given Ethernet address is valid 78270710Shselasky * @addr: Pointer to a six-byte array containing the Ethernet address 79270710Shselasky * 80270710Shselasky * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not 81270710Shselasky * a multicast address, and is not FF:FF:FF:FF:FF:FF. 82270710Shselasky * 83270710Shselasky * Return true if the address is valid. 84270710Shselasky **/ 85270710Shselaskystatic inline bool is_valid_ether_addr(const u8 *addr) 86270710Shselasky{ 87270710Shselasky /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to 88270710Shselasky ** explicitly check for it here. */ 89270710Shselasky return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr); 90270710Shselasky} 91270710Shselasky 92282513Shselaskystatic inline void ether_addr_copy(u8 *dst, const u8 *src) 93282513Shselasky{ 94282513Shselasky memcpy(dst, src, 6); 95282513Shselasky} 96270710Shselasky 97270710Shselasky#endif /* _LINUX_ETHERDEVICE */ 98