Skip to contentSkip to conversation

Bluetooth: 6LoWPAN: Fix lladdr length

PATCH In review Luiz Augusto von Dentz 4 participants 9 messages Mar 12, 2017 – Mar 27, 2017 1 message not in the archive

Subsystems (7)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

v7 cover Bluetooth: 6LoWPAN: Fix lladdr length

From: Luiz Augusto von Dentz <[email protected]>

These patches fixes lladdr length to be 6 bytes long and not 8 which cause neighbor advertisement to be sent with wrong lladdr including FF:FE filler bytes for eui64.

Note: This does not fix some of the existing crashes which I hope to address in a different set.

v2: Make all code paths that generate a link-local from lladdr use the same code.
v3: Use lowpan_iphc_uncompress_eui48_lladdr to generate the remote ip address.
v4: Handle comments from Stefan Schmidt.
v5: Add patch to fix IID format for Bluetooth
v6: Fix addrconf_ifid_eui48 to follow IID format for Bluetooth
v7: Rework addrconf_ifid_6lowpan so it doesn't use addrconf_ifid_eui48

Alexander Aring (2):
6lowpan: iphc: override l2 packet information
ipv6: addrconf: fix 48 bit 6lowpan autoconfiguration

Luiz Augusto von Dentz (2):
6lowpan: Use netdev addr_len to determine lladdr len 6lowpan: Fix IID format for Bluetooth

Patrik Flykt (2):
bluetooth: Set 6 byte device addresses
6lowpan: Set MAC address length according to LOWPAN_LLTYPE

 include/net/6lowpan.h   |  15 ++++++
 net/6lowpan/core.c      |  11 +++-
 net/6lowpan/iphc.c      |  57 +++++++++++++++++----
 net/bluetooth/6lowpan.c | 130 ++++++++----------------------------------------
 net/ipv6/addrconf.c     |  23 ++++++---
 5 files changed, 109 insertions(+), 127 deletions(-)
Signature · 1 line
2.9.3

A message that is not in the archive (sent off-list or not yet received): 20170312081938.11700-1-luiz.dentz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH v7 1/6 bluetooth: Set 6 byte device addresses

From: Patrik Flykt <[email protected]>

Set BTLE MAC addresses that are 6 bytes long and not 8 bytes that are used in other places with 6lowpan.

---
 net/bluetooth/6lowpan.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
net/bluetooth/6lowpan.c +8 -11
index 1904a93..1456b01 100644
@@ -80,6 +80,8 @@ struct lowpan_btle_dev {
 	struct delayed_work notify_peers;
 };
 
