]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: add helper eth_addr_add()
authorMichael Walle <michael@walle.cc>
Mon, 6 Feb 2023 13:43:42 +0000 (13:43 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 6 Feb 2023 18:06:58 +0000 (19:06 +0100)
Add a helper to add an offset to a ethernet address. This comes in handy
if you have a base ethernet address for multiple interfaces.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230206134356.839737-9-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/etherdevice.h

index a541f0c4f146c85724b73d2fb38b042bdc9d2154..224645f17c333b2311573197a28b41701eb35f92 100644 (file)
@@ -507,6 +507,20 @@ static inline void eth_addr_inc(u8 *addr)
        u64_to_ether_addr(u, addr);
 }
 
+/**
+ * eth_addr_add() - Add (or subtract) an offset to/from the given MAC address.
+ *
+ * @offset: Offset to add.
+ * @addr: Pointer to a six-byte array containing Ethernet address to increment.
+ */
+static inline void eth_addr_add(u8 *addr, long offset)
+{
+       u64 u = ether_addr_to_u64(addr);
+
+       u += offset;
+       u64_to_ether_addr(u, addr);
+}
+
 /**
  * is_etherdev_addr - Tell if given Ethernet address belongs to the device.
  * @dev: Pointer to a device structure