History

net: add helper eth_hw_addr_crc

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.

Heiner Kallweit committed 6 years ago

Commit b86cd701 parent e90c9fc1 file · +12 −0Browse files

Showing the changes to include/linux (1 of 1 file). Show all

Unified · Split

include/linux/etherdevice.h+12−0
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 #include <linux/if_ether.h>
2121 #include <linux/netdevice.h>
2222 #include <linux/random.h>
23+#include <linux/crc32.h>
2324 #include <asm/unaligned.h>
2425 #include <asm/bitsperlong.h>
2526
@@ -265,6 +266,17 @@ static inline void eth_hw_addr_random(struct net_device *dev) · 239 unmodified lines
265266 eth_random_addr(dev->dev_addr);
266267 }
267268
269+/**
270+ * eth_hw_addr_crc - Calculate CRC from netdev_hw_addr
271+ * @ha: pointer to hardware address
272+ *
273+ * Calculate CRC from a hardware address as basis for filter hashes.
274+ */
275+static inline u32 eth_hw_addr_crc(struct netdev_hw_addr *ha)
276+{
277+ return ether_crc(ETH_ALEN, ha->addr);
278+}
279+
268280 /**
269281 * ether_addr_copy - Copy an Ethernet address
270282 * @dst: Pointer to a six-byte array Ethernet address destination