etherdevice.h revision 289624
1/* $FreeBSD: head/sys/ofed/include/linux/etherdevice.h 289624 2015-10-20 11:40:04Z hselasky $ */ 2/*- 3 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. 4 * Copyright (c) 2014 Mellanox Technologies, Ltd. All rights reserved. 5 * 6 * This software is available to you under a choice of one of two 7 * licenses. You may choose to be licensed under the terms of the GNU 8 * General Public License (GPL) Version 2, available from the file 9 * COPYING in the main directory of this source tree, or the 10 * OpenIB.org BSD license below: 11 * 12 * Redistribution and use in source and binary forms, with or 13 * without modification, are permitted provided that the following 14 * conditions are met: 15 * 16 * - Redistributions of source code must retain the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer. 19 * 20 * - Redistributions in binary form must reproduce the above 21 * copyright notice, this list of conditions and the following 22 * disclaimer in the documentation and/or other materials 23 * provided with the distribution. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 * SOFTWARE. 33 */ 34 35 36#ifndef _LINUX_ETHERDEVICE 37#define _LINUX_ETHERDEVICE 38 39#include <linux/types.h> 40 41/** 42 * is_zero_ether_addr - Determine if give Ethernet address is all zeros. 43 * @addr: Pointer to a six-byte array containing the Ethernet address 44 * 45 * Return true if the address is all zeroes. 46 */ 47static inline bool is_zero_ether_addr(const u8 *addr) 48{ 49 return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); 50} 51 52 53 54/** 55 * is_multicast_ether_addr - Determine if the Ethernet address is a multicast. 56 * @addr: Pointer to a six-byte array containing the Ethernet address 57 * 58 * Return true if the address is a multicast address. 59 * By definition the broadcast address is also a multicast address. 60 */ 61static inline bool is_multicast_ether_addr(const u8 *addr) 62{ 63 return (0x01 & addr[0]); 64} 65 66/** 67 * is_broadcast_ether_addr - Determine if the Ethernet address is broadcast 68 * @addr: Pointer to a six-byte array containing the Ethernet address 69 * 70 * Return true if the address is the broadcast address. 71 */ 72static inline bool is_broadcast_ether_addr(const u8 *addr) 73{ 74 return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff; 75} 76 77/** 78 * is_valid_ether_addr - Determine if the given Ethernet address is valid 79 * @addr: Pointer to a six-byte array containing the Ethernet address 80 * 81 * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not 82 * a multicast address, and is not FF:FF:FF:FF:FF:FF. 83 * 84 * Return true if the address is valid. 85 **/ 86static inline bool is_valid_ether_addr(const u8 *addr) 87{ 88 /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to 89 ** explicitly check for it here. */ 90 return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr); 91} 92 93static inline void ether_addr_copy(u8 *dst, const u8 *src) 94{ 95 memcpy(dst, src, 6); 96} 97 98#endif /* _LINUX_ETHERDEVICE */ 99