611-v6.3-net-add-helper-eth_addr_add.patch 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. From 7390609b0121a1b982c5ecdfcd72dc328e5784ee Mon Sep 17 00:00:00 2001
  2. From: Michael Walle <[email protected]>
  3. Date: Mon, 6 Feb 2023 13:43:42 +0000
  4. Subject: [PATCH] net: add helper eth_addr_add()
  5. Add a helper to add an offset to a ethernet address. This comes in handy
  6. if you have a base ethernet address for multiple interfaces.
  7. Signed-off-by: Michael Walle <[email protected]>
  8. Reviewed-by: Andrew Lunn <[email protected]>
  9. Acked-by: Jakub Kicinski <[email protected]>
  10. Signed-off-by: Srinivas Kandagatla <[email protected]>
  11. Link: https://lore.kernel.org/r/[email protected]
  12. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  13. ---
  14. include/linux/etherdevice.h | 14 ++++++++++++++
  15. 1 file changed, 14 insertions(+)
  16. --- a/include/linux/etherdevice.h
  17. +++ b/include/linux/etherdevice.h
  18. @@ -478,6 +478,20 @@ static inline void eth_addr_inc(u8 *addr
  19. }
  20. /**
  21. + * eth_addr_add() - Add (or subtract) an offset to/from the given MAC address.
  22. + *
  23. + * @offset: Offset to add.
  24. + * @addr: Pointer to a six-byte array containing Ethernet address to increment.
  25. + */
  26. +static inline void eth_addr_add(u8 *addr, long offset)
  27. +{
  28. + u64 u = ether_addr_to_u64(addr);
  29. +
  30. + u += offset;
  31. + u64_to_ether_addr(u, addr);
  32. +}
  33. +
  34. +/**
  35. * is_etherdev_addr - Tell if given Ethernet address belongs to the device.
  36. * @dev: Pointer to a device structure
  37. * @addr: Pointer to a six-byte array containing the Ethernet address