[U-Boot] [PATCH 08/14] net: core: Add function to check/set MAC locality
Olliver Schinagl
oliver at schinagl.nl
Fri Nov 25 16:30:26 CET 2016
Universally administered and locally administered addresses are
distinguished by setting the second-least-significant bit of the first
octet of the address. Having a function to check and set this U/L bit
from a function makes it nice for boards that want to generate their own
mac address to ensure they are locally administered.
Signed-off-by: Olliver Schinagl <oliver at schinagl.nl>
---
include/net.h | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/include/net.h b/include/net.h
index 2534913..08f8af8 100644
--- a/include/net.h
+++ b/include/net.h
@@ -772,6 +772,28 @@ static inline int is_multicast_ethaddr(const u8 *addr)
return 0x01 & addr[0];
}
+/**
+ * is_local_ethaddr - Determine if the Ethernet address is a locally
+ * administered MAC address.
+ * @addr: Pointer to a six-byte array containing the Ethernet address
+ *
+ * Return true if the address is a locally administered address.
+ */
+static inline int is_local_ethaddr(const u8 *addr)
+{
+ return 0x02 & addr[0];
+}
+
+/**
+ * set_local_ethaddr - Make the supplied Ethernet address a locally
+ * administered one.
+ * @addr: Pointer to a six-byte array containing the Ethernet address
+ */
+static inline void set_local_ethaddr(u8 *addr)
+{
+ addr[0] |= 0x02; /* set local assignment bit (IEEE802) */
+}
+
/*
* is_broadcast_ethaddr - Determine if the Ethernet address is broadcast
* @addr: Pointer to a six-byte array containing the Ethernet address
@@ -816,7 +838,7 @@ static inline void net_random_ethaddr(uchar *addr)
addr[i] = rand_r(&seed);
addr[0] &= 0xfe; /* clear multicast bit */
- addr[0] |= 0x02; /* set local assignment bit (IEEE802) */
+ set_local_ethaddr(addr);
}
/* Convert an IP address to a string */
--
2.10.2
More information about the U-Boot
mailing list