Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: add helper eth_addr_add()

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>

authored by

Michael Walle and committed by
Greg Kroah-Hartman
7390609b 2e8dc541

+14
+14
include/linux/etherdevice.h
··· 508 508 } 509 509 510 510 /** 511 + * eth_addr_add() - Add (or subtract) an offset to/from the given MAC address. 512 + * 513 + * @offset: Offset to add. 514 + * @addr: Pointer to a six-byte array containing Ethernet address to increment. 515 + */ 516 + static inline void eth_addr_add(u8 *addr, long offset) 517 + { 518 + u64 u = ether_addr_to_u64(addr); 519 + 520 + u += offset; 521 + u64_to_ether_addr(u, addr); 522 + } 523 + 524 + /** 511 525 * is_etherdev_addr - Tell if given Ethernet address belongs to the device. 512 526 * @dev: Pointer to a device structure 513 527 * @addr: Pointer to a six-byte array containing the Ethernet address