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 <oli...@schinagl.nl>
---
 include/net.h | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/include/net.h b/include/net.h
index b4af8eaae4..b1d6f05a76 100644
--- a/include/net.h
+++ b/include/net.h
@@ -779,6 +779,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
@@ -823,7 +845,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.11.0

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to