All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH,RFC bluetooth-next 1/2] ieee802154: Fix generation of random EUI-64 addresses.
@ 2015-05-28 12:38 Lennert Buytenhek
  2015-05-28 13:17 ` Alexander Aring
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Lennert Buytenhek @ 2015-05-28 12:38 UTC (permalink / raw)
  To: linux-wpan

Currently, ieee802154_random_extended_addr() has a 50% chance of
generating a group (multicast) address, while this function is used
for generating station addresses (which can't be group addresses)
for interfaces that don't have a hardware-provided address.

Also, in case get_random_bytes() generates the EUI-64 address
00:00:00:00:00:00:00:00 (extremely unlikely), which is an invalid
address, ieee802154_random_extended_addr() reacts by changing it
to 01:00:00:00:00:00:00:00, which is an invalid station address as
well, as it is a group address.

This patch changes the address generation procedure to grab eight
random bytes, treat that as an EUI-64, and then clear the Group
address bit and set the Locally Administered bit, which is in
line with how eth_random_addr() generates random EUI-48s.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
---
 include/linux/ieee802154.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/ieee802154.h b/include/linux/ieee802154.h
index 8872ca1..552210d 100644
--- a/include/linux/ieee802154.h
+++ b/include/linux/ieee802154.h
@@ -244,9 +244,9 @@ static inline void ieee802154_random_extended_addr(__le64 *addr)
 {
 	get_random_bytes(addr, IEEE802154_EXTENDED_ADDR_LEN);
 
-	/* toggle some bit if we hit an invalid extended addr */
-	if (!ieee802154_is_valid_extended_addr(*addr))
-		((u8 *)addr)[IEEE802154_EXTENDED_ADDR_LEN - 1] ^= 0x01;
+	/* clear the group bit, and set the locally administered bit */
+	((u8 *)addr)[IEEE802154_EXTENDED_ADDR_LEN - 1] &= ~0x01;
+	((u8 *)addr)[IEEE802154_EXTENDED_ADDR_LEN - 1] |= 0x02;
 }
 
 #endif /* LINUX_IEEE802154_H */
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-05-29  8:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-28 12:38 [PATCH,RFC bluetooth-next 1/2] ieee802154: Fix generation of random EUI-64 addresses Lennert Buytenhek
2015-05-28 13:17 ` Alexander Aring
2015-05-28 13:39   ` Lennert Buytenhek
2015-05-28 14:12     ` Lennert Buytenhek
2015-05-28 14:42     ` Alexander Aring
2015-05-28 14:53       ` Alexander Aring
2015-05-29  3:22         ` Lennert Buytenhek
2015-05-29  3:19       ` Lennert Buytenhek
2015-05-29  8:21         ` Stefan Schmidt
2015-05-29  8:27           ` Lennert Buytenhek
2015-05-28 15:13 ` Phoebe Buckheister
2015-05-28 15:23   ` Alexander Aring
2015-05-28 16:11 ` Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.