2017-02-17 15:49:58

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v3 0/5] 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.

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

Luiz Augusto von Dentz (1):
6lowpan: Use netdev addr_len to determine lladdr len

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

include/net/6lowpan.h | 19 +++++++++++++++++
net/6lowpan/core.c | 11 +++++++++-
net/6lowpan/iphc.c | 57 ++++++++++++++++++++++++++++++++++++++-----------
net/bluetooth/6lowpan.c | 52 +++++++++++---------------------------------
net/ipv6/addrconf.c | 17 ++++++++++-----
5 files changed, 99 insertions(+), 57 deletions(-)

--
2.9.3



2017-02-21 08:49:05

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH v3 4/5] ipv6: addrconf: fix 48 bit 6lowpan autoconfiguration

Hi Stefan,

On Tue, Feb 21, 2017 at 12:10 AM, Stefan Schmidt <[email protected]> wrote:
> Hello.
>
> [Added netdev in cc as it touches ipv6/addrconf]
>
> 6LoWPAN handling changes only so an ACK should be ok and we could carry it
> through the bluetooth tree after the respin (see below).
>
> David, is that ok with you?
>
>
> On 02/17/2017 04:50 PM, Luiz Augusto von Dentz wrote:
>>
>> From: Alexander Aring <[email protected]>
>>
>> This patch adds support for 48 bit 6LoWPAN address length
>> autoconfiguration which is the case for BTLE 6LoWPAN.
>>
>> Signed-off-by: Alexander Aring <[email protected]>
>> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
>> ---
>> net/ipv6/addrconf.c | 17 ++++++++++++-----
>> 1 file changed, 12 insertions(+), 5 deletions(-)
>>
>> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
>> index ac9bd56..dede33f 100644
>> --- a/net/ipv6/addrconf.c
>> +++ b/net/ipv6/addrconf.c
>> @@ -2050,12 +2050,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;
>> }
>>
>> @@ -2146,7 +2153,7 @@ static int ipv6_generate_eui64(u8 *eui, struct
>> net_device *dev)
>> case ARPHRD_IPGRE:
>> 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:
>>
>
> Against which tree did you make this patch? Seems it needs a rebase.
>
> Applying it against bluetooth-next master branch:
>
> Applying: ipv6: addrconf: fix 48 bit 6lowpan autoconfiguration
> error: patch failed: net/ipv6/addrconf.c:2146
> error: net/ipv6/addrconf.c: patch does not apply
> Patch failed at 0001 ipv6: addrconf: fix 48 bit 6lowpan autoconfiguration

It should be fine in v4:

Applying: ipv6: addrconf: fix 48 bit 6lowpan autoconfiguration
Using index info to reconstruct a base tree...
M net/ipv6/addrconf.c
Falling back to patching base and 3-way merge...
Auto-merging net/ipv6/addrconf.c

--
Luiz Augusto von Dentz

2017-02-20 22:15:54

by Stefan Schmidt

[permalink] [raw]
Subject: Re: [PATCH v3 5/5] 6lowpan: Use netdev addr_len to determine lladdr len

Hello.

