Skip to content

Commit

Permalink
net: add helper eth_hw_addr_crc
Browse files Browse the repository at this point in the history
Several drivers use the same code as basis for filter hashes. Therefore
let's factor it out to a helper. This way drivers don't have to access
struct netdev_hw_addr internals.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Heiner Kallweit authored and David S. Miller committed May 4, 2020
1 parent e90c9fc commit b86cd70
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/linux/etherdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <linux/if_ether.h>
#include <linux/netdevice.h>
#include <linux/random.h>
#include <linux/crc32.h>
#include <asm/unaligned.h>
#include <asm/bitsperlong.h>

Expand Down Expand Up @@ -265,6 +266,17 @@ static inline void eth_hw_addr_random(struct net_device *dev)
eth_random_addr(dev->dev_addr);
}

/**
* eth_hw_addr_crc - Calculate CRC from netdev_hw_addr
* @ha: pointer to hardware address
*
* Calculate CRC from a hardware address as basis for filter hashes.
*/
static inline u32 eth_hw_addr_crc(struct netdev_hw_addr *ha)
{
return ether_crc(ETH_ALEN, ha->addr);
}

/**
* ether_addr_copy - Copy an Ethernet address
* @dst: Pointer to a six-byte array Ethernet address destination
Expand Down

0 comments on commit b86cd70

Please sign in to comment.