+static void set_addr(u8 *eui, u8 *addr, u8 addr_type);
+
 static inline struct lowpan_btle_dev *
 lowpan_btle_dev(const struct net_device *netdev)
 {
@@ -272,9 +274,10 @@ static int give_skb_to_upper(struct sk_buff *skb, struct net_device *dev)
 static int iphc_decompress(struct sk_buff *skb, struct net_device *netdev,
 			   struct l2cap_chan *chan)
 {
-	const u8 *saddr, *daddr;
+	const u8 *saddr;
 	struct lowpan_btle_dev *dev;
 	struct lowpan_peer *peer;
+	unsigned char eui64_daddr[EUI64_ADDR_LEN];
 
 	dev = lowpan_btle_dev(netdev);
 
@@ -285,9 +288,9 @@ static int iphc_decompress(struct sk_buff *skb, struct net_device *netdev,
 		return -EINVAL;
 
 	saddr = peer->eui64_addr;
-	daddr = dev->netdev->dev_addr;
+	set_addr(&eui64_daddr[0], chan->src.b, chan->src_type);
 
-	return lowpan_header_decompress(skb, netdev, daddr, saddr);
+	return lowpan_header_decompress(skb, netdev, &eui64_daddr, saddr);
 }
 
 static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
@@ -681,13 +684,6 @@ static void set_addr(u8 *eui, u8 *addr, u8 addr_type)
 	BT_DBG("type %d addr %*phC", addr_type, 8, eui);
 }
 
-static void set_dev_addr(struct net_device *netdev, bdaddr_t *addr,
-		         u8 addr_type)
-{
-	netdev->addr_assign_type = NET_ADDR_PERM;
-	set_addr(netdev->dev_addr, addr->b, addr_type);
-}
-
 static void ifup(struct net_device *netdev)
 {
 	int err;
@@ -803,7 +799,8 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_btle_dev **dev)
 	if (!netdev)
 		return -ENOMEM;
 
-	set_dev_addr(netdev, &chan->src, chan->src_type);
+	netdev->addr_assign_type = NET_ADDR_PERM;
+	baswap((void *)netdev->dev_addr, &chan->src);
 
 	netdev->netdev_ops = &netdev_ops;
 	SET_NETDEV_DEV(netdev, &chan->conn->hcon->hdev->dev);
Signature · 1 line
2.9.3
#3 lore raw

PATCH v7 3/6 6lowpan: iphc: override l2 packet information

In reply to a message not in the archive

From: Alexander Aring <[email protected]>

The skb->pkt_type need to be set by L2, but on 6LoWPAN there exists L2 e.g. BTLE which doesn't has multicast addressing. If it's a multicast or not is detected by IPHC headers multicast bit. The IPv6 layer will evaluate this pkt_type, so we force set this type while uncompressing. Should be okay for 802.15.4 as well.

---
 net/6lowpan/iphc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
net/6lowpan/iphc.c +8 -0
index 79f1fa2..fb5f6fa 100644
@@ -666,6 +666,8 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
 
 	switch (iphc1 & (LOWPAN_IPHC_M | LOWPAN_IPHC_DAC)) {
 	case LOWPAN_IPHC_M | LOWPAN_IPHC_DAC:
+		skb->pkt_type = PACKET_BROADCAST;
+
 		spin_lock_bh(&lowpan_dev(dev)->ctx.lock);
 		ci = lowpan_iphc_ctx_get_by_id(dev, LOWPAN_IPHC_CID_DCI(cid));
 		if (!ci) {
@@ -681,11 +683,15 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
 		spin_unlock_bh(&lowpan_dev(dev)->ctx.lock);
 		break;
 	case LOWPAN_IPHC_M:
+		skb->pkt_type = PACKET_BROADCAST;
+
 		/* multicast */
 		err = lowpan_uncompress_multicast_daddr(skb, &hdr.daddr,
 							iphc1 & LOWPAN_IPHC_DAM_MASK);
 		break;
 	case LOWPAN_IPHC_DAC:
+		skb->pkt_type = PACKET_HOST;
+
 		spin_lock_bh(&lowpan_dev(dev)->ctx.lock);
 		ci = lowpan_iphc_ctx_get_by_id(dev, LOWPAN_IPHC_CID_DCI(cid));
 		if (!ci) {
@@ -701,6 +707,8 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
 		spin_unlock_bh(&lowpan_dev(dev)->ctx.lock);
 		break;
 	default:
+		skb->pkt_type = PACKET_HOST;
+
 		err = lowpan_iphc_uncompress_addr(skb, dev, &hdr.daddr,
 						  iphc1 & LOWPAN_IPHC_DAM_MASK,
 						  daddr);
Signature · 1 line
2.9.3
#4 lore raw

PATCH v7 5/6 6lowpan: Use netdev addr_len to determine lladdr len

In reply to a message not in the archive

From: Luiz Augusto von Dentz <[email protected]>

This allow technologies such as Bluetooth to use its native lladdr which is eui48 instead of eui64 which was expected by functions like lowpan_header_decompress and lowpan_header_compress.

---
 include/net/6lowpan.h   | 19 +++++++++++++++++++
 net/6lowpan/iphc.c      | 49 ++++++++++++++++++++++++++++++++++++++-----------
 net/bluetooth/6lowpan.c | 42 ++++++------------------------------------
 3 files changed, 63 insertions(+), 47 deletions(-)
include/net/6lowpan.h +19 -0
index 5ab4c99..c5792cb 100644
@@ -198,6 +198,25 @@ static inline void lowpan_iphc_uncompress_eui64_lladdr(struct in6_addr *ipaddr,
 	ipaddr->s6_addr[8] ^= 0x02;
 }
 
+static inline void lowpan_iphc_uncompress_eui48_lladdr(struct in6_addr *ipaddr,
+						       const void *lladdr)
+{
+	/* fe:80::XXXX:XXff:feXX:XXXX
+	 *        \_________________/
+	 *              hwaddr
+	 */
+	ipaddr->s6_addr[0] = 0xFE;
+	ipaddr->s6_addr[1] = 0x80;
+	memcpy(&ipaddr->s6_addr[8], lladdr, 3);
+	ipaddr->s6_addr[11] = 0xFF;
+	ipaddr->s6_addr[12] = 0xFE;
+	memcpy(&ipaddr->s6_addr[13], lladdr + 3, 3);
+	/* second bit-flip (Universe/Local)
+	 * is done according RFC2464
+	 */
+	ipaddr->s6_addr[8] ^= 0x02;
+}
+
 #ifdef DEBUG
 /* print data in line */
 static inline void raw_dump_inline(const char *caller, char *msg,
net/6lowpan/iphc.c +38 -11

88 lines not on this page · raw message

net/bluetooth/6lowpan.c +6 -36

86 lines not on this page · raw message

Signature · 1 line
2.9.3
#5 lore raw
In reply to a message not in the archive

From: Luiz Augusto von Dentz <[email protected]>
Date: Sun, 12 Mar 2017 10:19:32 +0200

Quoted 9 lines

From: Luiz Augusto von Dentz <[email protected]>

These patches fixes lladdr length to be 6 bytes long and not 8 which cause neighbor advertisement to be sent with wrong lladdr including FF:FE filler bytes for eui64.

Note: This does not fix some of the existing crashes which I hope to address in a different set.

Quoted 7 lines

v2: Make all code paths that generate a link-local from lladdr use the same code.
v3: Use lowpan_iphc_uncompress_eui48_lladdr to generate the remote ip address.
v4: Handle comments from Stefan Schmidt.
v5: Add patch to fix IID format for Bluetooth
v6: Fix addrconf_ifid_eui48 to follow IID format for Bluetooth
v7: Rework addrconf_ifid_6lowpan so it doesn't use addrconf_ifid_eui48

Since this is predominantly bluetooth/6lowpan stuff, please merge this via the bluetooth tree.

Thanks!

#6 lore raw
In reply to a message not in the archive

Hi Luiz,

Quoted 27 lines

These patches fixes lladdr length to be 6 bytes long and not 8 which cause neighbor advertisement to be sent with wrong lladdr including FF:FE filler bytes for eui64.

Note: This does not fix some of the existing crashes which I hope to address in a different set.

v2: Make all code paths that generate a link-local from lladdr use the same code.
v3: Use lowpan_iphc_uncompress_eui48_lladdr to generate the remote ip address.
v4: Handle comments from Stefan Schmidt.
v5: Add patch to fix IID format for Bluetooth
v6: Fix addrconf_ifid_eui48 to follow IID format for Bluetooth
v7: Rework addrconf_ifid_6lowpan so it doesn't use addrconf_ifid_eui48

Alexander Aring (2):
6lowpan: iphc: override l2 packet information
ipv6: addrconf: fix 48 bit 6lowpan autoconfiguration

Luiz Augusto von Dentz (2):
6lowpan: Use netdev addr_len to determine lladdr len 6lowpan: Fix IID format for Bluetooth

Patrik Flykt (2):
bluetooth: Set 6 byte device addresses
6lowpan: Set MAC address length according to LOWPAN_LLTYPE

Quoted 6 lines
include/net/6lowpan.h   |  15 ++++++
net/6lowpan/core.c      |  11 +++-
net/6lowpan/iphc.c      |  57 +++++++++++++++++----
net/bluetooth/6lowpan.c | 130 ++++++++----------------------------------------
net/ipv6/addrconf.c     |  23 ++++++---
5 files changed, 109 insertions(+), 127 deletions(-)

all 6 patches have been applied to bluetooth-next tree.

Regards

Marcel

author maintainer
#7 lore raw

PATCH v7 2/6 6lowpan: Set MAC address length according to LOWPAN_LLTYPE

In reply to Luiz Augusto von Dentz

From: Patrik Flykt <[email protected]>

Set MAC address length according to the 6LoWPAN link layer in use. Bluetooth Low Energy uses 48 bit addressing while IEEE802.15.4 uses 64 bits.

---
 net/6lowpan/core.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
net/6lowpan/core.c +10 -1
index 5945f7e..5f9909a 100644
@@ -23,7 +23,16 @@ int lowpan_register_netdevice(struct net_device *dev,
 {
 	int i, ret;
 
-	dev->addr_len = EUI64_ADDR_LEN;
+	switch (lltype) {
+	case LOWPAN_LLTYPE_IEEE802154:
+		dev->addr_len = EUI64_ADDR_LEN;
+		break;
+
+	case LOWPAN_LLTYPE_BTLE:
+		dev->addr_len = ETH_ALEN;
+		break;
+	}
+
 	dev->type = ARPHRD_6LOWPAN;
 	dev->mtu = IPV6_MIN_MTU;
 	dev->priv_flags |= IFF_NO_QUEUE;
Signature · 1 line
2.9.3
author maintainer
#8 lore raw

PATCH v7 4/6 ipv6: addrconf: fix 48 bit 6lowpan autoconfiguration

In reply to Luiz Augusto von Dentz

From: Alexander Aring <[email protected]>

This patch adds support for 48 bit 6LoWPAN address length autoconfiguration which is the case for BTLE 6LoWPAN.

---
 net/ipv6/addrconf.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
net/ipv6/addrconf.c +12 -5
index 3a2025f..7756640 100644
@@ -2052,12 +2052,19 @@ static void addrconf_leave_anycast(struct inet6_ifaddr *ifp)
 	__ipv6_dev_ac_dec(ifp->idev, &addr);
 }
 
-static int addrconf_ifid_eui64(u8 *eui, struct net_device *dev)
+static int addrconf_ifid_6lowpan(u8 *eui, struct net_device *dev)
 {
-	if (dev->addr_len != EUI64_ADDR_LEN)
+	switch (dev->addr_len) {
+	case ETH_ALEN:
+		return addrconf_ifid_eui48(eui, dev);
+	case EUI64_ADDR_LEN:
+		memcpy(eui, dev->dev_addr, EUI64_ADDR_LEN);
+		eui[0] ^= 2;
+		break;
+	default:
 		return -1;
-	memcpy(eui, dev->dev_addr, EUI64_ADDR_LEN);
-	eui[0] ^= 2;
+	}
+
 	return 0;
 }
 
@@ -2149,7 +2156,7 @@ static int ipv6_generate_eui64(u8 *eui, struct net_device *dev)
 	case ARPHRD_TUNNEL:
 		return addrconf_ifid_gre(eui, dev);
 	case ARPHRD_6LOWPAN:
-		return addrconf_ifid_eui64(eui, dev);
+		return addrconf_ifid_6lowpan(eui, dev);
 	case ARPHRD_IEEE1394:
 		return addrconf_ifid_ieee1394(eui, dev);
 	case ARPHRD_TUNNEL6:
Signature · 1 line
2.9.3
author maintainer
#9 lore raw

PATCH v7 6/6 6lowpan: Fix IID format for Bluetooth

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

According to RFC 7668 U/L bit shall not be used:

https://wiki.tools.ietf.org/html/rfc7668#section-3.2.2 [Page 10]:

In the figure, letter 'b' represents a bit from the Bluetooth device address, copied as is without any changes on any bit. This means that no bit in the IID indicates whether the underlying Bluetooth device address is public or random.

   |0              1|1              3|3              4|4              6|
   |0              5|6              1|2              7|8              3|
   +----------------+----------------+----------------+----------------+
   |bbbbbbbbbbbbbbbb|bbbbbbbb11111111|11111110bbbbbbbb|bbbbbbbbbbbbbbbb|
   +----------------+----------------+----------------+----------------+

Because of this the code cannot figure out the address type from the IP address anymore thus it makes no sense to use peer_lookup_ba as it needs the peer address type.

---
 include/net/6lowpan.h   |  4 ---
 net/bluetooth/6lowpan.c | 79 ++++++++-----------------------------------------
 net/ipv6/addrconf.c     |  6 +++-
 3 files changed, 17 insertions(+), 72 deletions(-)
include/net/6lowpan.h +0 -4
index c5792cb..a713780 100644
@@ -211,10 +211,6 @@ static inline void lowpan_iphc_uncompress_eui48_lladdr(struct in6_addr *ipaddr,
 	ipaddr->s6_addr[11] = 0xFF;
 	ipaddr->s6_addr[12] = 0xFE;
 	memcpy(&ipaddr->s6_addr[13], lladdr + 3, 3);
-	/* second bit-flip (Universe/Local)
-	 * is done according RFC2464
-	 */
-	ipaddr->s6_addr[8] ^= 0x02;
 }
 
 #ifdef DEBUG
net/bluetooth/6lowpan.c +12 -67

116 lines not on this page · raw message

net/ipv6/addrconf.c +5 -1
index 7756640..1f1aaaf6 100644
@@ -2056,7 +2056,11 @@ static int addrconf_ifid_6lowpan(u8 *eui, struct net_device *dev)
 {
 	switch (dev->addr_len) {
 	case ETH_ALEN:
-		return addrconf_ifid_eui48(eui, dev);
+		memcpy(eui, dev->dev_addr, 3);
+		eui[3] = 0xFF;
+		eui[4] = 0xFE;
+		memcpy(eui + 5, dev->dev_addr + 3, 3);
+		break;
 	case EUI64_ADDR_LEN:
 		memcpy(eui, dev->dev_addr, EUI64_ADDR_LEN);
 		eui[0] ^= 2;
Signature · 1 line
2.9.3