On 02/17/2017 04:50 PM, Luiz Augusto von Dentz wrote:
> 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.
>
> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
> ---
> include/net/6lowpan.h | 19 +++++++++++++++++++
> net/6lowpan/iphc.c | 49 +++++++++++++++++++++++++++++++++++++------------
> net/bluetooth/6lowpan.c | 42 ++++++------------------------------------
> 3 files changed, 62 insertions(+), 48 deletions(-)
>
> diff --git a/include/net/6lowpan.h b/include/net/6lowpan.h
> index 5ab4c99..c5792cb 100644
> --- a/include/net/6lowpan.h
> +++ b/include/net/6lowpan.h
> @@ -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,
> diff --git a/net/6lowpan/iphc.c b/net/6lowpan/iphc.c
> index fb5f6fa..ddbeeb7 100644
> --- a/net/6lowpan/iphc.c
> +++ b/net/6lowpan/iphc.c
> @@ -278,6 +278,22 @@ lowpan_iphc_ctx_get_by_mcast_addr(const struct net_device *dev,
> return ret;
> }
>
> +static void lowpan_iphc_uncompress_lladdr(const struct net_device *dev,
> + struct in6_addr *ipaddr,
> + const void *lladdr)
> +{
> + switch (dev->addr_len) {
> + case ETH_ALEN:
> + lowpan_iphc_uncompress_eui48_lladdr(ipaddr, lladdr);
> + break;
> + case EUI64_ADDR_LEN:
> + lowpan_iphc_uncompress_eui64_lladdr(ipaddr, lladdr);
> + break;
> + default:
> + WARN_ON_ONCE(1);
> + }
> +}
> +
> /* Uncompress address function for source and
> * destination address(non-multicast).
> *
> @@ -320,8 +336,7 @@ static int lowpan_iphc_uncompress_addr(struct sk_buff *skb,
> lowpan_iphc_uncompress_802154_lladdr(ipaddr, lladdr);
> break;
> default:
> - lowpan_iphc_uncompress_eui64_lladdr(ipaddr, lladdr);
> - break;
> + lowpan_iphc_uncompress_lladdr(dev, ipaddr, lladdr);

You removed the break statement here while keeping it in the next hunk.
It does not make a difference in he end but for consistency you should
either keep the break statements or remove all similar ones (in the
default cases)

> }
> break;
> default:
> @@ -381,7 +396,7 @@ static int lowpan_iphc_uncompress_ctx_addr(struct sk_buff *skb,
> lowpan_iphc_uncompress_802154_lladdr(ipaddr, lladdr);
> break;
> default:
> - lowpan_iphc_uncompress_eui64_lladdr(ipaddr, lladdr);
> + lowpan_iphc_uncompress_lladdr(dev, ipaddr, lladdr);
> break;
> }
> ipv6_addr_prefix_copy(ipaddr, &ctx->pfx, ctx->plen);
> @@ -810,6 +825,21 @@ lowpan_iphc_compress_ctx_802154_lladdr(const struct in6_addr *ipaddr,
> return lladdr_compress;
> }
>
> +static bool lowpan_iphc_addr_equal(const struct net_device *dev,
> + const struct lowpan_iphc_ctx *ctx,
> + const struct in6_addr *ipaddr,
> + const void *lladdr)
> +{
> + struct in6_addr tmp = {};
> +
> + lowpan_iphc_uncompress_lladdr(dev, &tmp, lladdr);
> +
> + if (ctx)
> + ipv6_addr_prefix_copy(&tmp, &ctx->pfx, ctx->plen);
> +
> + return ipv6_addr_equal(&tmp, ipaddr);
> +}
> +
> static u8 lowpan_compress_ctx_addr(u8 **hc_ptr, const struct net_device *dev,
> const struct in6_addr *ipaddr,
> const struct lowpan_iphc_ctx *ctx,
> @@ -827,13 +857,7 @@ static u8 lowpan_compress_ctx_addr(u8 **hc_ptr, const struct net_device *dev,
> }
> break;
> default:
> - /* check for SAM/DAM = 11 */
> - memcpy(&tmp.s6_addr[8], lladdr, EUI64_ADDR_LEN);
> - /* second bit-flip (Universe/Local) is done according RFC2464 */
> - tmp.s6_addr[8] ^= 0x02;
> - /* context information are always used */
> - ipv6_addr_prefix_copy(&tmp, &ctx->pfx, ctx->plen);
> - if (ipv6_addr_equal(&tmp, ipaddr)) {
> + if (lowpan_iphc_addr_equal(dev, ctx, ipaddr, lladdr)) {
> dam = LOWPAN_IPHC_DAM_11;
> goto out;
> }
> @@ -929,11 +953,12 @@ static u8 lowpan_compress_addr_64(u8 **hc_ptr, const struct net_device *dev,
> }
> break;
> default:
> - if (is_addr_mac_addr_based(ipaddr, lladdr)) {
> - dam = LOWPAN_IPHC_DAM_11; /* 0-bits */
> + if (lowpan_iphc_addr_equal(dev, NULL, ipaddr, lladdr)) {
> + dam = LOWPAN_IPHC_DAM_11;
> pr_debug("address compression 0 bits\n");
> goto out;
> }
> +
> break;
> }
>
> diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
> index 1456b01..0b68cfc 100644
> --- a/net/bluetooth/6lowpan.c
> +++ b/net/bluetooth/6lowpan.c
> @@ -64,7 +64,7 @@ struct lowpan_peer {
> struct l2cap_chan *chan;
>
> /* peer addresses in various formats */
> - unsigned char eui64_addr[EUI64_ADDR_LEN];
> + unsigned char lladdr[ETH_ALEN];
> struct in6_addr peer_addr;
> };
>
> @@ -80,8 +80,6 @@ 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)
> {
> @@ -277,7 +275,6 @@ static int iphc_decompress(struct sk_buff *skb, struct net_device *netdev,
> const u8 *saddr;
> struct lowpan_btle_dev *dev;
> struct lowpan_peer *peer;
> - unsigned char eui64_daddr[EUI64_ADDR_LEN];
>
> dev = lowpan_btle_dev(netdev);
>
> @@ -287,10 +284,9 @@ static int iphc_decompress(struct sk_buff *skb, struct net_device *netdev,
> if (!peer)
> return -EINVAL;
>
> - saddr = peer->eui64_addr;
> - set_addr(&eui64_daddr[0], chan->src.b, chan->src_type);
> + saddr = peer->lladdr;
>
> - return lowpan_header_decompress(skb, netdev, &eui64_daddr, saddr);
> + return lowpan_header_decompress(skb, netdev, netdev->dev_addr, saddr);
> }
>
> static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
> @@ -477,7 +473,7 @@ static int setup_header(struct sk_buff *skb, struct net_device *netdev,
> }
> }
>
> - daddr = peer->eui64_addr;
> + daddr = peer->lladdr;
> *peer_addr = addr;
> *peer_addr_type = addr_type;
> lowpan_cb(skb)->chan = peer->chan;
> @@ -663,27 +659,6 @@ static struct device_type bt_type = {
> .name = "bluetooth",
> };
>
> -static void set_addr(u8 *eui, u8 *addr, u8 addr_type)
> -{
> - /* addr is the BT address in little-endian format */
> - eui[0] = addr[5];
> - eui[1] = addr[4];
> - eui[2] = addr[3];
> - eui[3] = 0xFF;
> - eui[4] = 0xFE;
> - eui[5] = addr[2];
> - eui[6] = addr[1];
> - eui[7] = addr[0];
> -
> - /* Universal/local bit set, BT 6lowpan draft ch. 3.2.1 */
> - if (addr_type == BDADDR_LE_PUBLIC)
> - eui[0] &= ~0x02;
> - else
> - eui[0] |= 0x02;
> -
> - BT_DBG("type %d addr %*phC", addr_type, 8, eui);
> -}
> -
> static void ifup(struct net_device *netdev)
> {
> int err;
> @@ -762,14 +737,9 @@ static struct l2cap_chan *add_peer_chan(struct l2cap_chan *chan,
> peer->chan = chan;
> memset(&peer->peer_addr, 0, sizeof(struct in6_addr));
>
> - /* RFC 2464 ch. 5 */
> - peer->peer_addr.s6_addr[0] = 0xFE;
> - peer->peer_addr.s6_addr[1] = 0x80;
> - set_addr((u8 *)&peer->peer_addr.s6_addr + 8, chan->dst.b,
> - chan->dst_type);
> + baswap((void *)peer->lladdr, &chan->dst);
>
> - memcpy(&peer->eui64_addr, (u8 *)&peer->peer_addr.s6_addr + 8,
> - EUI64_ADDR_LEN);
> + lowpan_iphc_uncompress_eui48_lladdr(&peer->peer_addr, peer->lladdr);
>
> /* IPv6 address needs to have the U/L bit set properly so toggle
> * it back here.
>

With the nitpicks from above:

Reviewed-by: Stefan Schmidt <[email protected]>

regards
Stefan Schmidt

2017-02-20 22:10:14

by Stefan Schmidt

[permalink] [raw]
Subject: Re: [PATCH v3 4/5] ipv6: addrconf: fix 48 bit 6lowpan autoconfiguration

Hello.

[Added netdev in cc as it touches ipv6/addrconf]

6LoWPAN handling changes only so an ACK should be ok and we could carry
it through the bluetooth tree after the respin (see below).

David, is that ok with you?

On 02/17/2017 04:50 PM, Luiz Augusto von Dentz wrote:
> From: Alexander Aring <[email protected]>
>
> This patch adds support for 48 bit 6LoWPAN address length
> autoconfiguration which is the case for BTLE 6LoWPAN.
>
> Signed-off-by: Alexander Aring <[email protected]>
> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
> ---
> net/ipv6/addrconf.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index ac9bd56..dede33f 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ -2050,12 +2050,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;
> }
>
> @@ -2146,7 +2153,7 @@ static int ipv6_generate_eui64(u8 *eui, struct net_device *dev)
> case ARPHRD_IPGRE:
> 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:
>

Against which tree did you make this patch? Seems it needs a rebase.

Applying it against bluetooth-next master branch:

Applying: ipv6: addrconf: fix 48 bit 6lowpan autoconfiguration
error: patch failed: net/ipv6/addrconf.c:2146
error: net/ipv6/addrconf.c: patch does not apply
Patch failed at 0001 ipv6: addrconf: fix 48 bit 6lowpan autoconfiguration

regards
Stefan Schmidt

2017-02-20 22:03:34

by Stefan Schmidt

[permalink] [raw]
Subject: Re: [PATCH v3 3/5] 6lowpan: iphc: override l2 packet information

Hello.

On 02/17/2017 04:50 PM, Luiz Augusto von Dentz wrote:
> 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.
>
> Signed-off-by: Alexander Aring <[email protected]>
> ---
> net/6lowpan/iphc.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/net/6lowpan/iphc.c b/net/6lowpan/iphc.c
> index 79f1fa2..fb5f6fa 100644
> --- a/net/6lowpan/iphc.c
> +++ b/net/6lowpan/iphc.c
> @@ -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);
>


Reviewed-by: Stefan Schmidt <[email protected]>

regards
Stefan Schmidt

2017-02-20 21:56:28

by Stefan Schmidt

[permalink] [raw]
Subject: Re: [PATCH v3 1/5] bluetooth: Set 6 byte device addresses

Hello.

On 02/17/2017 04:49 PM, Luiz Augusto von Dentz wrote:
> 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.
>
> Signed-off-by: Patrik Flykt <[email protected]>
> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
> ---
> net/bluetooth/6lowpan.c | 19 ++++++++-----------
> 1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
> index 1904a93..1456b01 100644
> --- a/net/bluetooth/6lowpan.c
> +++ b/net/bluetooth/6lowpan.c
> @@ -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);
>

Reviewed-by: Stefan Schmidt <[email protected]>

regards
Stefan Schmidt

2017-02-17 15:50:03

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v3 5/5] 6lowpan: Use netdev addr_len to determine lladdr len

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.

Signed-off-by: Luiz Augusto von Dentz <[email protected]>
---
include/net/6lowpan.h | 19 +++++++++++++++++++
net/6lowpan/iphc.c | 49 +++++++++++++++++++++++++++++++++++++------------
net/bluetooth/6lowpan.c | 42 ++++++------------------------------------
3 files changed, 62 insertions(+), 48 deletions(-)

diff --git a/include/net/6lowpan.h b/include/net/6lowpan.h
index 5ab4c99..c5792cb 100644
--- a/include/net/6lowpan.h
+++ b/include/net/6lowpan.h
@@ -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,
diff --git a/net/6lowpan/iphc.c b/net/6lowpan/iphc.c
index fb5f6fa..ddbeeb7 100644
--- a/net/6lowpan/iphc.c
+++ b/net/6lowpan/iphc.c
@@ -278,6 +278,22 @@ lowpan_iphc_ctx_get_by_mcast_addr(const struct net_device *dev,
return ret;
}

+static void lowpan_iphc_uncompress_lladdr(const struct net_device *dev,
+ struct in6_addr *ipaddr,
+ const void *lladdr)
+{
+ switch (dev->addr_len) {
+ case ETH_ALEN:
+ lowpan_iphc_uncompress_eui48_lladdr(ipaddr, lladdr);
+ break;
+ case EUI64_ADDR_LEN:
+ lowpan_iphc_uncompress_eui64_lladdr(ipaddr, lladdr);
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ }
+}
+
/* Uncompress address function for source and
* destination address(non-multicast).
*
@@ -320,8 +336,7 @@ static int lowpan_iphc_uncompress_addr(struct sk_buff *skb,
lowpan_iphc_uncompress_802154_lladdr(ipaddr, lladdr);
break;
default:
- lowpan_iphc_uncompress_eui64_lladdr(ipaddr, lladdr);
- break;
+ lowpan_iphc_uncompress_lladdr(dev, ipaddr, lladdr);
}
break;
default:
@@ -381,7 +396,7 @@ static int lowpan_iphc_uncompress_ctx_addr(struct sk_buff *skb,
lowpan_iphc_uncompress_802154_lladdr(ipaddr, lladdr);
break;
default:
- lowpan_iphc_uncompress_eui64_lladdr(ipaddr, lladdr);
+ lowpan_iphc_uncompress_lladdr(dev, ipaddr, lladdr);
break;
}
ipv6_addr_prefix_copy(ipaddr, &ctx->pfx, ctx->plen);
@@ -810,6 +825,21 @@ lowpan_iphc_compress_ctx_802154_lladdr(const struct in6_addr *ipaddr,
return lladdr_compress;
}

+static bool lowpan_iphc_addr_equal(const struct net_device *dev,
+ const struct lowpan_iphc_ctx *ctx,
+ const struct in6_addr *ipaddr,
+ const void *lladdr)
+{
+ struct in6_addr tmp = {};
+
+ lowpan_iphc_uncompress_lladdr(dev, &tmp, lladdr);
+
+ if (ctx)
+ ipv6_addr_prefix_copy(&tmp, &ctx->pfx, ctx->plen);
+
+ return ipv6_addr_equal(&tmp, ipaddr);
+}
+
static u8 lowpan_compress_ctx_addr(u8 **hc_ptr, const struct net_device *dev,
const struct in6_addr *ipaddr,
const struct lowpan_iphc_ctx *ctx,
@@ -827,13 +857,7 @@ static u8 lowpan_compress_ctx_addr(u8 **hc_ptr, const struct net_device *dev,
}
break;
default:
- /* check for SAM/DAM = 11 */
- memcpy(&tmp.s6_addr[8], lladdr, EUI64_ADDR_LEN);
- /* second bit-flip (Universe/Local) is done according RFC2464 */
- tmp.s6_addr[8] ^= 0x02;
- /* context information are always used */
- ipv6_addr_prefix_copy(&tmp, &ctx->pfx, ctx->plen);
- if (ipv6_addr_equal(&tmp, ipaddr)) {
+ if (lowpan_iphc_addr_equal(dev, ctx, ipaddr, lladdr)) {
dam = LOWPAN_IPHC_DAM_11;
goto out;
}
@@ -929,11 +953,12 @@ static u8 lowpan_compress_addr_64(u8 **hc_ptr, const struct net_device *dev,
}
break;
default:
- if (is_addr_mac_addr_based(ipaddr, lladdr)) {
- dam = LOWPAN_IPHC_DAM_11; /* 0-bits */
+ if (lowpan_iphc_addr_equal(dev, NULL, ipaddr, lladdr)) {
+ dam = LOWPAN_IPHC_DAM_11;
pr_debug("address compression 0 bits\n");
goto out;
}
+
break;
}

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 1456b01..0b68cfc 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -64,7 +64,7 @@ struct lowpan_peer {
struct l2cap_chan *chan;

/* peer addresses in various formats */
- unsigned char eui64_addr[EUI64_ADDR_LEN];
+ unsigned char lladdr[ETH_ALEN];
struct in6_addr peer_addr;
};

@@ -80,8 +80,6 @@ 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)
{
@@ -277,7 +275,6 @@ static int iphc_decompress(struct sk_buff *skb, struct net_device *netdev,
const u8 *saddr;
struct lowpan_btle_dev *dev;
struct lowpan_peer *peer;
- unsigned char eui64_daddr[EUI64_ADDR_LEN];

dev = lowpan_btle_dev(netdev);

@@ -287,10 +284,9 @@ static int iphc_decompress(struct sk_buff *skb, struct net_device *netdev,
if (!peer)
return -EINVAL;

- saddr = peer->eui64_addr;
- set_addr(&eui64_daddr[0], chan->src.b, chan->src_type);
+ saddr = peer->lladdr;

- return lowpan_header_decompress(skb, netdev, &eui64_daddr, saddr);
+ return lowpan_header_decompress(skb, netdev, netdev->dev_addr, saddr);
}

static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
@@ -477,7 +473,7 @@ static int setup_header(struct sk_buff *skb, struct net_device *netdev,
}
}

- daddr = peer->eui64_addr;
+ daddr = peer->lladdr;
*peer_addr = addr;
*peer_addr_type = addr_type;
lowpan_cb(skb)->chan = peer->chan;
@@ -663,27 +659,6 @@ static struct device_type bt_type = {
.name = "bluetooth",
};

-static void set_addr(u8 *eui, u8 *addr, u8 addr_type)
-{
- /* addr is the BT address in little-endian format */
- eui[0] = addr[5];
- eui[1] = addr[4];
- eui[2] = addr[3];
- eui[3] = 0xFF;
- eui[4] = 0xFE;
- eui[5] = addr[2];
- eui[6] = addr[1];
- eui[7] = addr[0];
-
- /* Universal/local bit set, BT 6lowpan draft ch. 3.2.1 */
- if (addr_type == BDADDR_LE_PUBLIC)
- eui[0] &= ~0x02;
- else
- eui[0] |= 0x02;
-
- BT_DBG("type %d addr %*phC", addr_type, 8, eui);
-}
-
static void ifup(struct net_device *netdev)
{
int err;
@@ -762,14 +737,9 @@ static struct l2cap_chan *add_peer_chan(struct l2cap_chan *chan,
peer->chan = chan;
memset(&peer->peer_addr, 0, sizeof(struct in6_addr));

- /* RFC 2464 ch. 5 */
- peer->peer_addr.s6_addr[0] = 0xFE;
- peer->peer_addr.s6_addr[1] = 0x80;
- set_addr((u8 *)&peer->peer_addr.s6_addr + 8, chan->dst.b,
- chan->dst_type);
+ baswap((void *)peer->lladdr, &chan->dst);

- memcpy(&peer->eui64_addr, (u8 *)&peer->peer_addr.s6_addr + 8,
- EUI64_ADDR_LEN);
+ lowpan_iphc_uncompress_eui48_lladdr(&peer->peer_addr, peer->lladdr);

/* IPv6 address needs to have the U/L bit set properly so toggle
* it back here.
--
2.9.3


2017-02-17 15:50:02

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v3 4/5] ipv6: addrconf: fix 48 bit 6lowpan autoconfiguration

From: Alexander Aring <[email protected]>

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

Signed-off-by: Alexander Aring <[email protected]>
Signed-off-by: Luiz Augusto von Dentz <[email protected]>
---
net/ipv6/addrconf.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index ac9bd56..dede33f 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -2050,12 +2050,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;
}

@@ -2146,7 +2153,7 @@ static int ipv6_generate_eui64(u8 *eui, struct net_device *dev)
case ARPHRD_IPGRE:
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:
--
2.9.3


2017-02-17 15:50:01

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v3 3/5] 6lowpan: iphc: override l2 packet information

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.

Signed-off-by: Alexander Aring <[email protected]>
---
net/6lowpan/iphc.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/net/6lowpan/iphc.c b/net/6lowpan/iphc.c
index 79f1fa2..fb5f6fa 100644
--- a/net/6lowpan/iphc.c
+++ b/net/6lowpan/iphc.c
@@ -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);
--
2.9.3


2017-02-17 15:50:00

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v3 2/5] 6lowpan: Set MAC address lenght according to LOWPAN_LLTYPE

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.

Signed-off-by: Patrik Flykt <[email protected]>
---
net/6lowpan/core.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/net/6lowpan/core.c b/net/6lowpan/core.c
index 5945f7e..5f9909a 100644
--- a/net/6lowpan/core.c
+++ b/net/6lowpan/core.c
@@ -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;
--
2.9.3


2017-02-17 15:49:59

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v3 1/5] 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.

Signed-off-by: Patrik Flykt <[email protected]>
Signed-off-by: Luiz Augusto von Dentz <[email protected]>
---
net/bluetooth/6lowpan.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
index 1904a93..1456b01 100644
--- a/net/bluetooth/6lowpan.c
+++ b/net/bluetooth/6lowpan.c
@@ -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);
--
2.9.3