etherdevice.h revision 282513
11590Srgrimes/*- 21590Srgrimes * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. 31590Srgrimes * Copyright (c) 2014 Mellanox Technologies, Ltd. All rights reserved. 41590Srgrimes * 51590Srgrimes * This software is available to you under a choice of one of two 61590Srgrimes * licenses. You may choose to be licensed under the terms of the GNU 71590Srgrimes * General Public License (GPL) Version 2, available from the file 81590Srgrimes * COPYING in the main directory of this source tree, or the 91590Srgrimes * OpenIB.org BSD license below: 101590Srgrimes * 111590Srgrimes * Redistribution and use in source and binary forms, with or 121590Srgrimes * without modification, are permitted provided that the following 131590Srgrimes * conditions are met: 141590Srgrimes * 151590Srgrimes * - Redistributions of source code must retain the above 161590Srgrimes * copyright notice, this list of conditions and the following 171590Srgrimes * disclaimer. 181590Srgrimes * 191590Srgrimes * - Redistributions in binary form must reproduce the above 201590Srgrimes * copyright notice, this list of conditions and the following 211590Srgrimes * disclaimer in the documentation and/or other materials 221590Srgrimes * provided with the distribution. 231590Srgrimes * 241590Srgrimes * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 251590Srgrimes * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 261590Srgrimes * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 271590Srgrimes * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 281590Srgrimes * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 291590Srgrimes * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 301590Srgrimes * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 311590Srgrimes * SOFTWARE. 321590Srgrimes */ 331590Srgrimes 341590Srgrimes 3574769Smikeh#ifndef _LINUX_ETHERDEVICE 3688150Smikeh#define _LINUX_ETHERDEVICE 3774769Smikeh 381590Srgrimes#include <linux/types.h> 3999112Sobrien 4099112Sobrien/** 411590Srgrimes * is_zero_ether_addr - Determine if give Ethernet address is all zeros. 421590Srgrimes * @addr: Pointer to a six-byte array containing the Ethernet address 431590Srgrimes * 441590Srgrimes * Return true if the address is all zeroes. 451590Srgrimes */ 461590Srgrimesstatic inline bool is_zero_ether_addr(const u8 *addr) 471590Srgrimes{ 481590Srgrimes return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); 491590Srgrimes} 501590Srgrimes 511590Srgrimes 521590Srgrimes 5377274Smikeh/** 541590Srgrimes * is_multicast_ether_addr - Determine if the Ethernet address is a multicast. 5577274Smikeh * @addr: Pointer to a six-byte array containing the Ethernet address 5677274Smikeh * 5777274Smikeh * Return true if the address is a multicast address. 581590Srgrimes * By definition the broadcast address is also a multicast address. 591590Srgrimes */ 601590Srgrimesstatic inline bool is_multicast_ether_addr(const u8 *addr) 611590Srgrimes{ 621590Srgrimes return (0x01 & addr[0]); 631590Srgrimes} 641590Srgrimes 651590Srgrimes/** 661590Srgrimes * is_broadcast_ether_addr - Determine if the Ethernet address is broadcast 671590Srgrimes * @addr: Pointer to a six-byte array containing the Ethernet address 681590Srgrimes * 6974769Smikeh * Return true if the address is the broadcast address. 701590Srgrimes */ 7188150Smikehstatic inline bool is_broadcast_ether_addr(const u8 *addr) 721590Srgrimes{ 7374769Smikeh return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff; 741590Srgrimes} 751590Srgrimes 7677274Smikeh/** 7777274Smikeh * is_valid_ether_addr - Determine if the given Ethernet address is valid 781590Srgrimes * @addr: Pointer to a six-byte array containing the Ethernet address 791590Srgrimes * 801590Srgrimes * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not 811590Srgrimes * a multicast address, and is not FF:FF:FF:FF:FF:FF. 8274769Smikeh * 8377274Smikeh * Return true if the address is valid. 841590Srgrimes **/ 851590Srgrimesstatic inline bool is_valid_ether_addr(const u8 *addr) 861590Srgrimes{ 8774769Smikeh /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to 8877274Smikeh ** explicitly check for it here. */ 891590Srgrimes return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr); 901590Srgrimes} 911590Srgrimes 9274769Smikehstatic inline void ether_addr_copy(u8 *dst, const u8 *src) 9377274Smikeh{ 9474769Smikeh memcpy(dst, src, 6); 9574769Smikeh} 961590Srgrimes 971590Srgrimes#endif /* _LINUX_ETHERDEVICE */ 981590Srgrimes