[PATCH 1/4] net: add ethaddr sequence handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of storing every MAC address in full, boards may elect
to store a base address and increment it N times. Add a helper
to iterate over such an Ethernet address sequence. Example usage:

  const u8 *eth_addr;
  u8 eth_base[ETH_ALEN] = "\x00\x01\x02\x03\x04\x05";
  int i = 0, eth_count = 4;

  for_each_seq_ethaddr(eth_addr, eth_base, &eth_count)
          eth_register_ethaddr(i++, eth_addr);

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 include/net.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/net.h b/include/net.h
index a04ed5b0ab92..1b6995b50043 100644
--- a/include/net.h
+++ b/include/net.h
@@ -516,6 +516,18 @@ static inline void eth_addr_add(u8 *addr, long offset)
 	u64_to_ether_addr(u, addr);
 }
 
+#define for_each_seq_ethaddr(eth_addr, eth_base, eth_count) \
+	for (eth_addr = *eth_count ? eth_base : NULL; eth_addr; eth_addr = eth_addr_seq_next(eth_base, eth_count))
+
+static inline const u8 *eth_addr_seq_next(u8 eth_base[6], unsigned *eth_count)
+{
+	if (--(*eth_count) <= 0)
+		return NULL;
+
+	eth_addr_inc(eth_base);
+	return eth_base;
+}
+
 typedef void rx_handler_f(void *ctx, char *packet, unsigned int len);
 
 struct eth_device *eth_get_byname(const char *name);
-- 
2.39.5





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux