Skip to contentSkip to conversation

ieee802154: 6lowpan: cleanup and rework dispatch evaluation

RFC Superseded Alexander Aring 2 participants 44 messages Aug 3, 2015 – Aug 15, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

cover ieee802154: 6lowpan: cleanup and rework dispatch evaluation

Hi,

this patch series contains a rework of 802.15.4 6LoWPAN receive handling. We need to check on some things before which never checked before, like is 802.15.4 dataframe, if we can access skb->data[0] (could be that skb->len is 0 then), etc.

Also various bug fixes like the masking for fragmentation dispatch value which is currently wrong. Also we should again check the dispatch value after successful reassembly a fragment, we currently assume always a iphc header there. This is wrong it could also be a non-compressed header. This can occur if the compressed header is larger than lower interface MTU size, we doesn't react on this while transmit which is another issue. Nevertheless we also don't reach this case at worst-case compression currently.

I introduced a complete new handling for the dispatch values based on mac80211 datatype receive handling mechanism.

This patch series based on bluetooth-next with various pending patches, I uploaded the branch at:

https://github.com/linux-wpan/linux-wpan-next/commits/802154_6lowpan_cleanup2

so everybody can test it.

- Alex

Alexander Aring (16):
ieee802154: 6lowpan: change dev vars to wdev and ldev
ieee802154: 6lowpan: remove set to zero
ieee802154: 6lowpan: remove EXPORT_SYMBOL
ieee802154: 6lowpan: remove check on wdev is running
ieee802154: 6lowpan: cleanup pull of iphc bytes
ieee802154: 6lowpan: trivial checks at first
ieee802154: 6lowpan: change skb->dev earlier
ieee802154: 6lowpan: change frag return value handling
ieee820154: 6lowpan: dispatch evaluation rework
ieee802154: 6lowpan: add dispatch evalualtion helpers
ieee802154: 6lowpan: fix fragmentation dispatch mask
ieee802154: 6lowpan: add generic lowpan header check
ieee802154: 6lowpan: add handler for all dispatch values
ieee802154: 6lowpan: add check for reserved dispatch
ieee802154: 6lowpan: check on valid 802.15.4 frame
ieee802154: 6lowpan: remove packet type to host

 include/linux/ieee802154.h          |  48 +++++-
 include/net/6lowpan.h               |  18 ++-
 net/ieee802154/6lowpan/6lowpan_i.h  |   5 +-
 net/ieee802154/6lowpan/core.c       |  83 +++++-----
 net/ieee802154/6lowpan/reassembly.c |  15 +-
 net/ieee802154/6lowpan/rx.c         | 312 +++++++++++++++++++++++++++---------
 net/ieee802154/6lowpan/tx.c         |  39 +++--
 7 files changed, 369 insertions(+), 151 deletions(-)
Signature · 1 line
2.5.0
author maintainer
#1 lore raw

RFC 1/16 ieee802154: 6lowpan: change dev vars to wdev and ldev

Inside the IEEE 802.15.4 6LoWPAN subsystem we use two interfaces which are wpan and lowpan interfaces. Instead of using always the variable name "dev" for both we rename the "dev" variable to wdev which means the wpan net_device and ldev which means a lowpan net_device. This avoids confusing and always looking back to see which net_device is meant by the variable name "dev".

---
 net/ieee802154/6lowpan/6lowpan_i.h  |  2 +-
 net/ieee802154/6lowpan/core.c       | 85 ++++++++++++++++++-------------------
 net/ieee802154/6lowpan/reassembly.c | 14 +++---
 net/ieee802154/6lowpan/rx.c         | 20 ++++-----
 net/ieee802154/6lowpan/tx.c         | 39 +++++++++--------
 5 files changed, 79 insertions(+), 81 deletions(-)
net/ieee802154/6lowpan/6lowpan_i.h +1 -1
index ff727aa..d62046e 100644
@@ -40,7 +40,7 @@ static inline u32 ieee802154_addr_hash(const struct ieee802154_addr *a)
 
 /* private device info */
 struct lowpan_dev_info {
-	struct net_device	*real_dev; /* real WPAN device ptr */
+	struct net_device	*wdev; /* real WPAN device ptr */
 	u16			fragment_tag;
 };
 
net/ieee802154/6lowpan/core.c +42 -43

157 lines not on this page · raw message

net/ieee802154/6lowpan/reassembly.c +7 -7
index f46e4d1..c9f77f7 100644
@@ -46,7 +46,7 @@ static struct lowpan_frag_info *lowpan_cb(struct sk_buff *skb)
 static struct inet_frags lowpan_frags;
 
 static int lowpan_frag_reasm(struct lowpan_frag_queue *fq,
-			     struct sk_buff *prev, struct net_device *dev);
+			     struct sk_buff *prev, struct net_device *ldev);
 
 static unsigned int lowpan_hash_frag(u16 tag, u16 d_size,
 				     const struct ieee802154_addr *saddr,
@@ -141,7 +141,7 @@ static int lowpan_frag_queue(struct lowpan_frag_queue *fq,
 			     struct sk_buff *skb, const u8 frag_type)
 {
 	struct sk_buff *prev, *next;
-	struct net_device *dev;
+	struct net_device *ldev;
 	int end, offset;
 
 	if (fq->q.flags & INET_FRAG_COMPLETE)
@@ -195,8 +195,8 @@ found:
 	else
 		fq->q.fragments = skb;
 
-	dev = skb->dev;
-	if (dev)
+	ldev = skb->dev;
+	if (ldev)
 		skb->dev = NULL;
 
 	fq->q.stamp = skb->tstamp;
@@ -215,7 +215,7 @@ found:
 		unsigned long orefdst = skb->_skb_refdst;
 
 		skb->_skb_refdst = 0UL;
-		res = lowpan_frag_reasm(fq, prev, dev);
+		res = lowpan_frag_reasm(fq, prev, ldev);
 		skb->_skb_refdst = orefdst;
 		return res;
 	}
@@ -235,7 +235,7 @@ err:
  *	the last and the first frames arrived and all the bits are here.
  */
 static int lowpan_frag_reasm(struct lowpan_frag_queue *fq, struct sk_buff *prev,
-			     struct net_device *dev)
+			     struct net_device *ldev)
 {
 	struct sk_buff *fp, *head = fq->q.fragments;
 	int sum_truesize;
@@ -313,7 +313,7 @@ static int lowpan_frag_reasm(struct lowpan_frag_queue *fq, struct sk_buff *prev,
 	sub_frag_mem_limit(&fq->q, sum_truesize);
 
 	head->next = NULL;
-	head->dev = dev;
+	head->dev = ldev;
 	head->tstamp = fq->q.stamp;
 
 	fq->q.fragments = NULL;
net/ieee802154/6lowpan/rx.c +10 -10
index d6f5e8e..6302b94 100644
@@ -16,9 +16,9 @@
 #include "6lowpan_i.h"
 
 static int lowpan_give_skb_to_device(struct sk_buff *skb,
-				     struct net_device *dev)
+				     struct net_device *wdev)
 {
-	skb->dev = dev->ieee802154_ptr->lowpan_dev;
+	skb->dev = wdev->ieee802154_ptr->lowpan_dev;
 	skb->protocol = htons(ETH_P_IPV6);
 	skb->pkt_type = PACKET_HOST;
 
@@ -61,8 +61,8 @@ iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
 					IEEE802154_ADDR_LEN, iphc0, iphc1);
 }
 
-static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
-		      struct packet_type *pt, struct net_device *orig_dev)
+static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
+		      struct packet_type *pt, struct net_device *orig_wdev)
 {
 	struct ieee802154_hdr hdr;
 	int ret;
@@ -71,13 +71,13 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
 	if (!skb)
 		goto drop;
 
-	if (!netif_running(dev))
+	if (!netif_running(wdev))
 		goto drop_skb;
 
 	if (skb->pkt_type == PACKET_OTHERHOST)
 		goto drop_skb;
 
-	if (dev->type != ARPHRD_IEEE802154)
+	if (wdev->type != ARPHRD_IEEE802154)
 		goto drop_skb;
 
 	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
@@ -87,7 +87,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
 	if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
 		/* Pull off the 1-byte of 6lowpan header. */
 		skb_pull(skb, 1);
-		return lowpan_give_skb_to_device(skb, dev);
+		return lowpan_give_skb_to_device(skb, wdev);
 	} else {
 		switch (skb->data[0] & 0xe0) {
 		case LOWPAN_DISPATCH_IPHC:	/* ipv6 datagram */
@@ -95,7 +95,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
 			if (ret < 0)
 				goto drop_skb;
 
-			return lowpan_give_skb_to_device(skb, dev);
+			return lowpan_give_skb_to_device(skb, wdev);
 		case LOWPAN_DISPATCH_FRAG1:	/* first fragment header */
 			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
 			if (ret == 1) {
@@ -103,7 +103,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
 				if (ret < 0)
 					goto drop_skb;
 
-				return lowpan_give_skb_to_device(skb, dev);
+				return lowpan_give_skb_to_device(skb, wdev);
 			} else if (ret == -1) {
 				return NET_RX_DROP;
 			} else {
@@ -116,7 +116,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
 				if (ret < 0)
 					goto drop_skb;
 
-				return lowpan_give_skb_to_device(skb, dev);
+				return lowpan_give_skb_to_device(skb, wdev);
 			} else if (ret == -1) {
 				return NET_RX_DROP;
 			} else {
net/ieee802154/6lowpan/tx.c +19 -20
index 1bf4a30..564e973 100644
@@ -36,7 +36,7 @@ lowpan_addr_info *lowpan_skb_priv(const struct sk_buff *skb)
 			sizeof(struct lowpan_addr_info));
 }
 
-int lowpan_header_create(struct sk_buff *skb, struct net_device *dev,
+int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev,
 			 unsigned short type, const void *_daddr,
 			 const void *_saddr, unsigned int len)
 {
@@ -51,7 +51,7 @@ int lowpan_header_create(struct sk_buff *skb, struct net_device *dev,
 		return 0;
 
 	if (!saddr)
-		saddr = dev->dev_addr;
+		saddr = ldev->dev_addr;
 
 	raw_dump_inline(__func__, "saddr", (unsigned char *)saddr, 8);
 	raw_dump_inline(__func__, "daddr", (unsigned char *)daddr, 8);
@@ -73,22 +73,21 @@ static struct sk_buff*
 lowpan_alloc_frag(struct sk_buff *skb, int size,
 		  const struct ieee802154_hdr *master_hdr)
 {
-	struct net_device *real_dev = lowpan_dev_info(skb->dev)->real_dev;
+	struct net_device *wdev = lowpan_dev_info(skb->dev)->wdev;
 	struct sk_buff *frag;
 	int rc;
 
-	frag = alloc_skb(real_dev->hard_header_len +
-			 real_dev->needed_tailroom + size,
+	frag = alloc_skb(wdev->hard_header_len + wdev->needed_tailroom + size,
 			 GFP_ATOMIC);
 
 	if (likely(frag)) {
-		frag->dev = real_dev;
+		frag->dev = wdev;
 		frag->priority = skb->priority;
-		skb_reserve(frag, real_dev->hard_header_len);
+		skb_reserve(frag, wdev->hard_header_len);
 		skb_reset_network_header(frag);
 		*mac_cb(frag) = *mac_cb(skb);
 
-		rc = dev_hard_header(frag, real_dev, 0, &master_hdr->dest,
+		rc = dev_hard_header(frag, wdev, 0, &master_hdr->dest,
 				     &master_hdr->source, size);
 		if (rc < 0) {
 			kfree_skb(frag);
@@ -123,7 +122,7 @@ lowpan_xmit_fragment(struct sk_buff *skb, const struct ieee802154_hdr *wpan_hdr,
 }
 
 static int
-lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *dev,
+lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *ldev,
 		       const struct ieee802154_hdr *wpan_hdr)
 {
 	u16 dgram_size, dgram_offset;
@@ -134,8 +133,8 @@ lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *dev,
 
 	dgram_size = lowpan_uncompress_size(skb, &dgram_offset) -
 		     skb->mac_len;
-	frag_tag = htons(lowpan_dev_info(dev)->fragment_tag);
-	lowpan_dev_info(dev)->fragment_tag++;
+	frag_tag = htons(lowpan_dev_info(ldev)->fragment_tag);
+	lowpan_dev_info(ldev)->fragment_tag++;
 
 	frag_hdr[0] = LOWPAN_DISPATCH_FRAG1 | ((dgram_size >> 8) & 0x07);
 	frag_hdr[1] = dgram_size & 0xff;
@@ -188,9 +187,9 @@ err:
 	return rc;
 }
 
-static int lowpan_header(struct sk_buff *skb, struct net_device *dev)
+static int lowpan_header(struct sk_buff *skb, struct net_device *ldev)
 {
-	struct wpan_dev *wpan_dev = lowpan_dev_info(dev)->real_dev->ieee802154_ptr;
+	struct wpan_dev *wpan_dev = lowpan_dev_info(ldev)->wdev->ieee802154_ptr;
 	struct ieee802154_addr sa, da;
 	struct ieee802154_mac_cb *cb = mac_cb_init(skb);
 	struct lowpan_addr_info info;
@@ -202,7 +201,7 @@ static int lowpan_header(struct sk_buff *skb, struct net_device *dev)
 	daddr = &info.daddr.u.extended_addr;
 	saddr = &info.saddr.u.extended_addr;
 
-	lowpan_header_compress(skb, dev, ETH_P_IPV6, daddr, saddr, skb->len);
+	lowpan_header_compress(skb, ldev, ETH_P_IPV6, daddr, saddr, skb->len);
 
 	cb->type = IEEE802154_FC_TYPE_DATA;
 
@@ -227,11 +226,11 @@ static int lowpan_header(struct sk_buff *skb, struct net_device *dev)
 		cb->ackreq = wpan_dev->ackreq;
 	}
 
-	return dev_hard_header(skb, lowpan_dev_info(dev)->real_dev,
-			ETH_P_IPV6, (void *)&da, (void *)&sa, 0);
+	return dev_hard_header(skb, lowpan_dev_info(ldev)->wdev, ETH_P_IPV6,
+			       (void *)&da, (void *)&sa, 0);
 }
 
-netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
+netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
 {
 	struct ieee802154_hdr wpan_hdr;
 	int max_single, ret;
@@ -245,7 +244,7 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
 	if (!skb)
 		return NET_XMIT_DROP;
 
-	ret = lowpan_header(skb, dev);
+	ret = lowpan_header(skb, ldev);
 	if (ret < 0) {
 		kfree_skb(skb);
 		return NET_XMIT_DROP;
@@ -259,13 +258,13 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
 	max_single = ieee802154_max_payload(&wpan_hdr);
 
 	if (skb_tail_pointer(skb) - skb_network_header(skb) <= max_single) {
-		skb->dev = lowpan_dev_info(dev)->real_dev;
+		skb->dev = lowpan_dev_info(ldev)->wdev;
 		return dev_queue_xmit(skb);
 	} else {
 		netdev_tx_t rc;
 
 		pr_debug("frame is too big, fragmentation is needed\n");
-		rc = lowpan_xmit_fragmented(skb, dev, &wpan_hdr);
+		rc = lowpan_xmit_fragmented(skb, ldev, &wpan_hdr);
 
 		return rc < 0 ? NET_XMIT_DROP : rc;
 	}
Signature · 1 line
2.5.0
Reviewed-by on v1 1/16
#2 lore raw

Re: [RFC 01/16] ieee802154: 6lowpan: change dev vars to wdev and ldev

Hello.

Quoted 21 lines · Alexander Aring

Inside the IEEE 802.15.4 6LoWPAN subsystem we use two interfaces which are wpan and lowpan interfaces. Instead of using always the variable name "dev" for both we rename the "dev" variable to wdev which means the wpan net_device and ldev which means a lowpan net_device. This avoids confusing and always looking back to see which net_device is meant by the variable name "dev".

---
  net/ieee802154/6lowpan/6lowpan_i.h  |  2 +-
  net/ieee802154/6lowpan/core.c       | 85 ++++++++++++++++++-------------------
  net/ieee802154/6lowpan/reassembly.c | 14 +++---
  net/ieee802154/6lowpan/rx.c         | 20 ++++-----
  net/ieee802154/6lowpan/tx.c         | 39 +++++++++--------
  5 files changed, 79 insertions(+), 81 deletions(-)
net/ieee802154/6lowpan/6lowpan_i.h +0 -0
index ff727aa..d62046e 100644

net/ieee802154/6lowpan/6lowpan_i.h static inline u32 ieee802154_addr_hash(const struct ieee802154_addr *a) · line 43

Quoted 5 lines
net/ieee802154/6lowpan/6lowpan_i.h +1 -1
@@ -40,7 +40,7 @@ static inline u32 ieee802154_addr_hash(const struct ieee802154_addr *a)
 
  /* private device info */
  struct lowpan_dev_info {
-	struct net_device	*real_dev; /* real WPAN device ptr */
+	struct net_device	*wdev; /* real WPAN device ptr */

Maybe remove the real also from the comment here.

Quoted 431 lines
net/ieee802154/6lowpan/6lowpan_i.h +0 -0
  	u16			fragment_tag;
  };
 
net/ieee802154/6lowpan/core.c +42 -43
index ef17c6a..46efaca 100644
@@ -59,7 +59,7 @@ static struct header_ops lowpan_header_ops = {
  static struct lock_class_key lowpan_tx_busylock;
  static struct lock_class_key lowpan_netdev_xmit_lock_key;
 
-static void lowpan_set_lockdep_class_one(struct net_device *dev,
+static void lowpan_set_lockdep_class_one(struct net_device *ldev,
  					 struct netdev_queue *txq,
  					 void *_unused)
  {
@@ -67,10 +67,10 @@ static void lowpan_set_lockdep_class_one(struct net_device *dev,
  			  &lowpan_netdev_xmit_lock_key);
  }
 
-static int lowpan_dev_init(struct net_device *dev)
+static int lowpan_dev_init(struct net_device *ldev)
  {
-	netdev_for_each_tx_queue(dev, lowpan_set_lockdep_class_one, NULL);
-	dev->qdisc_tx_busylock = &lowpan_tx_busylock;
+	netdev_for_each_tx_queue(ldev, lowpan_set_lockdep_class_one, NULL);
+	ldev->qdisc_tx_busylock = &lowpan_tx_busylock;
  	return 0;
  }
 
@@ -79,23 +79,23 @@ static const struct net_device_ops lowpan_netdev_ops = {
  	.ndo_start_xmit		= lowpan_xmit,
  };
 
-static void lowpan_setup(struct net_device *dev)
+static void lowpan_setup(struct net_device *ldev)
  {
-	dev->addr_len		= IEEE802154_ADDR_LEN;
-	memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
-	dev->type		= ARPHRD_6LOWPAN;
+	ldev->addr_len		= IEEE802154_ADDR_LEN;
+	memset(ldev->broadcast, 0xff, IEEE802154_ADDR_LEN);
+	ldev->type		= ARPHRD_6LOWPAN;
  	/* Frame Control + Sequence Number + Address fields + Security Header */
-	dev->hard_header_len	= 2 + 1 + 20 + 14;
-	dev->needed_tailroom	= 2; /* FCS */
-	dev->mtu		= IPV6_MIN_MTU;
-	dev->tx_queue_len	= 0;
-	dev->flags		= IFF_BROADCAST | IFF_MULTICAST;
-	dev->watchdog_timeo	= 0;
-
-	dev->netdev_ops		= &lowpan_netdev_ops;
-	dev->header_ops		= &lowpan_header_ops;
-	dev->destructor		= free_netdev;
-	dev->features		|= NETIF_F_NETNS_LOCAL;
+	ldev->hard_header_len	= 2 + 1 + 20 + 14;
+	ldev->needed_tailroom	= 2; /* FCS */
+	ldev->mtu		= IPV6_MIN_MTU;
+	ldev->tx_queue_len	= 0;
+	ldev->flags		= IFF_BROADCAST | IFF_MULTICAST;
+	ldev->watchdog_timeo	= 0;
+
+	ldev->netdev_ops	= &lowpan_netdev_ops;
+	ldev->header_ops	= &lowpan_header_ops;
+	ldev->destructor	= free_netdev;
+	ldev->features		|= NETIF_F_NETNS_LOCAL;
  }
 
  static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -107,10 +107,10 @@ static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[])
  	return 0;
  }
 
-static int lowpan_newlink(struct net *src_net, struct net_device *dev,
+static int lowpan_newlink(struct net *src_net, struct net_device *ldev,
  			  struct nlattr *tb[], struct nlattr *data[])
  {
-	struct net_device *real_dev;
+	struct net_device *wdev;
  	int ret;
 
  	ASSERT_RTNL();
@@ -118,48 +118,47 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
  	pr_debug("adding new link\n");
 
  	if (!tb[IFLA_LINK] ||
-	    !net_eq(dev_net(dev), &init_net))
+	    !net_eq(dev_net(ldev), &init_net))
  		return -EINVAL;
  	/* find and hold real wpan device */
-	real_dev = dev_get_by_index(dev_net(dev), nla_get_u32(tb[IFLA_LINK]));
-	if (!real_dev)
+	wdev = dev_get_by_index(dev_net(ldev), nla_get_u32(tb[IFLA_LINK]));
+	if (!wdev)
  		return -ENODEV;
-	if (real_dev->type != ARPHRD_IEEE802154) {
-		dev_put(real_dev);
+	if (wdev->type != ARPHRD_IEEE802154) {
+		dev_put(wdev);
  		return -EINVAL;
  	}
 
-	if (real_dev->ieee802154_ptr->lowpan_dev) {
-		dev_put(real_dev);
+	if (wdev->ieee802154_ptr->lowpan_dev) {
+		dev_put(wdev);
  		return -EBUSY;
  	}
 
-	lowpan_dev_info(dev)->real_dev = real_dev;
+	lowpan_dev_info(ldev)->wdev = wdev;
  	/* Set the lowpan hardware address to the wpan hardware address. */
-	memcpy(dev->dev_addr, real_dev->dev_addr, IEEE802154_ADDR_LEN);
+	memcpy(ldev->dev_addr, wdev->dev_addr, IEEE802154_ADDR_LEN);
 
-	lowpan_priv(dev)->lltype = LOWPAN_LLTYPE_IEEE802154;
+	lowpan_priv(ldev)->lltype = LOWPAN_LLTYPE_IEEE802154;
 
-	ret = register_netdevice(dev);
+	ret = register_netdevice(ldev);
  	if (ret >= 0) {
-		real_dev->ieee802154_ptr->lowpan_dev = dev;
+		wdev->ieee802154_ptr->lowpan_dev = ldev;
  		lowpan_rx_init();
  	}
 
  	return ret;
  }
 
-static void lowpan_dellink(struct net_device *dev, struct list_head *head)
+static void lowpan_dellink(struct net_device *ldev, struct list_head *head)
  {
-	struct lowpan_dev_info *lowpan_dev = lowpan_dev_info(dev);
-	struct net_device *real_dev = lowpan_dev->real_dev;
+	struct net_device *wdev = lowpan_dev_info(ldev)->wdev;
 
  	ASSERT_RTNL();
 
  	lowpan_rx_exit();
-	real_dev->ieee802154_ptr->lowpan_dev = NULL;
-	unregister_netdevice(dev);
-	dev_put(real_dev);
+	wdev->ieee802154_ptr->lowpan_dev = NULL;
+	unregister_netdevice(ldev);
+	dev_put(wdev);
  }
 
  static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
@@ -185,9 +184,9 @@ static inline void lowpan_netlink_fini(void)
  static int lowpan_device_event(struct notifier_block *unused,
  			       unsigned long event, void *ptr)
  {
-	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
+	struct net_device *wdev = netdev_notifier_info_to_dev(ptr);
 
-	if (dev->type != ARPHRD_IEEE802154)
+	if (wdev->type != ARPHRD_IEEE802154)
  		goto out;
 
  	switch (event) {
@@ -196,8 +195,8 @@ static int lowpan_device_event(struct notifier_block *unused,
  		 * also delete possible lowpan interfaces which belongs
  		 * to the wpan interface.
  		 */
-		if (dev->ieee802154_ptr && dev->ieee802154_ptr->lowpan_dev)
-			lowpan_dellink(dev->ieee802154_ptr->lowpan_dev, NULL);
+		if (wdev->ieee802154_ptr && wdev->ieee802154_ptr->lowpan_dev)
+			lowpan_dellink(wdev->ieee802154_ptr->lowpan_dev, NULL);
  		break;
  	default:
  		break;
net/ieee802154/6lowpan/reassembly.c +7 -7
index f46e4d1..c9f77f7 100644
@@ -46,7 +46,7 @@ static struct lowpan_frag_info *lowpan_cb(struct sk_buff *skb)
  static struct inet_frags lowpan_frags;
 
  static int lowpan_frag_reasm(struct lowpan_frag_queue *fq,
-			     struct sk_buff *prev, struct net_device *dev);
+			     struct sk_buff *prev, struct net_device *ldev);
 
  static unsigned int lowpan_hash_frag(u16 tag, u16 d_size,
  				     const struct ieee802154_addr *saddr,
@@ -141,7 +141,7 @@ static int lowpan_frag_queue(struct lowpan_frag_queue *fq,
  			     struct sk_buff *skb, const u8 frag_type)
  {
  	struct sk_buff *prev, *next;
-	struct net_device *dev;
+	struct net_device *ldev;
  	int end, offset;
 
  	if (fq->q.flags & INET_FRAG_COMPLETE)
@@ -195,8 +195,8 @@ found:
  	else
  		fq->q.fragments = skb;
 
-	dev = skb->dev;
-	if (dev)
+	ldev = skb->dev;
+	if (ldev)
  		skb->dev = NULL;
 
  	fq->q.stamp = skb->tstamp;
@@ -215,7 +215,7 @@ found:
  		unsigned long orefdst = skb->_skb_refdst;
 
  		skb->_skb_refdst = 0UL;
-		res = lowpan_frag_reasm(fq, prev, dev);
+		res = lowpan_frag_reasm(fq, prev, ldev);
  		skb->_skb_refdst = orefdst;
  		return res;
  	}
@@ -235,7 +235,7 @@ err:
   *	the last and the first frames arrived and all the bits are here.
   */
  static int lowpan_frag_reasm(struct lowpan_frag_queue *fq, struct sk_buff *prev,
-			     struct net_device *dev)
+			     struct net_device *ldev)
  {
  	struct sk_buff *fp, *head = fq->q.fragments;
  	int sum_truesize;
@@ -313,7 +313,7 @@ static int lowpan_frag_reasm(struct lowpan_frag_queue *fq, struct sk_buff *prev,
  	sub_frag_mem_limit(&fq->q, sum_truesize);
 
  	head->next = NULL;
-	head->dev = dev;
+	head->dev = ldev;
  	head->tstamp = fq->q.stamp;
 
  	fq->q.fragments = NULL;
net/ieee802154/6lowpan/rx.c +10 -10
index d6f5e8e..6302b94 100644
@@ -16,9 +16,9 @@
  #include "6lowpan_i.h"
 
  static int lowpan_give_skb_to_device(struct sk_buff *skb,
-				     struct net_device *dev)
+				     struct net_device *wdev)
  {
-	skb->dev = dev->ieee802154_ptr->lowpan_dev;
+	skb->dev = wdev->ieee802154_ptr->lowpan_dev;
  	skb->protocol = htons(ETH_P_IPV6);
  	skb->pkt_type = PACKET_HOST;
 
@@ -61,8 +61,8 @@ iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
  					IEEE802154_ADDR_LEN, iphc0, iphc1);
  }
 
-static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
-		      struct packet_type *pt, struct net_device *orig_dev)
+static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
+		      struct packet_type *pt, struct net_device *orig_wdev)
  {
  	struct ieee802154_hdr hdr;
  	int ret;
@@ -71,13 +71,13 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
  	if (!skb)
  		goto drop;
 
-	if (!netif_running(dev))
+	if (!netif_running(wdev))
  		goto drop_skb;
 
  	if (skb->pkt_type == PACKET_OTHERHOST)
  		goto drop_skb;
 
-	if (dev->type != ARPHRD_IEEE802154)
+	if (wdev->type != ARPHRD_IEEE802154)
  		goto drop_skb;
 
  	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
@@ -87,7 +87,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
  	if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
  		/* Pull off the 1-byte of 6lowpan header. */
  		skb_pull(skb, 1);
-		return lowpan_give_skb_to_device(skb, dev);
+		return lowpan_give_skb_to_device(skb, wdev);
  	} else {
  		switch (skb->data[0] & 0xe0) {
  		case LOWPAN_DISPATCH_IPHC:	/* ipv6 datagram */
@@ -95,7 +95,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
  			if (ret < 0)
  				goto drop_skb;
 
-			return lowpan_give_skb_to_device(skb, dev);
+			return lowpan_give_skb_to_device(skb, wdev);
  		case LOWPAN_DISPATCH_FRAG1:	/* first fragment header */
  			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
  			if (ret == 1) {
@@ -103,7 +103,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
  				if (ret < 0)
  					goto drop_skb;
 
-				return lowpan_give_skb_to_device(skb, dev);
+				return lowpan_give_skb_to_device(skb, wdev);
  			} else if (ret == -1) {
  				return NET_RX_DROP;
  			} else {
@@ -116,7 +116,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
  				if (ret < 0)
  					goto drop_skb;
 
-				return lowpan_give_skb_to_device(skb, dev);
+				return lowpan_give_skb_to_device(skb, wdev);
  			} else if (ret == -1) {
  				return NET_RX_DROP;
  			} else {
net/ieee802154/6lowpan/tx.c +18 -19
index 1bf4a30..564e973 100644
@@ -36,7 +36,7 @@ lowpan_addr_info *lowpan_skb_priv(const struct sk_buff *skb)
  			sizeof(struct lowpan_addr_info));
  }
 
-int lowpan_header_create(struct sk_buff *skb, struct net_device *dev,
+int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev,
  			 unsigned short type, const void *_daddr,
  			 const void *_saddr, unsigned int len)
  {
@@ -51,7 +51,7 @@ int lowpan_header_create(struct sk_buff *skb, struct net_device *dev,
  		return 0;
 
  	if (!saddr)
-		saddr = dev->dev_addr;
+		saddr = ldev->dev_addr;
 
  	raw_dump_inline(__func__, "saddr", (unsigned char *)saddr, 8);
  	raw_dump_inline(__func__, "daddr", (unsigned char *)daddr, 8);
@@ -73,22 +73,21 @@ static struct sk_buff*
  lowpan_alloc_frag(struct sk_buff *skb, int size,
  		  const struct ieee802154_hdr *master_hdr)
  {
-	struct net_device *real_dev = lowpan_dev_info(skb->dev)->real_dev;
+	struct net_device *wdev = lowpan_dev_info(skb->dev)->wdev;
  	struct sk_buff *frag;
  	int rc;
 
-	frag = alloc_skb(real_dev->hard_header_len +
-			 real_dev->needed_tailroom + size,
+	frag = alloc_skb(wdev->hard_header_len + wdev->needed_tailroom + size,
  			 GFP_ATOMIC);
 
  	if (likely(frag)) {
-		frag->dev = real_dev;
+		frag->dev = wdev;
  		frag->priority = skb->priority;
-		skb_reserve(frag, real_dev->hard_header_len);
+		skb_reserve(frag, wdev->hard_header_len);
  		skb_reset_network_header(frag);
  		*mac_cb(frag) = *mac_cb(skb);
 
-		rc = dev_hard_header(frag, real_dev, 0, &master_hdr->dest,
+		rc = dev_hard_header(frag, wdev, 0, &master_hdr->dest,
  				     &master_hdr->source, size);
  		if (rc < 0) {
  			kfree_skb(frag);
@@ -123,7 +122,7 @@ lowpan_xmit_fragment(struct sk_buff *skb, const struct ieee802154_hdr *wpan_hdr,
  }
 
  static int
-lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *dev,
+lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *ldev,
  		       const struct ieee802154_hdr *wpan_hdr)
  {
  	u16 dgram_size, dgram_offset;
@@ -134,8 +133,8 @@ lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *dev,
 
  	dgram_size = lowpan_uncompress_size(skb, &dgram_offset) -
  		     skb->mac_len;
-	frag_tag = htons(lowpan_dev_info(dev)->fragment_tag);
-	lowpan_dev_info(dev)->fragment_tag++;
+	frag_tag = htons(lowpan_dev_info(ldev)->fragment_tag);
+	lowpan_dev_info(ldev)->fragment_tag++;
 
  	frag_hdr[0] = LOWPAN_DISPATCH_FRAG1 | ((dgram_size >> 8) & 0x07);
  	frag_hdr[1] = dgram_size & 0xff;
@@ -188,9 +187,9 @@ err:
  	return rc;
  }
 
-static int lowpan_header(struct sk_buff *skb, struct net_device *dev)
+static int lowpan_header(struct sk_buff *skb, struct net_device *ldev)
  {
-	struct wpan_dev *wpan_dev = lowpan_dev_info(dev)->real_dev->ieee802154_ptr;
+	struct wpan_dev *wpan_dev = lowpan_dev_info(ldev)->wdev->ieee802154_ptr;
  	struct ieee802154_addr sa, da;
  	struct ieee802154_mac_cb *cb = mac_cb_init(skb);
  	struct lowpan_addr_info info;
@@ -202,7 +201,7 @@ static int lowpan_header(struct sk_buff *skb, struct net_device *dev)
  	daddr = &info.daddr.u.extended_addr;
  	saddr = &info.saddr.u.extended_addr;
 
-	lowpan_header_compress(skb, dev, ETH_P_IPV6, daddr, saddr, skb->len);
+	lowpan_header_compress(skb, ldev, ETH_P_IPV6, daddr, saddr, skb->len);
 
  	cb->type = IEEE802154_FC_TYPE_DATA;
 
@@ -227,11 +226,11 @@ static int lowpan_header(struct sk_buff *skb, struct net_device *dev)
  		cb->ackreq = wpan_dev->ackreq;
  	}
 
-	return dev_hard_header(skb, lowpan_dev_info(dev)->real_dev,
-			ETH_P_IPV6, (void *)&da, (void *)&sa, 0);
+	return dev_hard_header(skb, lowpan_dev_info(ldev)->wdev, ETH_P_IPV6,
+			       (void *)&da, (void *)&sa, 0);
  }
 
-netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
+netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
  {
  	struct ieee802154_hdr wpan_hdr;
  	int max_single, ret;
@@ -245,7 +244,7 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
  	if (!skb)
  		return NET_XMIT_DROP;
 
-	ret = lowpan_header(skb, dev);
+	ret = lowpan_header(skb, ldev);
  	if (ret < 0) {
  		kfree_skb(skb);
  		return NET_XMIT_DROP;
@@ -259,13 +258,13 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
  	max_single = ieee802154_max_payload(&wpan_hdr);
 
  	if (skb_tail_pointer(skb) - skb_network_header(skb) <= max_single) {
-		skb->dev = lowpan_dev_info(dev)->real_dev;
+		skb->dev = lowpan_dev_info(ldev)->wdev;

net/ieee802154/6lowpan/tx.c netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev) · line 270

Quoted 10 lines
net/ieee802154/6lowpan/tx.c +1 -1
  		return dev_queue_xmit(skb);
  	} else {
  		netdev_tx_t rc;
 
  		pr_debug("frame is too big, fragmentation is needed\n");
-		rc = lowpan_xmit_fragmented(skb, dev, &wpan_hdr);
+		rc = lowpan_xmit_fragmented(skb, ldev, &wpan_hdr);
 
  		return rc < 0 ? NET_XMIT_DROP : rc;
  	}

regards
Stefan Schmidt

author maintainer
#3 lore raw

RFC 2/16 ieee802154: 6lowpan: remove set to zero

In reply to Alexander Aring

Internal mechanism by calling netdev_alloc which use kzalloc already sets these variables to zero. This patch cleanup the setup of net_device.

---
 net/ieee802154/6lowpan/core.c | 2 --
 1 file changed, 2 deletions(-)
net/ieee802154/6lowpan/core.c +0 -2
index 46efaca..ca331bc 100644
@@ -88,9 +88,7 @@ static void lowpan_setup(struct net_device *ldev)
 	ldev->hard_header_len	= 2 + 1 + 20 + 14;
 	ldev->needed_tailroom	= 2; /* FCS */
 	ldev->mtu		= IPV6_MIN_MTU;
-	ldev->tx_queue_len	= 0;
 	ldev->flags		= IFF_BROADCAST | IFF_MULTICAST;
-	ldev->watchdog_timeo	= 0;
 
 	ldev->netdev_ops	= &lowpan_netdev_ops;
 	ldev->header_ops	= &lowpan_header_ops;
Signature · 1 line
2.5.0
Reviewed-by on v1 2/16
#4 lore raw

Re: [RFC 02/16] ieee802154: 6lowpan: remove set to zero

Hello.

Quoted 13 lines · Alexander Aring

Internal mechanism by calling netdev_alloc which use kzalloc already sets these variables to zero. This patch cleanup the setup of net_device.

---
  net/ieee802154/6lowpan/core.c | 2 --
  1 file changed, 2 deletions(-)
net/ieee802154/6lowpan/core.c +0 -0
index 46efaca..ca331bc 100644

net/ieee802154/6lowpan/core.c static void lowpan_setup(struct net_device *ldev) · line 94

Quoted 9 lines
net/ieee802154/6lowpan/core.c +0 -2
@@ -88,9 +88,7 @@ static void lowpan_setup(struct net_device *ldev)
  	ldev->hard_header_len	= 2 + 1 + 20 + 14;
  	ldev->needed_tailroom	= 2; /* FCS */
  	ldev->mtu		= IPV6_MIN_MTU;
-	ldev->tx_queue_len	= 0;
  	ldev->flags		= IFF_BROADCAST | IFF_MULTICAST;
-	ldev->watchdog_timeo	= 0;
 
  	ldev->netdev_ops	= &lowpan_netdev_ops;
  	ldev->header_ops	= &lowpan_header_ops;

regards
Stefan Schmidt

author maintainer
#5 lore raw

RFC 3/16 ieee802154: 6lowpan: remove EXPORT_SYMBOL

In reply to Alexander Aring

This function is used internally inside of ieee802154 6lowpan module only and not outside of any other module. We don't need to export this function then.

---
 net/ieee802154/6lowpan/reassembly.c | 1 -
 1 file changed, 1 deletion(-)
net/ieee802154/6lowpan/reassembly.c +0 -1
index c9f77f7..cfb8443 100644
@@ -387,7 +387,6 @@ err:
 	kfree_skb(skb);
 	return -1;
 }
-EXPORT_SYMBOL(lowpan_frag_rcv);
 
 #ifdef CONFIG_SYSCTL
 static int zero;
Signature · 1 line
2.5.0
Reviewed-by on v1 3/16
#6 lore raw

Re: [RFC 03/16] ieee802154: 6lowpan: remove EXPORT_SYMBOL

Hello.

Quoted 14 lines · Alexander Aring

This function is used internally inside of ieee802154 6lowpan module only and not outside of any other module. We don't need to export this function then.

---
  net/ieee802154/6lowpan/reassembly.c | 1 -
  1 file changed, 1 deletion(-)
net/ieee802154/6lowpan/reassembly.c +0 -0
index c9f77f7..cfb8443 100644

net/ieee802154/6lowpan/reassembly.c err: · line 392

Quoted 7 lines
net/ieee802154/6lowpan/reassembly.c +0 -1
@@ -387,7 +387,6 @@ err:
  	kfree_skb(skb);
  	return -1;
  }
-EXPORT_SYMBOL(lowpan_frag_rcv);
 
  #ifdef CONFIG_SYSCTL
  static int zero;

regards
Stefan Schmidt

author maintainer
#7 lore raw

RFC 4/16 ieee802154: 6lowpan: remove check on wdev is running

In reply to Alexander Aring

We don't need to check if the wpan interface is running because the lowpan_rcv is the packet layer receive handler for thw wpan interface. This means for the check if the wpan interface is running ends always in true.

---
 net/ieee802154/6lowpan/rx.c | 3 ---
 1 file changed, 3 deletions(-)
net/ieee802154/6lowpan/rx.c +0 -3
index 6302b94..99aeb56 100644
@@ -71,9 +71,6 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 	if (!skb)
 		goto drop;
 
-	if (!netif_running(wdev))
-		goto drop_skb;
-
 	if (skb->pkt_type == PACKET_OTHERHOST)
 		goto drop_skb;
 
Signature · 1 line
2.5.0
Reviewed-by on v1 4/16
#8 lore raw

Re: [RFC 04/16] ieee802154: 6lowpan: remove check on wdev is running

Hello.

Quoted 2 lines · Alexander Aring

We don't need to check if the wpan interface is running because the lowpan_rcv is the packet layer receive handler for thw wpan interface.

Typo. s/thw/the/

Quoted 13 lines

This means for the check if the wpan interface is running ends always in true.

---
  net/ieee802154/6lowpan/rx.c | 3 ---
  1 file changed, 3 deletions(-)
net/ieee802154/6lowpan/rx.c +0 -0
index 6302b94..99aeb56 100644

net/ieee802154/6lowpan/rx.c static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev, · line 76

Quoted 9 lines
net/ieee802154/6lowpan/rx.c +0 -3
@@ -71,9 +71,6 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
  	if (!skb)
  		goto drop;
 
-	if (!netif_running(wdev))
-		goto drop_skb;
-
  	if (skb->pkt_type == PACKET_OTHERHOST)
  		goto drop_skb;
 

regards
Stefan Schmidt

author maintainer
#9 lore raw

Re: [RFC 04/16] ieee802154: 6lowpan: remove check on wdev is running

In reply to Alexander Aring
Quoted 15 lines · Alexander Aring

We don't need to check if the wpan interface is running because the lowpan_rcv is the packet layer receive handler for thw wpan interface. This means for the check if the wpan interface is running ends always in true.

---
 net/ieee802154/6lowpan/rx.c | 3 ---
 1 file changed, 3 deletions(-)
net/ieee802154/6lowpan/rx.c +0 -0
index 6302b94..99aeb56 100644

net/ieee802154/6lowpan/rx.c static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev, · line 74

Quoted 7 lines
net/ieee802154/6lowpan/rx.c +0 -3
@@ -71,9 +71,6 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 	if (!skb)
 		goto drop;
 
-	if (!netif_running(wdev))
-		goto drop_skb;
-
 

I think this check should be converted to check if lowpan_dev (which belongs to the wdev) is running. Then we can drop it earlier. I think it currently works because netif_rx handles that then when the interface is down which belongs to the skb->dev.

There is a small window when the lowpan is down and while doing 6lowpan stuff. It could be that the lowpan is set to up while doing the 6lowpan stuff.

Vice versa it could be that the lowpan interface is up and then down while doing 6lowpan stuff, but then again netif_rx will handle that then right (I hope, since commit e9e4dd3267d0c5234c5c0f47440456b10875dec9 "net: do not process device backlog during unregistration" it does that with netif_running, but I think there must be some machanism for that before otherwise we should got issues when a lowpan_dev was down and receive skb's).

With changing this to netif_running according the lowpan_dev, we have the second case only. Both cases are very unlikely.

It's just a likely case to have lowpan interface down and then we always do 6lowpan adaptation layer and then netif_rx will drop it because netif_running is false. We should check this earlier.

- Alex

author maintainer
#10 lore raw

RFC 5/16 ieee802154: 6lowpan: cleanup pull of iphc bytes

In reply to Alexander Aring

This patch cleanups the pull of the iphc bytes. We don't need to check if the skb->len contains two bytes, this will be checked by lowpan_fetch_skb_u8.

---
 net/ieee802154/6lowpan/rx.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
net/ieee802154/6lowpan/rx.c +2 -7
index 99aeb56..7b6b038 100644
@@ -33,14 +33,9 @@ iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
 	void *sap, *dap;
 
 	raw_dump_table(__func__, "raw skb data dump", skb->data, skb->len);
-	/* at least two bytes will be used for the encoding */
-	if (skb->len < 2)
-		return -EINVAL;
-
-	if (lowpan_fetch_skb_u8(skb, &iphc0))
-		return -EINVAL;
 
-	if (lowpan_fetch_skb_u8(skb, &iphc1))
+	if (lowpan_fetch_skb_u8(skb, &iphc0) ||
+	    lowpan_fetch_skb_u8(skb, &iphc1))
 		return -EINVAL;
 
 	ieee802154_addr_to_sa(&sa, &hdr->source);
Signature · 1 line
2.5.0
Reviewed-by on v1 5/16
#11 lore raw

Re: [RFC 05/16] ieee802154: 6lowpan: cleanup pull of iphc bytes

Hello.

Quoted 20 lines · Alexander Aring

This patch cleanups the pull of the iphc bytes. We don't need to check if the skb->len contains two bytes, this will be checked by lowpan_fetch_skb_u8.

---
  net/ieee802154/6lowpan/rx.c | 9 ++-------
  1 file changed, 2 insertions(+), 7 deletions(-)
net/ieee802154/6lowpan/rx.c +0 -3
index 99aeb56..7b6b038 100644
@@ -33,14 +33,9 @@ iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
  	void *sap, *dap;
 
  	raw_dump_table(__func__, "raw skb data dump", skb->data, skb->len);
-	/* at least two bytes will be used for the encoding */
-	if (skb->len < 2)
-		return -EINVAL;

net/ieee802154/6lowpan/rx.c iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr) · line 41

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +2 -4
-
-	if (lowpan_fetch_skb_u8(skb, &iphc0))
-		return -EINVAL;
 
-	if (lowpan_fetch_skb_u8(skb, &iphc1))
+	if (lowpan_fetch_skb_u8(skb, &iphc0) ||
+	    lowpan_fetch_skb_u8(skb, &iphc1))
  		return -EINVAL;
 
  	ieee802154_addr_to_sa(&sa, &hdr->source);

regards
Stefan Schmidt

author maintainer
#12 lore raw

RFC 6/16 ieee802154: 6lowpan: trivial checks at first

In reply to Alexander Aring

This patch moves some trivial checks at first before calling skb_share_check which could do some memcpy if the buffer is shared.

---
 net/ieee802154/6lowpan/rx.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
net/ieee802154/6lowpan/rx.c +4 -6
index 7b6b038..11a5629 100644
@@ -62,16 +62,14 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 	struct ieee802154_hdr hdr;
 	int ret;
 
+	if (skb->pkt_type == PACKET_OTHERHOST ||
+	    wdev->type != ARPHRD_IEEE802154)
+		goto drop;
+
 	skb = skb_share_check(skb, GFP_ATOMIC);
 	if (!skb)
 		goto drop;
 
-	if (skb->pkt_type == PACKET_OTHERHOST)
-		goto drop_skb;
-
-	if (wdev->type != ARPHRD_IEEE802154)
-		goto drop_skb;
-
 	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
 		goto drop_skb;
 
Signature · 1 line
2.5.0
Reviewed-by on v1 6/16
#13 lore raw

Re: [RFC 06/16] ieee802154: 6lowpan: trivial checks at first

Hello.

Quoted 23 lines · Alexander Aring

This patch moves some trivial checks at first before calling skb_share_check which could do some memcpy if the buffer is shared.

---
  net/ieee802154/6lowpan/rx.c | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
net/ieee802154/6lowpan/rx.c +4 -0
index 7b6b038..11a5629 100644
@@ -62,16 +62,14 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
  	struct ieee802154_hdr hdr;
  	int ret;
 
+	if (skb->pkt_type == PACKET_OTHERHOST ||
+	    wdev->type != ARPHRD_IEEE802154)
+		goto drop;
+
  	skb = skb_share_check(skb, GFP_ATOMIC);
  	if (!skb)
  		goto drop;

net/ieee802154/6lowpan/rx.c static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev, · line 75

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +0 -6
 
-	if (skb->pkt_type == PACKET_OTHERHOST)
-		goto drop_skb;
-
-	if (wdev->type != ARPHRD_IEEE802154)
-		goto drop_skb;
-
  	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
  		goto drop_skb;
 

regards
Stefan Schmidt

author maintainer
#14 lore raw

Re: [RFC 06/16] ieee802154: 6lowpan: trivial checks at first

Quoted 27 lines · Stefan Schmidt

Hello.

Quoted 24 lines · Alexander Aring

This patch moves some trivial checks at first before calling skb_share_check which could do some memcpy if the buffer is shared.

---
 net/ieee802154/6lowpan/rx.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
net/ieee802154/6lowpan/rx.c +4 -2
index 7b6b038..11a5629 100644
@@ -62,16 +62,14 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 	struct ieee802154_hdr hdr;
 	int ret;
+	if (skb->pkt_type == PACKET_OTHERHOST ||
+	    wdev->type != ARPHRD_IEEE802154)
+		goto drop;
+
 	skb = skb_share_check(skb, GFP_ATOMIC);
 	if (!skb)
 		goto drop;
-	if (skb->pkt_type == PACKET_OTHERHOST)
-		goto drop_skb;
Quoted 9 lines

net/ieee802154/6lowpan/rx.c static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev, · line 74

Quoted 6 lines
net/ieee802154/6lowpan/rx.c +0 -4
-
-	if (wdev->type != ARPHRD_IEEE802154)
-		goto drop_skb;
-
 	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
 		goto drop_skb;

Maybe I should switch also the conditions, means first check on wdev-type. Because this function is called for all registered net_devices (in my opinion) and do first check on type ARPHRD_IEEE802154 sounds more resonable. We don't care about the other stuff (means different types).

In short: I think "wdev->type != ARPHRD_IEEE802154" is a more likely case than "skb->pkt_type == PACKET_OTHERHOST".

- Alex

author maintainer
#15 lore raw

Re: [RFC 06/16] ieee802154: 6lowpan: trivial checks at first

In reply to Alexander Aring
Quoted 13 lines · Alexander Aring

This patch moves some trivial checks at first before calling skb_share_check which could do some memcpy if the buffer is shared.

---
 net/ieee802154/6lowpan/rx.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
net/ieee802154/6lowpan/rx.c +0 -0
index 7b6b038..11a5629 100644

net/ieee802154/6lowpan/rx.c static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev, · line 71

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +4 -0
@@ -62,16 +62,14 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 	struct ieee802154_hdr hdr;
 	int ret;
 
+	if (skb->pkt_type == PACKET_OTHERHOST ||
+	    wdev->type != ARPHRD_IEEE802154)
+		goto drop;
+
 	skb = skb_share_check(skb, GFP_ATOMIC);
 	if (!skb)
 		goto drop;

mhhh, nothing according to the patch but I think "skb_share_check" is wrong here and this depends on the dispatch value.

Why it's wrong?

When we do iphc_decompress we manipulate the buffer but "skb_share_check" unshare the "skb structure" only.

That's the different between skb_clone and skb_copy. skb_clone doesn't "copy" the buffer, the buffer is still shared afterwards when it's shared.

Sometimes like ipv6 dispatch we only run skb_pull, then we need "skb_share_check" only, because skb_pull doesn't manipulate the buffer, it's doing only some pointer moving inside "skb structure" so skb_clone if it's shared is enough, skb_clone is too much.

I would remove this from the lowpan_rcv and we need to care that this function does read_only on "skb buffer" and "skb structure", then we don't need to call anything.

To do "skb_share_check" (skb_clone if shared) or "skb_unshare" (skb_copy if shared), should be handled by the dispatch handlers lowpan_rx_h_ipv6, lowpan_rx_h_iphc, lowpan_rx_h_....

- Alex

author maintainer
#16 lore raw

RFC 7/16 ieee802154: 6lowpan: change skb->dev earlier

In reply to Alexander Aring

We should change the skb->dev pointer earlier to the lowpan interface. Sometimes we call iphc_decompress which also use some netdev printout functionality. This patch will change that the correct interface will be displayed in this case, which should be the lowpan interface.

---
 net/ieee802154/6lowpan/rx.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
net/ieee802154/6lowpan/rx.c +7 -7
index 11a5629..3871804a 100644
@@ -15,10 +15,8 @@
 
 #include "6lowpan_i.h"
 
-static int lowpan_give_skb_to_device(struct sk_buff *skb,
-				     struct net_device *wdev)
+static int lowpan_give_skb_to_device(struct sk_buff *skb)
 {
-	skb->dev = wdev->ieee802154_ptr->lowpan_dev;
 	skb->protocol = htons(ETH_P_IPV6);
 	skb->pkt_type = PACKET_HOST;
 
@@ -73,11 +71,13 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
 		goto drop_skb;
 
+	skb->dev = wdev->ieee802154_ptr->lowpan_dev;
+
 	/* check that it's our buffer */
 	if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
 		/* Pull off the 1-byte of 6lowpan header. */
 		skb_pull(skb, 1);
-		return lowpan_give_skb_to_device(skb, wdev);
+		return lowpan_give_skb_to_device(skb);
 	} else {
 		switch (skb->data[0] & 0xe0) {
 		case LOWPAN_DISPATCH_IPHC:	/* ipv6 datagram */
@@ -85,7 +85,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 			if (ret < 0)
 				goto drop_skb;
 
-			return lowpan_give_skb_to_device(skb, wdev);
+			return lowpan_give_skb_to_device(skb);
 		case LOWPAN_DISPATCH_FRAG1:	/* first fragment header */
 			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
 			if (ret == 1) {
@@ -93,7 +93,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 				if (ret < 0)
 					goto drop_skb;
 
-				return lowpan_give_skb_to_device(skb, wdev);
+				return lowpan_give_skb_to_device(skb);
 			} else if (ret == -1) {
 				return NET_RX_DROP;
 			} else {
@@ -106,7 +106,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 				if (ret < 0)
 					goto drop_skb;
 
-				return lowpan_give_skb_to_device(skb, wdev);
+				return lowpan_give_skb_to_device(skb);
 			} else if (ret == -1) {
 				return NET_RX_DROP;
 			} else {
Signature · 1 line
2.5.0
Reviewed-by on v1 7/16
#17 lore raw

Re: [RFC 07/16] ieee802154: 6lowpan: change skb->dev earlier

Hello.

Quoted 60 lines · Alexander Aring

We should change the skb->dev pointer earlier to the lowpan interface. Sometimes we call iphc_decompress which also use some netdev printout functionality. This patch will change that the correct interface will be displayed in this case, which should be the lowpan interface.

---
  net/ieee802154/6lowpan/rx.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
net/ieee802154/6lowpan/rx.c +6 -6
index 11a5629..3871804a 100644
@@ -15,10 +15,8 @@
 
  #include "6lowpan_i.h"
 
-static int lowpan_give_skb_to_device(struct sk_buff *skb,
-				     struct net_device *wdev)
+static int lowpan_give_skb_to_device(struct sk_buff *skb)
  {
-	skb->dev = wdev->ieee802154_ptr->lowpan_dev;
  	skb->protocol = htons(ETH_P_IPV6);
  	skb->pkt_type = PACKET_HOST;
 
@@ -73,11 +71,13 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
  	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
  		goto drop_skb;
 
+	skb->dev = wdev->ieee802154_ptr->lowpan_dev;
+
  	/* check that it's our buffer */
  	if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
  		/* Pull off the 1-byte of 6lowpan header. */
  		skb_pull(skb, 1);
-		return lowpan_give_skb_to_device(skb, wdev);
+		return lowpan_give_skb_to_device(skb);
  	} else {
  		switch (skb->data[0] & 0xe0) {
  		case LOWPAN_DISPATCH_IPHC:	/* ipv6 datagram */
@@ -85,7 +85,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
  			if (ret < 0)
  				goto drop_skb;
 
-			return lowpan_give_skb_to_device(skb, wdev);
+			return lowpan_give_skb_to_device(skb);
  		case LOWPAN_DISPATCH_FRAG1:	/* first fragment header */
  			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
  			if (ret == 1) {
@@ -93,7 +93,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
  				if (ret < 0)
  					goto drop_skb;
 
-				return lowpan_give_skb_to_device(skb, wdev);
+				return lowpan_give_skb_to_device(skb);
  			} else if (ret == -1) {
  				return NET_RX_DROP;
  			} else {

net/ieee802154/6lowpan/rx.c static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev, · line 112

Quoted 8 lines
net/ieee802154/6lowpan/rx.c +1 -1
@@ -106,7 +106,7 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
  				if (ret < 0)
  					goto drop_skb;
 
-				return lowpan_give_skb_to_device(skb, wdev);
+				return lowpan_give_skb_to_device(skb);
  			} else if (ret == -1) {
  				return NET_RX_DROP;
  			} else {

regards
Stefan Schmidt

author maintainer
#18 lore raw

RFC 8/16 ieee802154: 6lowpan: change frag return value handling

In reply to Alexander Aring

The function lowpan_frag_rcv does return only:

- "1": skb is reassmbled
- "-1": skb is putted into the frag bucket or failure.

Other values can't happend. This patch will change that we return on "1" the return value of netif_rx and "-1" to NET_RX_DROP, which means that the packet doesn't reach the next layer.

---
 net/ieee802154/6lowpan/rx.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
net/ieee802154/6lowpan/rx.c +4 -8
index 3871804a..bf6e857 100644
@@ -94,11 +94,9 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 					goto drop_skb;
 
 				return lowpan_give_skb_to_device(skb);
-			} else if (ret == -1) {
-				return NET_RX_DROP;
-			} else {
-				return NET_RX_SUCCESS;
 			}
+
+			return NET_RX_DROP;
 		case LOWPAN_DISPATCH_FRAGN:	/* next fragments headers */
 			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAGN);
 			if (ret == 1) {
@@ -107,11 +105,9 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 					goto drop_skb;
 
 				return lowpan_give_skb_to_device(skb);
-			} else if (ret == -1) {
-				return NET_RX_DROP;
-			} else {
-				return NET_RX_SUCCESS;
 			}
+
+			return NET_RX_DROP;
 		default:
 			break;
 		}
Signature · 1 line
2.5.0
#19 lore raw

Re: [RFC 08/16] ieee802154: 6lowpan: change frag return value handling

Hello.

Quoted 36 lines · Alexander Aring

The function lowpan_frag_rcv does return only:

- "1": skb is reassmbled
- "-1": skb is putted into the frag bucket or failure.

Other values can't happend. This patch will change that we return on "1" the return value of netif_rx and "-1" to NET_RX_DROP, which means that the packet doesn't reach the next layer.

---
  net/ieee802154/6lowpan/rx.c | 12 ++++--------
  1 file changed, 4 insertions(+), 8 deletions(-)
net/ieee802154/6lowpan/rx.c +2 -4
index 3871804a..bf6e857 100644
@@ -94,11 +94,9 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
  					goto drop_skb;
 
  				return lowpan_give_skb_to_device(skb);
-			} else if (ret == -1) {
-				return NET_RX_DROP;
-			} else {
-				return NET_RX_SUCCESS;
  			}
+
+			return NET_RX_DROP;
  		case LOWPAN_DISPATCH_FRAGN:	/* next fragments headers */
  			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAGN);
  			if (ret == 1) {
@@ -107,11 +105,9 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
  					goto drop_skb;
 
  				return lowpan_give_skb_to_device(skb);

net/ieee802154/6lowpan/rx.c static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev, · line 113

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +2 -4
-			} else if (ret == -1) {
-				return NET_RX_DROP;
-			} else {
-				return NET_RX_SUCCESS;
  			}
+
+			return NET_RX_DROP;
  		default:
  			break;
  		}

Looking at the next patch (9) to me it looks like this one could get folded in it as the part you change here gets a rewrite anyway.

regards
Stefan Schmidt

author maintainer
#20 lore raw

Re: [RFC 08/16] ieee802154: 6lowpan: change frag return value handling

Quoted 42 lines · Stefan Schmidt

Hello.

Quoted 39 lines · Alexander Aring

The function lowpan_frag_rcv does return only:

- "1": skb is reassmbled
- "-1": skb is putted into the frag bucket or failure.

Other values can't happend. This patch will change that we return on "1" the return value of netif_rx and "-1" to NET_RX_DROP, which means that the packet doesn't reach the next layer.

---
 net/ieee802154/6lowpan/rx.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
net/ieee802154/6lowpan/rx.c +2 -8
index 3871804a..bf6e857 100644
@@ -94,11 +94,9 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 					goto drop_skb;
 				return lowpan_give_skb_to_device(skb);
-			} else if (ret == -1) {
-				return NET_RX_DROP;
-			} else {
-				return NET_RX_SUCCESS;
 			}
+
+			return NET_RX_DROP;
 		case LOWPAN_DISPATCH_FRAGN:	/* next fragments headers */
 			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAGN);
 			if (ret == 1) {
@@ -107,11 +105,9 @@ static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 					goto drop_skb;
 				return lowpan_give_skb_to_device(skb);
-			} else if (ret == -1) {
-				return NET_RX_DROP;
-			} else {
-				return NET_RX_SUCCESS;
 			}
Quoted 9 lines

net/ieee802154/6lowpan/rx.c static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev, · line 113

Quoted 5 lines
net/ieee802154/6lowpan/rx.c +2 -0
+
+			return NET_RX_DROP;
 		default:
 			break;
 		}

Looking at the next patch (9) to me it looks like this one could get folded in it as the part you change here gets a rewrite anyway.

ok.

- Alex

author maintainer
#21 lore raw

RFC 9/16 ieee820154: 6lowpan: dispatch evaluation rework

In reply to Alexander Aring

This patch complete reworks the evaluation of 6lowpan dispatch value by introducing several different handlers for each dispatch value. This patch also fixes a bug to re-evaluate the dispatch value after reassmble while fragmentation. Currently we always assume that we have an IPHC header there.

---
 net/ieee802154/6lowpan/rx.c | 155 +++++++++++++++++++++++++++++---------------
 1 file changed, 101 insertions(+), 54 deletions(-)
net/ieee802154/6lowpan/rx.c +101 -54
index bf6e857..c7afd4a 100644
@@ -15,12 +15,42 @@
 
 #include "6lowpan_i.h"
 
+typedef unsigned __bitwise__ lowpan_rx_result;
+#define RX_CONTINUE		((__force lowpan_rx_result) 0u)
+#define RX_DROP_UNUSABLE	((__force lowpan_rx_result) 1u)
+#define RX_DROP			((__force lowpan_rx_result) 2u)
+#define RX_QUEUED		((__force lowpan_rx_result) 3u)
+
+static int
+lowpan_rx_handlers_result(struct sk_buff *skb, lowpan_rx_result res)
+{
+	switch (res) {
+	/* nobody cared about this packet */
+	case RX_CONTINUE:
+	case RX_DROP_UNUSABLE:
+		kfree_skb(skb);
+	case RX_DROP:
+		return NET_RX_DROP;
+	default:
+		break;
+	}
+
+	return NET_RX_SUCCESS;
+}
+
 static int lowpan_give_skb_to_device(struct sk_buff *skb)
 {
+	int ret;
+
 	skb->protocol = htons(ETH_P_IPV6);
 	skb->pkt_type = PACKET_HOST;
 
-	return netif_rx(skb);
+	ret = netif_rx(skb);
+	/* kfree_skb handled by netif_rx, so RX_DROP on failure */
+	if (ret == NET_RX_SUCCESS)
+		return RX_QUEUED;
+	else
+		return RX_DROP;
 }
 
 static int
@@ -54,69 +84,86 @@ iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
 					IEEE802154_ADDR_LEN, iphc0, iphc1);
 }
 
-static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
-		      struct packet_type *pt, struct net_device *orig_wdev)
+static lowpan_rx_result lowpan_rx_h_ipv6(struct sk_buff *skb)
+{
+	if (skb->data[0] != LOWPAN_DISPATCH_IPV6)
+		return RX_CONTINUE;
+
+	/* Pull off the 1-byte of 6lowpan header. */
+	skb_pull(skb, 1);
+	return lowpan_give_skb_to_device(skb);
+}
+
+static lowpan_rx_result lowpan_rx_h_frag(struct sk_buff *skb)
+{
+	int ret;
+
+	if ((skb->data[0] & 0xe0) != LOWPAN_DISPATCH_FRAG1 &&
+	    (skb->data[0] & 0xe0) != LOWPAN_DISPATCH_FRAGN)
+		return RX_CONTINUE;
+
+	ret = lowpan_frag_rcv(skb, skb->data[0] & 0xe0);
+	if (ret == 1)
+		return RX_CONTINUE;
+
+	/* packet is dropped and putted into the frag bucket only */
+	return RX_DROP;
+}
+
+static lowpan_rx_result lowpan_rx_h_iphc(struct sk_buff *skb)
 {
-	struct ieee802154_hdr hdr;
 	int ret;
+	struct ieee802154_hdr hdr;
+
+	if ((skb->data[0] & 0xe0) != LOWPAN_DISPATCH_IPHC)
+		return RX_CONTINUE;
+
+	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
+		return RX_DROP_UNUSABLE;
+
+	ret = iphc_decompress(skb, &hdr);
+	if (ret < 0)
+		return RX_DROP_UNUSABLE;
+
+	return lowpan_give_skb_to_device(skb);
+}
+
+int lowpan_invoke_rx_handlers(struct sk_buff *skb)
+{
+	lowpan_rx_result res;
+
+#define CALL_RXH(rxh)			\
+	do {				\
+		res = rxh(skb);		\
+		if (res != RX_CONTINUE)	\
+			goto rxh_next;	\
+	} while (0)
+
+	/* frag at first, because it contains dispatch value again */
+	CALL_RXH(lowpan_rx_h_frag);
 
+	/* likely at first */
+	CALL_RXH(lowpan_rx_h_iphc);
+	CALL_RXH(lowpan_rx_h_ipv6);
+
+rxh_next:
+	return lowpan_rx_handlers_result(skb, res);
+#undef CALL_RXH
+}
+
+static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
+		      struct packet_type *pt, struct net_device *orig_wdev)
+{
 	if (skb->pkt_type == PACKET_OTHERHOST ||
 	    wdev->type != ARPHRD_IEEE802154)
-		goto drop;
+		return NET_RX_DROP;
 
 	skb = skb_share_check(skb, GFP_ATOMIC);
 	if (!skb)
-		goto drop;
-
-	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
-		goto drop_skb;
+		return NET_RX_DROP;
 
 	skb->dev = wdev->ieee802154_ptr->lowpan_dev;
-
-	/* check that it's our buffer */
-	if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
-		/* Pull off the 1-byte of 6lowpan header. */
-		skb_pull(skb, 1);
-		return lowpan_give_skb_to_device(skb);
-	} else {
-		switch (skb->data[0] & 0xe0) {
-		case LOWPAN_DISPATCH_IPHC:	/* ipv6 datagram */
-			ret = iphc_decompress(skb, &hdr);
-			if (ret < 0)
-				goto drop_skb;
-
-			return lowpan_give_skb_to_device(skb);
-		case LOWPAN_DISPATCH_FRAG1:	/* first fragment header */
-			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
-			if (ret == 1) {
-				ret = iphc_decompress(skb, &hdr);
-				if (ret < 0)
-					goto drop_skb;
-
-				return lowpan_give_skb_to_device(skb);
-			}
-
-			return NET_RX_DROP;
-		case LOWPAN_DISPATCH_FRAGN:	/* next fragments headers */
-			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAGN);
-			if (ret == 1) {
-				ret = iphc_decompress(skb, &hdr);
-				if (ret < 0)
-					goto drop_skb;
-
-				return lowpan_give_skb_to_device(skb);
-			}
-
-			return NET_RX_DROP;
-		default:
-			break;
-		}
-	}
-
-drop_skb:
-	kfree_skb(skb);
-drop:
-	return NET_RX_DROP;
+	return lowpan_invoke_rx_handlers(skb);
 }
 
 static struct packet_type lowpan_packet_type = {
Signature · 1 line
2.5.0
Reviewed-by on v1 9/16
#22 lore raw

Re: [RFC 09/16] ieee820154: 6lowpan: dispatch evaluation rework

Hello.

Quoted 74 lines · Alexander Aring

This patch complete reworks the evaluation of 6lowpan dispatch value by introducing several different handlers for each dispatch value. This patch also fixes a bug to re-evaluate the dispatch value after reassmble while fragmentation. Currently we always assume that we have an IPHC header there.

---
  net/ieee802154/6lowpan/rx.c | 155 +++++++++++++++++++++++++++++---------------
  1 file changed, 101 insertions(+), 54 deletions(-)
net/ieee802154/6lowpan/rx.c +40 -3
index bf6e857..c7afd4a 100644
@@ -15,12 +15,42 @@
 
  #include "6lowpan_i.h"
 
+typedef unsigned __bitwise__ lowpan_rx_result;
+#define RX_CONTINUE		((__force lowpan_rx_result) 0u)
+#define RX_DROP_UNUSABLE	((__force lowpan_rx_result) 1u)
+#define RX_DROP			((__force lowpan_rx_result) 2u)
+#define RX_QUEUED		((__force lowpan_rx_result) 3u)
+
+static int
+lowpan_rx_handlers_result(struct sk_buff *skb, lowpan_rx_result res)
+{
+	switch (res) {
+	/* nobody cared about this packet */
+	case RX_CONTINUE:
+	case RX_DROP_UNUSABLE:
+		kfree_skb(skb);
+	case RX_DROP:
+		return NET_RX_DROP;
+	default:
+		break;
+	}
+
+	return NET_RX_SUCCESS;
+}
+
  static int lowpan_give_skb_to_device(struct sk_buff *skb)
  {
+	int ret;
+
  	skb->protocol = htons(ETH_P_IPV6);
  	skb->pkt_type = PACKET_HOST;
 
-	return netif_rx(skb);
+	ret = netif_rx(skb);
+	/* kfree_skb handled by netif_rx, so RX_DROP on failure */
+	if (ret == NET_RX_SUCCESS)
+		return RX_QUEUED;
+	else
+		return RX_DROP;
  }
 
  static int
@@ -54,69 +84,86 @@ iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
  					IEEE802154_ADDR_LEN, iphc0, iphc1);
  }
 
-static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
-		      struct packet_type *pt, struct net_device *orig_wdev)
+static lowpan_rx_result lowpan_rx_h_ipv6(struct sk_buff *skb)
+{
+	if (skb->data[0] != LOWPAN_DISPATCH_IPV6)
+		return RX_CONTINUE;
+
+	/* Pull off the 1-byte of 6lowpan header. */
+	skb_pull(skb, 1);
+	return lowpan_give_skb_to_device(skb);
+}

net/ieee802154/6lowpan/rx.c iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr) · line 105

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +10 -0
+
+static lowpan_rx_result lowpan_rx_h_frag(struct sk_buff *skb)
+{
+	int ret;
+
+	if ((skb->data[0] & 0xe0) != LOWPAN_DISPATCH_FRAG1 &&
+	    (skb->data[0] & 0xe0) != LOWPAN_DISPATCH_FRAGN)
+		return RX_CONTINUE;
+
+	ret = lowpan_frag_rcv(skb, skb->data[0] & 0xe0);

You fix this mask in patch 11 later one. Maybe its worth merging this fix in here? At least using 0xf8 as you only introduce the LOWPAN_DISPATCH_FRAG_MASK in patch 10.

Nothing to problematic but I always wonder about such things when I see a fix later in a series which was introduced/already touched earlier in the series.

net/ieee802154/6lowpan/rx.c iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr) · line 109

Quoted 4 lines
net/ieee802154/6lowpan/rx.c +4 -0
+	if (ret == 1)
+		return RX_CONTINUE;
+
+	/* packet is dropped and putted into the frag bucket only */

s/putted/put/

net/ieee802154/6lowpan/rx.c iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr) · line 118

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +7 -1
+	return RX_DROP;
+}
+
+static lowpan_rx_result lowpan_rx_h_iphc(struct sk_buff *skb)
  {
-	struct ieee802154_hdr hdr;
  	int ret;
+	struct ieee802154_hdr hdr;
+
+	if ((skb->data[0] & 0xe0) != LOWPAN_DISPATCH_IPHC)

All this use of 0xe0 is a bit annoying as the se magic value misses a real meaning. Luckily I have just seen that you clean this up in the next patch and it only is here as you broke up the code below into pieces. Just keep it as patch 10 fixes this.

Quoted 91 lines
net/ieee802154/6lowpan/rx.c +39 -44
+		return RX_CONTINUE;
+
+	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
+		return RX_DROP_UNUSABLE;
+
+	ret = iphc_decompress(skb, &hdr);
+	if (ret < 0)
+		return RX_DROP_UNUSABLE;
+
+	return lowpan_give_skb_to_device(skb);
+}
+
+int lowpan_invoke_rx_handlers(struct sk_buff *skb)
+{
+	lowpan_rx_result res;
+
+#define CALL_RXH(rxh)			\
+	do {				\
+		res = rxh(skb);		\
+		if (res != RX_CONTINUE)	\
+			goto rxh_next;	\
+	} while (0)
+
+	/* frag at first, because it contains dispatch value again */
+	CALL_RXH(lowpan_rx_h_frag);
 
+	/* likely at first */
+	CALL_RXH(lowpan_rx_h_iphc);
+	CALL_RXH(lowpan_rx_h_ipv6);
+
+rxh_next:
+	return lowpan_rx_handlers_result(skb, res);
+#undef CALL_RXH
+}
+
+static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
+		      struct packet_type *pt, struct net_device *orig_wdev)
+{
  	if (skb->pkt_type == PACKET_OTHERHOST ||
  	    wdev->type != ARPHRD_IEEE802154)
-		goto drop;
+		return NET_RX_DROP;
 
  	skb = skb_share_check(skb, GFP_ATOMIC);
  	if (!skb)
-		goto drop;
-
-	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
-		goto drop_skb;
+		return NET_RX_DROP;
 
  	skb->dev = wdev->ieee802154_ptr->lowpan_dev;
-
-	/* check that it's our buffer */
-	if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
-		/* Pull off the 1-byte of 6lowpan header. */
-		skb_pull(skb, 1);
-		return lowpan_give_skb_to_device(skb);
-	} else {
-		switch (skb->data[0] & 0xe0) {
-		case LOWPAN_DISPATCH_IPHC:	/* ipv6 datagram */
-			ret = iphc_decompress(skb, &hdr);
-			if (ret < 0)
-				goto drop_skb;
-
-			return lowpan_give_skb_to_device(skb);
-		case LOWPAN_DISPATCH_FRAG1:	/* first fragment header */
-			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
-			if (ret == 1) {
-				ret = iphc_decompress(skb, &hdr);
-				if (ret < 0)
-					goto drop_skb;
-
-				return lowpan_give_skb_to_device(skb);
-			}
-
-			return NET_RX_DROP;
-		case LOWPAN_DISPATCH_FRAGN:	/* next fragments headers */
-			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAGN);
-			if (ret == 1) {
-				ret = iphc_decompress(skb, &hdr);
-				if (ret < 0)
-					goto drop_skb;
-
-				return lowpan_give_skb_to_device(skb);
-			}
-
-			return NET_RX_DROP;
-		default:
-			break;
-		}

net/ieee802154/6lowpan/rx.c iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr) · line 169

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +1 -6
-	}
-
-drop_skb:
-	kfree_skb(skb);
-drop:
-	return NET_RX_DROP;
+	return lowpan_invoke_rx_handlers(skb);
  }
 
  static struct packet_type lowpan_packet_type = {

regards
Stefan Schmidt

author maintainer
#23 lore raw

RFC 10/16 ieee802154: 6lowpan: add dispatch evalualtion helpers

In reply to Alexander Aring

This patch introduce some static inline function for checking the right dispatch value. This also fixes an bug to detect the right fragmentation dispatch value, we currently use "0xe0" as masking the fragmentation dispatch. Correct is "0xf8" as mask.

---
 include/net/6lowpan.h              | 18 +++++++++++++-----
 net/ieee802154/6lowpan/6lowpan_i.h |  3 +++
 net/ieee802154/6lowpan/rx.c        | 30 +++++++++++++++++++++++++-----
 3 files changed, 41 insertions(+), 10 deletions(-)
include/net/6lowpan.h +13 -5
index e16763f..073c791 100644
@@ -126,11 +126,19 @@
 	 (((a)[6]) == 0xFF) &&	\
 	 (((a)[7]) == 0xFF))
 
-#define LOWPAN_DISPATCH_IPV6	0x41 /* 01000001 = 65 */
-#define LOWPAN_DISPATCH_HC1	0x42 /* 01000010 = 66 */
-#define LOWPAN_DISPATCH_IPHC	0x60 /* 011xxxxx = ... */
-#define LOWPAN_DISPATCH_FRAG1	0xc0 /* 11000xxx */
-#define LOWPAN_DISPATCH_FRAGN	0xe0 /* 11100xxx */
+#define LOWPAN_DISPATCH_IPV6		0x41 /* 01000001 = 65 */
+#define LOWPAN_DISPATCH_IPHC		0x60 /* 011xxxxx = ... */
+#define LOWPAN_DISPATCH_IPHC_MASK	0xe0
+
+static inline bool lowpan_is_ipv6(u8 dispatch)
+{
+	return dispatch == LOWPAN_DISPATCH_IPV6;
+}
+
+static inline bool lowpan_is_iphc(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_IPHC_MASK) == LOWPAN_DISPATCH_IPHC;
+}
 
 #define LOWPAN_DISPATCH_MASK	0xf8 /* 11111000 */
 
net/ieee802154/6lowpan/6lowpan_i.h +3 -0
index d62046e..e009a4a 100644
@@ -7,6 +7,9 @@
 #include <net/inet_frag.h>
 #include <net/6lowpan.h>
 
+#define LOWPAN_DISPATCH_FRAG1		0xc0
+#define LOWPAN_DISPATCH_FRAGN		0xe0
+
 struct lowpan_create_arg {
 	u16 tag;
 	u16 d_size;
net/ieee802154/6lowpan/rx.c +25 -5
index c7afd4a..b0066b7 100644
@@ -21,6 +21,16 @@ typedef unsigned __bitwise__ lowpan_rx_result;
 #define RX_DROP			((__force lowpan_rx_result) 2u)
 #define RX_QUEUED		((__force lowpan_rx_result) 3u)
 
+#define LOWPAN_DISPATCH_FIRST		0xc0
+#define LOWPAN_DISPATCH_FRAG_MASK	0xf8
+#define LOWPAN_DISPATCH_IPHC_MASK	0xe0
+
+#define LOWPAN_DISPATCH_NALP		0x00
+#define LOWPAN_DISPATCH_HC1		0x42
+#define LOWPAN_DISPATCH_BC0		0x50
+#define LOWPAN_DISPATCH_ESC		0x7f
+#define LOWPAN_DISPATCH_MESH		0x80
+
 static int
 lowpan_rx_handlers_result(struct sk_buff *skb, lowpan_rx_result res)
 {
@@ -86,7 +96,7 @@ iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
 
 static lowpan_rx_result lowpan_rx_h_ipv6(struct sk_buff *skb)
 {
-	if (skb->data[0] != LOWPAN_DISPATCH_IPV6)
+	if (!lowpan_is_ipv6(*skb_network_header(skb)))
 		return RX_CONTINUE;
 
 	/* Pull off the 1-byte of 6lowpan header. */
@@ -94,15 +104,25 @@ static lowpan_rx_result lowpan_rx_h_ipv6(struct sk_buff *skb)
 	return lowpan_give_skb_to_device(skb);
 }
 
+static inline bool lowpan_is_frag1(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_FRAG_MASK) == LOWPAN_DISPATCH_FRAG1;
+}
+
+static inline bool lowpan_is_fragn(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_FRAG_MASK) == LOWPAN_DISPATCH_FRAGN;
+}
+
 static lowpan_rx_result lowpan_rx_h_frag(struct sk_buff *skb)
 {
 	int ret;
 
-	if ((skb->data[0] & 0xe0) != LOWPAN_DISPATCH_FRAG1 &&
-	    (skb->data[0] & 0xe0) != LOWPAN_DISPATCH_FRAGN)
+	if (!(lowpan_is_frag1(*skb_network_header(skb)) ||
+	      lowpan_is_fragn(*skb_network_header(skb))))
 		return RX_CONTINUE;
 
-	ret = lowpan_frag_rcv(skb, skb->data[0] & 0xe0);
+	ret = lowpan_frag_rcv(skb, *skb_network_header(skb) & 0xe0);
 	if (ret == 1)
 		return RX_CONTINUE;
 
@@ -115,7 +135,7 @@ static lowpan_rx_result lowpan_rx_h_iphc(struct sk_buff *skb)
 	int ret;
 	struct ieee802154_hdr hdr;
 
-	if ((skb->data[0] & 0xe0) != LOWPAN_DISPATCH_IPHC)
+	if (!lowpan_is_iphc(*skb_network_header(skb)))
 		return RX_CONTINUE;
 
 	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
Signature · 1 line
2.5.0
Reviewed-by on v1 10/16
#24 lore raw

Re: [RFC 10/16] ieee802154: 6lowpan: add dispatch evalualtion helpers

Hello.

typo in subject. s/evalualtion/evaluation/

Quoted 63 lines · Alexander Aring

This patch introduce some static inline function for checking the right dispatch value. This also fixes an bug to detect the right fragmentation dispatch value, we currently use "0xe0" as masking the fragmentation dispatch. Correct is "0xf8" as mask.

---
  include/net/6lowpan.h              | 18 +++++++++++++-----
  net/ieee802154/6lowpan/6lowpan_i.h |  3 +++
  net/ieee802154/6lowpan/rx.c        | 30 +++++++++++++++++++++++++-----
  3 files changed, 41 insertions(+), 10 deletions(-)
include/net/6lowpan.h +13 -5
index e16763f..073c791 100644
@@ -126,11 +126,19 @@
  	 (((a)[6]) == 0xFF) &&	\
  	 (((a)[7]) == 0xFF))
 
-#define LOWPAN_DISPATCH_IPV6	0x41 /* 01000001 = 65 */
-#define LOWPAN_DISPATCH_HC1	0x42 /* 01000010 = 66 */
-#define LOWPAN_DISPATCH_IPHC	0x60 /* 011xxxxx = ... */
-#define LOWPAN_DISPATCH_FRAG1	0xc0 /* 11000xxx */
-#define LOWPAN_DISPATCH_FRAGN	0xe0 /* 11100xxx */
+#define LOWPAN_DISPATCH_IPV6		0x41 /* 01000001 = 65 */
+#define LOWPAN_DISPATCH_IPHC		0x60 /* 011xxxxx = ... */
+#define LOWPAN_DISPATCH_IPHC_MASK	0xe0
+
+static inline bool lowpan_is_ipv6(u8 dispatch)
+{
+	return dispatch == LOWPAN_DISPATCH_IPV6;
+}
+
+static inline bool lowpan_is_iphc(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_IPHC_MASK) == LOWPAN_DISPATCH_IPHC;
+}
 
  #define LOWPAN_DISPATCH_MASK	0xf8 /* 11111000 */
 
net/ieee802154/6lowpan/6lowpan_i.h +3 -0
index d62046e..e009a4a 100644
@@ -7,6 +7,9 @@
  #include <net/inet_frag.h>
  #include <net/6lowpan.h>
 
+#define LOWPAN_DISPATCH_FRAG1		0xc0
+#define LOWPAN_DISPATCH_FRAGN		0xe0
+
  struct lowpan_create_arg {
  	u16 tag;
  	u16 d_size;
net/ieee802154/6lowpan/rx.c +0 -0
index c7afd4a..b0066b7 100644
@@ -21,6 +21,16 @@ typedef unsigned __bitwise__ lowpan_rx_result;
  #define RX_DROP			((__force lowpan_rx_result) 2u)
  #define RX_QUEUED		((__force lowpan_rx_result) 3u)
 

net/ieee802154/6lowpan/rx.c typedef unsigned __bitwise__ lowpan_rx_result; · line 33

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +10 -0
+#define LOWPAN_DISPATCH_FIRST		0xc0
+#define LOWPAN_DISPATCH_FRAG_MASK	0xf8
+#define LOWPAN_DISPATCH_IPHC_MASK	0xe0
+
+#define LOWPAN_DISPATCH_NALP		0x00
+#define LOWPAN_DISPATCH_HC1		0x42
+#define LOWPAN_DISPATCH_BC0		0x50
+#define LOWPAN_DISPATCH_ESC		0x7f
+#define LOWPAN_DISPATCH_MESH		0x80
+

Any specific reason you moved the *_HC1 define here (same for the *_FRAG defines above)?

I would think having them all in 6lowpan.h would make most sense. You might need them only in this file for now but later one maybe in another file. It could be personal taste but having them all in one place should be easier. imho.

Quoted 42 lines
net/ieee802154/6lowpan/rx.c +14 -4
  static int
  lowpan_rx_handlers_result(struct sk_buff *skb, lowpan_rx_result res)
  {
@@ -86,7 +96,7 @@ iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
 
  static lowpan_rx_result lowpan_rx_h_ipv6(struct sk_buff *skb)
  {
-	if (skb->data[0] != LOWPAN_DISPATCH_IPV6)
+	if (!lowpan_is_ipv6(*skb_network_header(skb)))
  		return RX_CONTINUE;
 
  	/* Pull off the 1-byte of 6lowpan header. */
@@ -94,15 +104,25 @@ static lowpan_rx_result lowpan_rx_h_ipv6(struct sk_buff *skb)
  	return lowpan_give_skb_to_device(skb);
  }
 
+static inline bool lowpan_is_frag1(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_FRAG_MASK) == LOWPAN_DISPATCH_FRAG1;
+}
+
+static inline bool lowpan_is_fragn(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_FRAG_MASK) == LOWPAN_DISPATCH_FRAGN;
+}
+
  static lowpan_rx_result lowpan_rx_h_frag(struct sk_buff *skb)
  {
  	int ret;
 
-	if ((skb->data[0] & 0xe0) != LOWPAN_DISPATCH_FRAG1 &&
-	    (skb->data[0] & 0xe0) != LOWPAN_DISPATCH_FRAGN)
+	if (!(lowpan_is_frag1(*skb_network_header(skb)) ||
+	      lowpan_is_fragn(*skb_network_header(skb))))
  		return RX_CONTINUE;
 
-	ret = lowpan_frag_rcv(skb, skb->data[0] & 0xe0);
+	ret = lowpan_frag_rcv(skb, *skb_network_header(skb) & 0xe0);
  	if (ret == 1)
  		return RX_CONTINUE;
 

net/ieee802154/6lowpan/rx.c static lowpan_rx_result lowpan_rx_h_iphc(struct sk_buff *skb) · line 141

Quoted 8 lines
net/ieee802154/6lowpan/rx.c +1 -1
@@ -115,7 +135,7 @@ static lowpan_rx_result lowpan_rx_h_iphc(struct sk_buff *skb)
  	int ret;
  	struct ieee802154_hdr hdr;
 
-	if ((skb->data[0] & 0xe0) != LOWPAN_DISPATCH_IPHC)
+	if (!lowpan_is_iphc(*skb_network_header(skb)))
  		return RX_CONTINUE;
 
  	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)

regards
Stefan Schmidt

6lowpan.h

author maintainer
#25 lore raw

Re: [RFC 10/16] ieee802154: 6lowpan: add dispatch evalualtion helpers

Quoted 4 lines · Stefan Schmidt

Hello.

typo in subject. s/evalualtion/evaluation/

ok.

Quoted 73 lines · Alexander Aring
Quoted 58 lines

This patch introduce some static inline function for checking the right dispatch value. This also fixes an bug to detect the right fragmentation dispatch value, we currently use "0xe0" as masking the fragmentation dispatch. Correct is "0xf8" as mask.

---
 include/net/6lowpan.h              | 18 +++++++++++++-----
 net/ieee802154/6lowpan/6lowpan_i.h |  3 +++
 net/ieee802154/6lowpan/rx.c        | 30 +++++++++++++++++++++++++-----
 3 files changed, 41 insertions(+), 10 deletions(-)
include/net/6lowpan.h +13 -5
index e16763f..073c791 100644
@@ -126,11 +126,19 @@
 	 (((a)[6]) == 0xFF) &&	\
 	 (((a)[7]) == 0xFF))
-#define LOWPAN_DISPATCH_IPV6	0x41 /* 01000001 = 65 */
-#define LOWPAN_DISPATCH_HC1	0x42 /* 01000010 = 66 */
-#define LOWPAN_DISPATCH_IPHC	0x60 /* 011xxxxx = ... */
-#define LOWPAN_DISPATCH_FRAG1	0xc0 /* 11000xxx */
-#define LOWPAN_DISPATCH_FRAGN	0xe0 /* 11100xxx */
+#define LOWPAN_DISPATCH_IPV6		0x41 /* 01000001 = 65 */
+#define LOWPAN_DISPATCH_IPHC		0x60 /* 011xxxxx = ... */
+#define LOWPAN_DISPATCH_IPHC_MASK	0xe0
+
+static inline bool lowpan_is_ipv6(u8 dispatch)
+{
+	return dispatch == LOWPAN_DISPATCH_IPV6;
+}
+
+static inline bool lowpan_is_iphc(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_IPHC_MASK) == LOWPAN_DISPATCH_IPHC;
+}
 #define LOWPAN_DISPATCH_MASK	0xf8 /* 11111000 */
net/ieee802154/6lowpan/6lowpan_i.h +3 -0
index d62046e..e009a4a 100644
@@ -7,6 +7,9 @@
 #include <net/inet_frag.h>
 #include <net/6lowpan.h>
+#define LOWPAN_DISPATCH_FRAG1		0xc0
+#define LOWPAN_DISPATCH_FRAGN		0xe0
+
 struct lowpan_create_arg {
 	u16 tag;
 	u16 d_size;
net/ieee802154/6lowpan/rx.c +0 -0
index c7afd4a..b0066b7 100644
@@ -21,6 +21,16 @@ typedef unsigned __bitwise__ lowpan_rx_result;
 #define RX_DROP			((__force lowpan_rx_result) 2u)
 #define RX_QUEUED		((__force lowpan_rx_result) 3u)

net/ieee802154/6lowpan/rx.c typedef unsigned __bitwise__ lowpan_rx_result; · line 32

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +10 -0
+#define LOWPAN_DISPATCH_FIRST		0xc0
+#define LOWPAN_DISPATCH_FRAG_MASK	0xf8
+#define LOWPAN_DISPATCH_IPHC_MASK	0xe0
+
+#define LOWPAN_DISPATCH_NALP		0x00
+#define LOWPAN_DISPATCH_HC1		0x42
+#define LOWPAN_DISPATCH_BC0		0x50
+#define LOWPAN_DISPATCH_ESC		0x7f
+#define LOWPAN_DISPATCH_MESH		0x80
+

Any specific reason you moved the *_HC1 define here (same for the *_FRAG defines above)?

Quoted 4 lines

I would think having them all in 6lowpan.h would make most sense. You might need them only in this file for now but later one maybe in another file. It could be personal taste but having them all in one place should be easier. imho.

There exists 6LoWPAN functionality which is shared between BTLE 6LoWPAN and IEEE 802.15.4 6LoWPAN, these are:

- IPHC
- IPV6

they use both the same dispatch values.

The file "include/net/6lowpan.h" is part of the generic 6LoWPAN branch, so functionality which belongs to "IPHC" and "IPv6" (IPv6 dispatch is the easiest dispatch, there is only maybe this one inline function).

The other dispatches are not defined for BTLE, e.g. fragmentation is handled by MAC layer of BTLE so far I know. Also HC1 is not defined for BTLE 6LoWPAN.

HC1 is also deprecated, I think there will come no other 6LoWPAN standard which supports this format. (IPHC is the replacement, See [0], "MAY implement decompression according to Section 10 of [RFC4944] but
SHOULD NOT send packets compressed according to.." with otherwords we
should support receiving of HC1 but not sending HC1 anymore.)

If there comming new 6LoWPAN standards then we can later move these dispatch values to generic 6LoWPAN branch (and maybe more, like fragmentation framework) if they share these dispatches and also implement if it looks almost the same.

Nevertheless 6LoWPAN things which is not shared between two or more link-layer 6LoWPAN types should NOT go into the 6LoWPAN generic branch.

btw:
This is currently not true, "net/include/6lowpan.h" contains some defines which we should put into net/6lowpan/iphc.c (all IPHC defines which is used inside "iphc.c") and some things which are used in 802.15.4 6LoWPAN only.

This is all currently not clear and we need some another round for this to cleanup. (Usually I do send patch-series under 25 patches to have some milestones).

- Alex

[0] https://tools.ietf.org/html/rfc6282#section-2

#26 lore raw

Re: [RFC 10/16] ieee802154: 6lowpan: add dispatch evalualtion helpers

Hello.

Quoted 91 lines · Alexander Aring
Quoted 4 lines · Stefan Schmidt

Hello.

typo in subject. s/evalualtion/evaluation/

ok.

Quoted 72 lines · Alexander Aring
Quoted 58 lines

This patch introduce some static inline function for checking the right dispatch value. This also fixes an bug to detect the right fragmentation dispatch value, we currently use "0xe0" as masking the fragmentation dispatch. Correct is "0xf8" as mask.

---
  include/net/6lowpan.h              | 18 +++++++++++++-----
  net/ieee802154/6lowpan/6lowpan_i.h |  3 +++
  net/ieee802154/6lowpan/rx.c        | 30 +++++++++++++++++++++++++-----
  3 files changed, 41 insertions(+), 10 deletions(-)
include/net/6lowpan.h +13 -5
index e16763f..073c791 100644
@@ -126,11 +126,19 @@
  	 (((a)[6]) == 0xFF) &&	\
  	 (((a)[7]) == 0xFF))
-#define LOWPAN_DISPATCH_IPV6	0x41 /* 01000001 = 65 */
-#define LOWPAN_DISPATCH_HC1	0x42 /* 01000010 = 66 */
-#define LOWPAN_DISPATCH_IPHC	0x60 /* 011xxxxx = ... */
-#define LOWPAN_DISPATCH_FRAG1	0xc0 /* 11000xxx */
-#define LOWPAN_DISPATCH_FRAGN	0xe0 /* 11100xxx */
+#define LOWPAN_DISPATCH_IPV6		0x41 /* 01000001 = 65 */
+#define LOWPAN_DISPATCH_IPHC		0x60 /* 011xxxxx = ... */
+#define LOWPAN_DISPATCH_IPHC_MASK	0xe0
+
+static inline bool lowpan_is_ipv6(u8 dispatch)
+{
+	return dispatch == LOWPAN_DISPATCH_IPV6;
+}
+
+static inline bool lowpan_is_iphc(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_IPHC_MASK) == LOWPAN_DISPATCH_IPHC;
+}
  #define LOWPAN_DISPATCH_MASK	0xf8 /* 11111000 */
net/ieee802154/6lowpan/6lowpan_i.h +3 -0
index d62046e..e009a4a 100644
@@ -7,6 +7,9 @@
  #include <net/inet_frag.h>
  #include <net/6lowpan.h>
+#define LOWPAN_DISPATCH_FRAG1		0xc0
+#define LOWPAN_DISPATCH_FRAGN		0xe0
+
  struct lowpan_create_arg {
  	u16 tag;
  	u16 d_size;
net/ieee802154/6lowpan/rx.c +0 -0
index c7afd4a..b0066b7 100644
@@ -21,6 +21,16 @@ typedef unsigned __bitwise__ lowpan_rx_result;
  #define RX_DROP			((__force lowpan_rx_result) 2u)
  #define RX_QUEUED		((__force lowpan_rx_result) 3u)

net/ieee802154/6lowpan/rx.c typedef unsigned __bitwise__ lowpan_rx_result; · line 32

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +10 -0
+#define LOWPAN_DISPATCH_FIRST		0xc0
+#define LOWPAN_DISPATCH_FRAG_MASK	0xf8
+#define LOWPAN_DISPATCH_IPHC_MASK	0xe0
+
+#define LOWPAN_DISPATCH_NALP		0x00
+#define LOWPAN_DISPATCH_HC1		0x42
+#define LOWPAN_DISPATCH_BC0		0x50
+#define LOWPAN_DISPATCH_ESC		0x7f
+#define LOWPAN_DISPATCH_MESH		0x80
+

Any specific reason you moved the *_HC1 define here (same for the *_FRAG defines above)?

Quoted 4 lines

I would think having them all in 6lowpan.h would make most sense. You might need them only in this file for now but later one maybe in another file. It could be personal taste but having them all in one place should be easier. imho.

There exists 6LoWPAN functionality which is shared between BTLE 6LoWPAN and IEEE 802.15.4 6LoWPAN, these are:

- IPHC
- IPV6

they use both the same dispatch values.

Quoted 8 lines

The file "include/net/6lowpan.h" is part of the generic 6LoWPAN branch, so functionality which belongs to "IPHC" and "IPv6" (IPv6 dispatch is the easiest dispatch, there is only maybe this one inline function).

The other dispatches are not defined for BTLE, e.g. fragmentation is handled by MAC layer of BTLE so far I know. Also HC1 is not defined for BTLE 6LoWPAN.

Ah, now I understand why you keep them separate. Just keep it like you have in this case.

regards
Stefan Schmidt

author maintainer
#27 lore raw

Re: [RFC 10/16] ieee802154: 6lowpan: add dispatch evalualtion helpers

Quoted 99 lines · Stefan Schmidt

Hello.

Quoted 96 lines · Alexander Aring
Quoted 4 lines · Stefan Schmidt

Hello.

typo in subject. s/evalualtion/evaluation/

ok.

Quoted 72 lines · Alexander Aring
Quoted 58 lines

This patch introduce some static inline function for checking the right dispatch value. This also fixes an bug to detect the right fragmentation dispatch value, we currently use "0xe0" as masking the fragmentation dispatch. Correct is "0xf8" as mask.

---
 include/net/6lowpan.h              | 18 +++++++++++++-----
 net/ieee802154/6lowpan/6lowpan_i.h |  3 +++
 net/ieee802154/6lowpan/rx.c        | 30 +++++++++++++++++++++++++-----
 3 files changed, 41 insertions(+), 10 deletions(-)
include/net/6lowpan.h +13 -5
index e16763f..073c791 100644
@@ -126,11 +126,19 @@
 	 (((a)[6]) == 0xFF) &&	\
 	 (((a)[7]) == 0xFF))
-#define LOWPAN_DISPATCH_IPV6	0x41 /* 01000001 = 65 */
-#define LOWPAN_DISPATCH_HC1	0x42 /* 01000010 = 66 */
-#define LOWPAN_DISPATCH_IPHC	0x60 /* 011xxxxx = ... */
-#define LOWPAN_DISPATCH_FRAG1	0xc0 /* 11000xxx */
-#define LOWPAN_DISPATCH_FRAGN	0xe0 /* 11100xxx */
+#define LOWPAN_DISPATCH_IPV6		0x41 /* 01000001 = 65 */
+#define LOWPAN_DISPATCH_IPHC		0x60 /* 011xxxxx = ... */
+#define LOWPAN_DISPATCH_IPHC_MASK	0xe0
+
+static inline bool lowpan_is_ipv6(u8 dispatch)
+{
+	return dispatch == LOWPAN_DISPATCH_IPV6;
+}
+
+static inline bool lowpan_is_iphc(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_IPHC_MASK) == LOWPAN_DISPATCH_IPHC;
+}
 #define LOWPAN_DISPATCH_MASK	0xf8 /* 11111000 */
net/ieee802154/6lowpan/6lowpan_i.h +3 -0
index d62046e..e009a4a 100644
@@ -7,6 +7,9 @@
 #include <net/inet_frag.h>
 #include <net/6lowpan.h>
+#define LOWPAN_DISPATCH_FRAG1		0xc0
+#define LOWPAN_DISPATCH_FRAGN		0xe0
+
 struct lowpan_create_arg {
 	u16 tag;
 	u16 d_size;
net/ieee802154/6lowpan/rx.c +0 -0
index c7afd4a..b0066b7 100644
@@ -21,6 +21,16 @@ typedef unsigned __bitwise__ lowpan_rx_result;
 #define RX_DROP			((__force lowpan_rx_result) 2u)
 #define RX_QUEUED		((__force lowpan_rx_result) 3u)

net/ieee802154/6lowpan/rx.c typedef unsigned __bitwise__ lowpan_rx_result; · line 32

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +10 -0
+#define LOWPAN_DISPATCH_FIRST		0xc0
+#define LOWPAN_DISPATCH_FRAG_MASK	0xf8
+#define LOWPAN_DISPATCH_IPHC_MASK	0xe0
+
+#define LOWPAN_DISPATCH_NALP		0x00
+#define LOWPAN_DISPATCH_HC1		0x42
+#define LOWPAN_DISPATCH_BC0		0x50
+#define LOWPAN_DISPATCH_ESC		0x7f
+#define LOWPAN_DISPATCH_MESH		0x80
+

Any specific reason you moved the *_HC1 define here (same for the *_FRAG defines above)?

Quoted 4 lines

I would think having them all in 6lowpan.h would make most sense. You might need them only in this file for now but later one maybe in another file. It could be personal taste but having them all in one place should be easier. imho.

There exists 6LoWPAN functionality which is shared between BTLE 6LoWPAN and IEEE 802.15.4 6LoWPAN, these are:

- IPHC
- IPV6

they use both the same dispatch values.

The file "include/net/6lowpan.h" is part of the generic 6LoWPAN branch, so functionality which belongs to "IPHC" and "IPv6" (IPv6 dispatch is the easiest dispatch, there is only maybe this one inline function).

Quoted 7 lines
Quoted 3 lines

The other dispatches are not defined for BTLE, e.g. fragmentation is handled by MAC layer of BTLE so far I know. Also HC1 is not defined for BTLE 6LoWPAN.

Ah, now I understand why you keep them separate. Just keep it like you have in this case.

yes, I should be more clearly at the commit messages. Writing code is for me easier than writing commit messages according to the patch.

I will add some notes about that in the commit message.

- Alex

author maintainer
#28 lore raw

RFC 11/16 ieee802154: 6lowpan: fix fragmentation dispatch mask

In reply to Alexander Aring

This patch fix the dispatch fragmentation masking. With "0xe" we also get some reserved dispatch values.

---
 net/ieee802154/6lowpan/rx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ieee802154/6lowpan/rx.c +2 -1
index b0066b7..595830f 100644
@@ -122,7 +122,8 @@ static lowpan_rx_result lowpan_rx_h_frag(struct sk_buff *skb)
 	      lowpan_is_fragn(*skb_network_header(skb))))
 		return RX_CONTINUE;
 
-	ret = lowpan_frag_rcv(skb, *skb_network_header(skb) & 0xe0);
+	ret = lowpan_frag_rcv(skb, *skb_network_header(skb) &
+			      LOWPAN_DISPATCH_FRAG_MASK);
 	if (ret == 1)
 		return RX_CONTINUE;
 
Signature · 1 line
2.5.0
Reviewed-by on v1 11/16
#29 lore raw

Re: [RFC 11/16] ieee802154: 6lowpan: fix fragmentation dispatch mask

Hello.

Quoted 13 lines · Alexander Aring

This patch fix the dispatch fragmentation masking. With "0xe" we also get some reserved dispatch values.

---
  net/ieee802154/6lowpan/rx.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
net/ieee802154/6lowpan/rx.c +0 -0
index b0066b7..595830f 100644

net/ieee802154/6lowpan/rx.c static lowpan_rx_result lowpan_rx_h_frag(struct sk_buff *skb) · line 129

Quoted 9 lines
net/ieee802154/6lowpan/rx.c +2 -1
@@ -122,7 +122,8 @@ static lowpan_rx_result lowpan_rx_h_frag(struct sk_buff *skb)
  	      lowpan_is_fragn(*skb_network_header(skb))))
  		return RX_CONTINUE;
 
-	ret = lowpan_frag_rcv(skb, *skb_network_header(skb) & 0xe0);
+	ret = lowpan_frag_rcv(skb, *skb_network_header(skb) &
+			      LOWPAN_DISPATCH_FRAG_MASK);
  	if (ret == 1)
  		return RX_CONTINUE;
 

regards
Stefan Schmidt

author maintainer
#30 lore raw

RFC 12/16 ieee802154: 6lowpan: add generic lowpan header check

In reply to Alexander Aring

This patch introduce an earlier check if a 6LoWPAN can be valid. This contains at first for checking if the header contains a dispatch byte and isn't the nalp dispatch value, which means it isn't a 6LoWPAN packet.

---
 net/ieee802154/6lowpan/rx.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
net/ieee802154/6lowpan/rx.c +24 -1
index 595830f..62d181a 100644
@@ -172,11 +172,34 @@ rxh_next:
 #undef CALL_RXH
 }
 
+static inline bool lowpan_is_nalp(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_FIRST) == LOWPAN_DISPATCH_NALP;
+}
+
+/* lowpan_rx_h_check checks on generic 6LoWPAN requirements
+ * in MAC and 6LoWPAN header.
+ *
+ * Don't manipulate the skb here, it could be shared buffer.
+ */
+static bool lowpan_rx_h_check(struct sk_buff *skb)
+{
+	/* check for if we can evaluate the dispatch */
+	if (unlikely(!skb->len))
+		return false;
+
+	if (lowpan_is_nalp(*skb_network_header(skb)))
+		return false;
+
+	return true;
+}
+
 static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
 		      struct packet_type *pt, struct net_device *orig_wdev)
 {
 	if (skb->pkt_type == PACKET_OTHERHOST ||
-	    wdev->type != ARPHRD_IEEE802154)
+	    wdev->type != ARPHRD_IEEE802154 ||
+	    !lowpan_rx_h_check(skb))
 		return NET_RX_DROP;
 
 	skb = skb_share_check(skb, GFP_ATOMIC);
Signature · 1 line
2.5.0
Reviewed-by on v1 12/16
#31 lore raw

Re: [RFC 12/16] ieee802154: 6lowpan: add generic lowpan header check

Hello.

Quoted 1 line · Alexander Aring

This patch introduce an earlier check if a 6LoWPAN can be valid. This

Missing the worde frame here? ...6LoWPAN frame can be valid...

Quoted 20 lines

contains at first for checking if the header contains a dispatch byte and isn't the nalp dispatch value, which means it isn't a 6LoWPAN packet.

---
  net/ieee802154/6lowpan/rx.c | 25 ++++++++++++++++++++++++-
  1 file changed, 24 insertions(+), 1 deletion(-)
net/ieee802154/6lowpan/rx.c +3 -0
index 595830f..62d181a 100644
@@ -172,11 +172,34 @@ rxh_next:
  #undef CALL_RXH
  }
 
+static inline bool lowpan_is_nalp(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_FIRST) == LOWPAN_DISPATCH_NALP;

net/ieee802154/6lowpan/rx.c rxh_next: · line 187

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +10 -0
+}
+
+/* lowpan_rx_h_check checks on generic 6LoWPAN requirements
+ * in MAC and 6LoWPAN header.
+ *
+ * Don't manipulate the skb here, it could be shared buffer.
+ */
+static bool lowpan_rx_h_check(struct sk_buff *skb)
+{
+	/* check for if we can evaluate the dispatch */

check if... no need for a for here.

Quoted 9 lines
net/ieee802154/6lowpan/rx.c +9 -0
+	if (unlikely(!skb->len))
+		return false;
+
+	if (lowpan_is_nalp(*skb_network_header(skb)))
+		return false;
+
+	return true;
+}
+

net/ieee802154/6lowpan/rx.c rxh_next: · line 205

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +2 -1
  static int lowpan_rcv(struct sk_buff *skb, struct net_device *wdev,
  		      struct packet_type *pt, struct net_device *orig_wdev)
  {
  	if (skb->pkt_type == PACKET_OTHERHOST ||
-	    wdev->type != ARPHRD_IEEE802154)
+	    wdev->type != ARPHRD_IEEE802154 ||
+	    !lowpan_rx_h_check(skb))
  		return NET_RX_DROP;
 
  	skb = skb_share_check(skb, GFP_ATOMIC);

regards
Stefan Schmidt

author maintainer
#32 lore raw

RFC 13/16 ieee802154: 6lowpan: add handler for all dispatch values

In reply to Alexander Aring

This patch adds dummy handlers for all known IEEE 802.15.4 dispatch values which prints a warning that we don't support these dispatches right now. Also we add a warning to the RX_CONTINUE case inside of lowpan_rx_handlers_result which should now never happend.

---
 net/ieee802154/6lowpan/rx.c | 71 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
net/ieee802154/6lowpan/rx.c +71 -0
index 62d181a..146aa14 100644
@@ -37,6 +37,9 @@ lowpan_rx_handlers_result(struct sk_buff *skb, lowpan_rx_result res)
 	switch (res) {
 	/* nobody cared about this packet */
 	case RX_CONTINUE:
+		net_warn_ratelimited("%s: %s 0x%02x\n", skb->dev->name,
+				     "received unknown dispatch",
+				     *skb_network_header(skb));
 	case RX_DROP_UNUSABLE:
 		kfree_skb(skb);
 	case RX_DROP:
@@ -149,6 +152,70 @@ static lowpan_rx_result lowpan_rx_h_iphc(struct sk_buff *skb)
 	return lowpan_give_skb_to_device(skb);
 }
 
+static inline bool lowpan_is_hc1(u8 dispatch)
+{
+	return dispatch == LOWPAN_DISPATCH_HC1;
+}
+
+static lowpan_rx_result lowpan_rx_h_hc1(struct sk_buff *skb)
+{
+	if (!lowpan_is_hc1(*skb_network_header(skb)))
+		return RX_CONTINUE;
+
+	net_warn_ratelimited("%s: %s\n", skb->dev->name,
+			     "6LoWPAN HC1 not supported\n");
+
+	return RX_DROP_UNUSABLE;
+}
+
+static inline bool lowpan_is_bc0(u8 dispatch)
+{
+	return dispatch == LOWPAN_DISPATCH_BC0;
+}
+
+static lowpan_rx_result lowpan_rx_h_bc0(struct sk_buff *skb)
+{
+	if (!lowpan_is_bc0(*skb_network_header(skb)))
+		return RX_CONTINUE;
+
+	net_warn_ratelimited("%s: %s\n", skb->dev->name,
+			     "6LoWPAN BC0 not supported\n");
+
+	return RX_DROP_UNUSABLE;
+}
+
+static inline bool lowpan_is_esc(u8 dispatch)
+{
+	return dispatch == LOWPAN_DISPATCH_ESC;
+}
+
+static lowpan_rx_result lowpan_rx_h_esc(struct sk_buff *skb)
+{
+	if (!lowpan_is_esc(*skb_network_header(skb)))
+		return RX_CONTINUE;
+
+	net_warn_ratelimited("%s: %s\n", skb->dev->name,
+			     "6LoWPAN ESC not supported\n");
+
+	return RX_DROP_UNUSABLE;
+}
+
+static inline bool lowpan_is_mesh(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_FIRST) == LOWPAN_DISPATCH_MESH;
+}
+
+static lowpan_rx_result lowpan_rx_h_mesh(struct sk_buff *skb)
+{
+	if (!lowpan_is_mesh(*skb_network_header(skb)))
+		return RX_CONTINUE;
+
+	net_warn_ratelimited("%s: %s\n", skb->dev->name,
+			     "6LoWPAN MESH not supported\n");
+
+	return RX_DROP_UNUSABLE;
+}
+
 int lowpan_invoke_rx_handlers(struct sk_buff *skb)
 {
 	lowpan_rx_result res;
@@ -166,6 +233,10 @@ int lowpan_invoke_rx_handlers(struct sk_buff *skb)
 	/* likely at first */
 	CALL_RXH(lowpan_rx_h_iphc);
 	CALL_RXH(lowpan_rx_h_ipv6);
+	CALL_RXH(lowpan_rx_h_hc1);
+	CALL_RXH(lowpan_rx_h_bc0);
+	CALL_RXH(lowpan_rx_h_esc);
+	CALL_RXH(lowpan_rx_h_mesh);
 
 rxh_next:
 	return lowpan_rx_handlers_result(skb, res);
Signature · 1 line
2.5.0
Reviewed-by on v1 13/16
#33 lore raw

Re: [RFC 13/16] ieee802154: 6lowpan: add handler for all dispatch values

Hello.

Quoted 96 lines · Alexander Aring

This patch adds dummy handlers for all known IEEE 802.15.4 dispatch values which prints a warning that we don't support these dispatches right now. Also we add a warning to the RX_CONTINUE case inside of lowpan_rx_handlers_result which should now never happend.

---
  net/ieee802154/6lowpan/rx.c | 71 +++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 71 insertions(+)
net/ieee802154/6lowpan/rx.c +67 -0
index 62d181a..146aa14 100644
@@ -37,6 +37,9 @@ lowpan_rx_handlers_result(struct sk_buff *skb, lowpan_rx_result res)
  	switch (res) {
  	/* nobody cared about this packet */
  	case RX_CONTINUE:
+		net_warn_ratelimited("%s: %s 0x%02x\n", skb->dev->name,
+				     "received unknown dispatch",
+				     *skb_network_header(skb));
  	case RX_DROP_UNUSABLE:
  		kfree_skb(skb);
  	case RX_DROP:
@@ -149,6 +152,70 @@ static lowpan_rx_result lowpan_rx_h_iphc(struct sk_buff *skb)
  	return lowpan_give_skb_to_device(skb);
  }
 
+static inline bool lowpan_is_hc1(u8 dispatch)
+{
+	return dispatch == LOWPAN_DISPATCH_HC1;
+}
+
+static lowpan_rx_result lowpan_rx_h_hc1(struct sk_buff *skb)
+{
+	if (!lowpan_is_hc1(*skb_network_header(skb)))
+		return RX_CONTINUE;
+
+	net_warn_ratelimited("%s: %s\n", skb->dev->name,
+			     "6LoWPAN HC1 not supported\n");
+
+	return RX_DROP_UNUSABLE;
+}
+
+static inline bool lowpan_is_bc0(u8 dispatch)
+{
+	return dispatch == LOWPAN_DISPATCH_BC0;
+}
+
+static lowpan_rx_result lowpan_rx_h_bc0(struct sk_buff *skb)
+{
+	if (!lowpan_is_bc0(*skb_network_header(skb)))
+		return RX_CONTINUE;
+
+	net_warn_ratelimited("%s: %s\n", skb->dev->name,
+			     "6LoWPAN BC0 not supported\n");
+
+	return RX_DROP_UNUSABLE;
+}
+
+static inline bool lowpan_is_esc(u8 dispatch)
+{
+	return dispatch == LOWPAN_DISPATCH_ESC;
+}
+
+static lowpan_rx_result lowpan_rx_h_esc(struct sk_buff *skb)
+{
+	if (!lowpan_is_esc(*skb_network_header(skb)))
+		return RX_CONTINUE;
+
+	net_warn_ratelimited("%s: %s\n", skb->dev->name,
+			     "6LoWPAN ESC not supported\n");
+
+	return RX_DROP_UNUSABLE;
+}
+
+static inline bool lowpan_is_mesh(u8 dispatch)
+{
+	return (dispatch & LOWPAN_DISPATCH_FIRST) == LOWPAN_DISPATCH_MESH;
+}
+
+static lowpan_rx_result lowpan_rx_h_mesh(struct sk_buff *skb)
+{
+	if (!lowpan_is_mesh(*skb_network_header(skb)))
+		return RX_CONTINUE;
+
+	net_warn_ratelimited("%s: %s\n", skb->dev->name,
+			     "6LoWPAN MESH not supported\n");
+
+	return RX_DROP_UNUSABLE;
+}
+
  int lowpan_invoke_rx_handlers(struct sk_buff *skb)
  {
  	lowpan_rx_result res;

net/ieee802154/6lowpan/rx.c int lowpan_invoke_rx_handlers(struct sk_buff *skb) · line 242

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +4 -0
@@ -166,6 +233,10 @@ int lowpan_invoke_rx_handlers(struct sk_buff *skb)
  	/* likely at first */
  	CALL_RXH(lowpan_rx_h_iphc);
  	CALL_RXH(lowpan_rx_h_ipv6);
+	CALL_RXH(lowpan_rx_h_hc1);
+	CALL_RXH(lowpan_rx_h_bc0);
+	CALL_RXH(lowpan_rx_h_esc);
+	CALL_RXH(lowpan_rx_h_mesh);
 
  rxh_next:
  	return lowpan_rx_handlers_result(skb, res);

regards
Stefan Schmidt

author maintainer
#34 lore raw

RFC 14/16 ieee802154: 6lowpan: add check for reserved dispatch

In reply to Alexander Aring

This patch adds checks for reserved dispatch value by check on all known dispatch values.

---
 net/ieee802154/6lowpan/rx.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
net/ieee802154/6lowpan/rx.c +11 -1
index 146aa14..48869ac 100644
@@ -248,6 +248,15 @@ static inline bool lowpan_is_nalp(u8 dispatch)
 	return (dispatch & LOWPAN_DISPATCH_FIRST) == LOWPAN_DISPATCH_NALP;
 }
 
+static inline bool lowpan_is_reserved(u8 dispatch)
+{
+	return !(lowpan_is_nalp(dispatch) || lowpan_is_iphc(dispatch) ||
+		 lowpan_is_ipv6(dispatch) || lowpan_is_hc1(dispatch) ||
+		 lowpan_is_bc0(dispatch) || lowpan_is_mesh(dispatch) ||
+		 lowpan_is_esc(dispatch) || lowpan_is_frag1(dispatch) ||
+		 lowpan_is_fragn(dispatch));
+}
+
 /* lowpan_rx_h_check checks on generic 6LoWPAN requirements
  * in MAC and 6LoWPAN header.
  *
@@ -259,7 +268,8 @@ static bool lowpan_rx_h_check(struct sk_buff *skb)
 	if (unlikely(!skb->len))
 		return false;
 
-	if (lowpan_is_nalp(*skb_network_header(skb)))
+	if (lowpan_is_nalp(*skb_network_header(skb)) ||
+	    lowpan_is_reserved(*skb_network_header(skb)))
 		return false;
 
 	return true;
Signature · 1 line
2.5.0
#35 lore raw

Re: [RFC 14/16] ieee802154: 6lowpan: add check for reserved dispatch

Hello.

Quoted 13 lines · Alexander Aring

This patch adds checks for reserved dispatch value by check on all known dispatch values.

---
  net/ieee802154/6lowpan/rx.c | 12 +++++++++++-
  1 file changed, 11 insertions(+), 1 deletion(-)
net/ieee802154/6lowpan/rx.c +0 -0
index 146aa14..48869ac 100644

net/ieee802154/6lowpan/rx.c static inline bool lowpan_is_nalp(u8 dispatch) · line 253

Quoted 6 lines
net/ieee802154/6lowpan/rx.c +3 -0
@@ -248,6 +248,15 @@ static inline bool lowpan_is_nalp(u8 dispatch)
  	return (dispatch & LOWPAN_DISPATCH_FIRST) == LOWPAN_DISPATCH_NALP;
  }
 
+static inline bool lowpan_is_reserved(u8 dispatch)
+{
+	return !(lowpan_is_nalp(dispatch) || lowpan_is_iphc(dispatch) ||

OK, this is fishy. First of all you check lowpan_is_nalp here and negate it, but below you are checking without negation. One must be wrong. :)

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +6 -0
+		 lowpan_is_ipv6(dispatch) || lowpan_is_hc1(dispatch) ||
+		 lowpan_is_bc0(dispatch) || lowpan_is_mesh(dispatch) ||
+		 lowpan_is_esc(dispatch) || lowpan_is_frag1(dispatch) ||
+		 lowpan_is_fragn(dispatch));
+}
+
  /* lowpan_rx_h_check checks on generic 6LoWPAN requirements
   * in MAC and 6LoWPAN header.
   *

net/ieee802154/6lowpan/rx.c static bool lowpan_rx_h_check(struct sk_buff *skb) · line 271

Quoted 5 lines
net/ieee802154/6lowpan/rx.c +1 -1
@@ -259,7 +268,8 @@ static bool lowpan_rx_h_check(struct sk_buff *skb)
  	if (unlikely(!skb->len))
  		return false;
 
-	if (lowpan_is_nalp(*skb_network_header(skb)))
+	if (lowpan_is_nalp(*skb_network_header(skb)) ||

Here are you checking it as well. but without negating it.

net/ieee802154/6lowpan/rx.c static bool lowpan_rx_h_check(struct sk_buff *skb) · line 275

Quoted 4 lines
net/ieee802154/6lowpan/rx.c +1 -0
+	    lowpan_is_reserved(*skb_network_header(skb)))
  		return false;
 
  	return true;

regards
Stefan Schmidt

author maintainer
#36 lore raw

Re: [RFC 14/16] ieee802154: 6lowpan: add check for reserved dispatch

Quoted 27 lines · Stefan Schmidt

Hello.

Quoted 13 lines · Alexander Aring

This patch adds checks for reserved dispatch value by check on all known dispatch values.

---
 net/ieee802154/6lowpan/rx.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
net/ieee802154/6lowpan/rx.c +0 -0
index 146aa14..48869ac 100644

net/ieee802154/6lowpan/rx.c static inline bool lowpan_is_nalp(u8 dispatch) · line 252

Quoted 5 lines
net/ieee802154/6lowpan/rx.c +3 -0
@@ -248,6 +248,15 @@ static inline bool lowpan_is_nalp(u8 dispatch)
 	return (dispatch & LOWPAN_DISPATCH_FIRST) == LOWPAN_DISPATCH_NALP;
 }
+static inline bool lowpan_is_reserved(u8 dispatch)
+{
+	return !(lowpan_is_nalp(dispatch) || lowpan_is_iphc(dispatch) ||

OK, this is fishy. First of all you check lowpan_is_nalp here and negate it, but below you are checking without negation.
One must be wrong. :)

Quoted 17 lines
Quoted 10 lines
net/ieee802154/6lowpan/rx.c +6 -0
+		 lowpan_is_ipv6(dispatch) || lowpan_is_hc1(dispatch) ||
+		 lowpan_is_bc0(dispatch) || lowpan_is_mesh(dispatch) ||
+		 lowpan_is_esc(dispatch) || lowpan_is_frag1(dispatch) ||
+		 lowpan_is_fragn(dispatch));
+}
+
 /* lowpan_rx_h_check checks on generic 6LoWPAN requirements
  * in MAC and 6LoWPAN header.
  *

net/ieee802154/6lowpan/rx.c static bool lowpan_rx_h_check(struct sk_buff *skb) · line 270

Quoted 4 lines
net/ieee802154/6lowpan/rx.c +1 -1
@@ -259,7 +268,8 @@ static bool lowpan_rx_h_check(struct sk_buff *skb)
 	if (unlikely(!skb->len))
 		return false;
-	if (lowpan_is_nalp(*skb_network_header(skb)))
+	if (lowpan_is_nalp(*skb_network_header(skb)) ||

Here are you checking it as well. but without negating it.

yes, I think we should work here with ranges. Not checking all known values. (Maybe we can also do some bit magic there then).

Also I should lookup more iana registrations for dispatches. I forget

LOWPAN_DFF

See [0]. But then somebody else should send a patch to introduce some "netdev warning message".

btw: we should add some of these warning messages for lowpan_nhc as well. [1]. I am fine for introduce just a name and known nhc id for printing some warning that we don't support $NAME right now, instead of "unknown".

(Also wondering why "11111111 - Unassigned, reserved for extensions" - does this mean now that when we have "11111111" an additional nhc id byte is there? I don't see anything in rfc6282 which mention that. For this reason I had implement the such complicated rbtree lookup mechanism because I was not sure about this -> "When we know an additional nhc id byte is there". Anyway it's some variable length bitstring and rbtree structure should be fit there (I hope).

- Alex

[0] https://www.iana.org/assignments/_6lowpan-parameters/_6lowpan-parameters.xhtml#_6lowpan-parameters-1
[1] https://www.iana.org/assignments/_6lowpan-parameters/_6lowpan-parameters.xhtml#lowpan_nhc

author maintainer
#37 lore raw

RFC 15/16 ieee802154: 6lowpan: check on valid 802.15.4 frame

In reply to Alexander Aring

This patch adds frame control checks to check if the received frame is something which could contain a 6LoWPAN packet.

---
 include/linux/ieee802154.h  | 48 ++++++++++++++++++++++++++++++++++++++++++++-
 net/ieee802154/6lowpan/rx.c |  9 +++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)
include/linux/ieee802154.h +47 -1
index 4f26c01..5a64fc0 100644
@@ -208,7 +208,24 @@ enum {
 };
 
 /* frame control handling */
-#define IEEE802154_FCTL_ACKREQ	0x0020
+#define IEEE802154_FCTL_FTYPE		0x0003
+#define IEEE802154_FTYPE_DATA		0x0001
+#define IEEE802154_FCTL_ACKREQ		0x0020
+#define IEEE802154_FCTL_INTRA_PAN	0x0040
+#define IEEE802154_FCTL_DADDR		0x0c00
+#define IEEE802154_FCTL_DADDR_NONE	0x0000
+#define IEEE802154_FCTL_SADDR		0xc000
+#define IEEE802154_FCTL_SADDR_NONE	0x0000
+
+/*
+ * ieee802154_is_data - check if type is IEEE802154_FTYPE_DATA
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline int ieee802154_is_data(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE802154_FCTL_FTYPE)) ==
+		cpu_to_le16(IEEE802154_FTYPE_DATA);
+}
 
 /**
  * ieee802154_is_ackreq - check if acknowledgment request bit is set
@@ -220,6 +237,35 @@ static inline bool ieee802154_is_ackreq(__le16 fc)
 }
 
 /**
+ * ieee802154_is_intra_pan - check if intra pan id communication
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline bool ieee802154_is_intra_pan(__le16 fc)
+{
+	return fc & cpu_to_le16(IEEE802154_FCTL_INTRA_PAN);
+}
+
+/**
+ * ieee802154_is_daddr_none - check if daddr mode is none
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline bool ieee802154_is_daddr_none(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE802154_FCTL_DADDR)) ==
+		cpu_to_le16(IEEE802154_FCTL_DADDR_NONE);
+}
+
+/**
+ * ieee802154_is_saddr_none - check if saddr mode is none
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline bool ieee802154_is_saddr_none(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE802154_FCTL_SADDR)) ==
+		cpu_to_le16(IEEE802154_FCTL_SADDR_NONE);
+}
+
+/**
  * ieee802154_get_fc_from_skb - get the frame control field from an skb
  * @skb: skb where the frame control field will be get from
  */
net/ieee802154/6lowpan/rx.c +9 -0
index 48869ac..b1a9d14 100644
@@ -264,6 +264,15 @@ static inline bool lowpan_is_reserved(u8 dispatch)
  */
 static bool lowpan_rx_h_check(struct sk_buff *skb)
 {
+	__le16 fc = ieee802154_get_fc_from_skb(skb);
+
+	/* check on ieee802154 conform 6LoWPAN header */
+	if (!ieee802154_is_data(fc) ||
+	    ieee802154_is_daddr_none(fc) ||
+	    ieee802154_is_saddr_none(fc) ||
+	    !ieee802154_is_intra_pan(fc))
+		return false;
+
 	/* check for if we can evaluate the dispatch */
 	if (unlikely(!skb->len))
 		return false;
Signature · 1 line
2.5.0
Reviewed-by on v1 15/16
#38 lore raw

Re: [RFC 15/16] ieee802154: 6lowpan: check on valid 802.15.4 frame

Hello.

Quoted 80 lines · Alexander Aring

This patch adds frame control checks to check if the received frame is something which could contain a 6LoWPAN packet.

---
  include/linux/ieee802154.h  | 48 ++++++++++++++++++++++++++++++++++++++++++++-
  net/ieee802154/6lowpan/rx.c |  9 +++++++++
  2 files changed, 56 insertions(+), 1 deletion(-)
include/linux/ieee802154.h +47 -1
index 4f26c01..5a64fc0 100644
@@ -208,7 +208,24 @@ enum {
  };
 
  /* frame control handling */
-#define IEEE802154_FCTL_ACKREQ	0x0020
+#define IEEE802154_FCTL_FTYPE		0x0003
+#define IEEE802154_FTYPE_DATA		0x0001
+#define IEEE802154_FCTL_ACKREQ		0x0020
+#define IEEE802154_FCTL_INTRA_PAN	0x0040
+#define IEEE802154_FCTL_DADDR		0x0c00
+#define IEEE802154_FCTL_DADDR_NONE	0x0000
+#define IEEE802154_FCTL_SADDR		0xc000
+#define IEEE802154_FCTL_SADDR_NONE	0x0000
+
+/*
+ * ieee802154_is_data - check if type is IEEE802154_FTYPE_DATA
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline int ieee802154_is_data(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE802154_FCTL_FTYPE)) ==
+		cpu_to_le16(IEEE802154_FTYPE_DATA);
+}
 
  /**
   * ieee802154_is_ackreq - check if acknowledgment request bit is set
@@ -220,6 +237,35 @@ static inline bool ieee802154_is_ackreq(__le16 fc)
  }
 
  /**
+ * ieee802154_is_intra_pan - check if intra pan id communication
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline bool ieee802154_is_intra_pan(__le16 fc)
+{
+	return fc & cpu_to_le16(IEEE802154_FCTL_INTRA_PAN);
+}
+
+/**
+ * ieee802154_is_daddr_none - check if daddr mode is none
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline bool ieee802154_is_daddr_none(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE802154_FCTL_DADDR)) ==
+		cpu_to_le16(IEEE802154_FCTL_DADDR_NONE);
+}
+
+/**
+ * ieee802154_is_saddr_none - check if saddr mode is none
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline bool ieee802154_is_saddr_none(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE802154_FCTL_SADDR)) ==
+		cpu_to_le16(IEEE802154_FCTL_SADDR_NONE);
+}
+
+/**
   * ieee802154_get_fc_from_skb - get the frame control field from an skb
   * @skb: skb where the frame control field will be get from
   */
net/ieee802154/6lowpan/rx.c +0 -0
index 48869ac..b1a9d14 100644

net/ieee802154/6lowpan/rx.c static inline bool lowpan_is_reserved(u8 dispatch) · line 273

Quoted 10 lines
net/ieee802154/6lowpan/rx.c +7 -0
@@ -264,6 +264,15 @@ static inline bool lowpan_is_reserved(u8 dispatch)
   */
  static bool lowpan_rx_h_check(struct sk_buff *skb)
  {
+	__le16 fc = ieee802154_get_fc_from_skb(skb);
+
+	/* check on ieee802154 conform 6LoWPAN header */
+	if (!ieee802154_is_data(fc) ||
+	    ieee802154_is_daddr_none(fc) ||
+	    ieee802154_is_saddr_none(fc) ||
+	    !ieee802154_is_intra_pan(fc))

Interesting, 6LoWPAN frames always have to have the intra PAN flag set? Did not know this until now.

net/ieee802154/6lowpan/rx.c static inline bool lowpan_is_reserved(u8 dispatch) · line 278

Quoted 5 lines
net/ieee802154/6lowpan/rx.c +2 -0
+		return false;
+
  	/* check for if we can evaluate the dispatch */
  	if (unlikely(!skb->len))
  		return false;

regards
Stefan Schmidt

author maintainer
#39 lore raw

Re: [RFC 15/16] ieee802154: 6lowpan: check on valid 802.15.4 frame

Quoted 85 lines · Stefan Schmidt

Hello.

Quoted 82 lines · Alexander Aring

This patch adds frame control checks to check if the received frame is something which could contain a 6LoWPAN packet.

---
 include/linux/ieee802154.h  | 48 ++++++++++++++++++++++++++++++++++++++++++++-
 net/ieee802154/6lowpan/rx.c |  9 +++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)
include/linux/ieee802154.h +47 -1
index 4f26c01..5a64fc0 100644
@@ -208,7 +208,24 @@ enum {
 };
 /* frame control handling */
-#define IEEE802154_FCTL_ACKREQ	0x0020
+#define IEEE802154_FCTL_FTYPE		0x0003
+#define IEEE802154_FTYPE_DATA		0x0001
+#define IEEE802154_FCTL_ACKREQ		0x0020
+#define IEEE802154_FCTL_INTRA_PAN	0x0040
+#define IEEE802154_FCTL_DADDR		0x0c00
+#define IEEE802154_FCTL_DADDR_NONE	0x0000
+#define IEEE802154_FCTL_SADDR		0xc000
+#define IEEE802154_FCTL_SADDR_NONE	0x0000
+
+/*
+ * ieee802154_is_data - check if type is IEEE802154_FTYPE_DATA
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline int ieee802154_is_data(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE802154_FCTL_FTYPE)) ==
+		cpu_to_le16(IEEE802154_FTYPE_DATA);
+}
 /**
  * ieee802154_is_ackreq - check if acknowledgment request bit is set
@@ -220,6 +237,35 @@ static inline bool ieee802154_is_ackreq(__le16 fc)
 }
 /**
+ * ieee802154_is_intra_pan - check if intra pan id communication
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline bool ieee802154_is_intra_pan(__le16 fc)
+{
+	return fc & cpu_to_le16(IEEE802154_FCTL_INTRA_PAN);
+}
+
+/**
+ * ieee802154_is_daddr_none - check if daddr mode is none
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline bool ieee802154_is_daddr_none(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE802154_FCTL_DADDR)) ==
+		cpu_to_le16(IEEE802154_FCTL_DADDR_NONE);
+}
+
+/**
+ * ieee802154_is_saddr_none - check if saddr mode is none
+ * @fc: frame control bytes in little-endian byteorder
+ */
+static inline bool ieee802154_is_saddr_none(__le16 fc)
+{
+	return (fc & cpu_to_le16(IEEE802154_FCTL_SADDR)) ==
+		cpu_to_le16(IEEE802154_FCTL_SADDR_NONE);
+}
+
+/**
  * ieee802154_get_fc_from_skb - get the frame control field from an skb
  * @skb: skb where the frame control field will be get from
  */
net/ieee802154/6lowpan/rx.c +2 -0
index 48869ac..b1a9d14 100644
@@ -264,6 +264,15 @@ static inline bool lowpan_is_reserved(u8 dispatch)
  */
 static bool lowpan_rx_h_check(struct sk_buff *skb)
 {
+	__le16 fc = ieee802154_get_fc_from_skb(skb);
+
Quoted 8 lines

net/ieee802154/6lowpan/rx.c static inline bool lowpan_is_reserved(u8 dispatch) · line 273

Quoted 5 lines
net/ieee802154/6lowpan/rx.c +5 -0
+	/* check on ieee802154 conform 6LoWPAN header */
+	if (!ieee802154_is_data(fc) ||
+	    ieee802154_is_daddr_none(fc) ||
+	    ieee802154_is_saddr_none(fc) ||
+	    !ieee802154_is_intra_pan(fc))

Interesting, 6LoWPAN frames always have to have the intra PAN flag set? Did not know this until now.

I think intra-pan communication makes only sense, also I talked with Phoebe about ~ 1 year ago where I asked myself how 802.15.4 6LoWPAN handles non intra pan connection and I need to lookup again this in some RFC. I think it was at [0].

"A destination PAN identifier is included in the frame, and it
MUST match the PAN ID of the link in question."

which means "the destination pan id" must be the same of the current "link". The "link" means -> what we currently set to the 802.15.4 MIB.

I think this answers the question "802.15.4 6LoWPAN is intra-pan only".

Another question is:

How to deal with 802.15.4 which have the same destination and source PANID. The 802.15.4 says here it should set the intra panid bit.

NOW we could parse "source" and "destination" panid is the same and intra panid is NOT set. But for me it's an invalid 802.15.4 frame and we should drop it.

We currently don't drop this frames but we should do it in the lower layer parsing which I will think about it how to deal frame parsing when we have crypto working. :-/

Anyway I think everbody is welcome to send patches for this, but I maybe want to change it later in some complete different parsing mechanism.

- Alex

[0] https://tools.ietf.org/html/rfc4944#section-3

author maintainer
#40 lore raw

RFC 16/16 ieee802154: 6lowpan: remove packet type to host

In reply to Alexander Aring

This patch remove the packet_type to host and leave the mac pkt_type. By running 'grep -r "pkt_type" net/ipv6', the IPv6 stack will evaluate this value for PACKET_BROADCAST. Instead of overwriting this value we will leave the mac value there which is broadcasts if the mac frame was a broadcast frame.

---
 net/ieee802154/6lowpan/rx.c | 1 -
 1 file changed, 1 deletion(-)
net/ieee802154/6lowpan/rx.c +0 -1
index b1a9d14..1d9866a 100644
@@ -56,7 +56,6 @@ static int lowpan_give_skb_to_device(struct sk_buff *skb)
 	int ret;
 
 	skb->protocol = htons(ETH_P_IPV6);
-	skb->pkt_type = PACKET_HOST;
 
 	ret = netif_rx(skb);
 	/* kfree_skb handled by netif_rx, so RX_DROP on failure */
Signature · 1 line
2.5.0
Reviewed-by on v1 16/16
#41 lore raw

Re: [RFC 16/16] ieee802154: 6lowpan: remove packet type to host

Hello.

Quoted 16 lines · Alexander Aring

This patch remove the packet_type to host and leave the mac pkt_type. By running 'grep -r "pkt_type" net/ipv6', the IPv6 stack will evaluate this value for PACKET_BROADCAST. Instead of overwriting this value we will leave the mac value there which is broadcasts if the mac frame was a broadcast frame.

---
  net/ieee802154/6lowpan/rx.c | 1 -
  1 file changed, 1 deletion(-)
net/ieee802154/6lowpan/rx.c +0 -0
index b1a9d14..1d9866a 100644

net/ieee802154/6lowpan/rx.c static int lowpan_give_skb_to_device(struct sk_buff *skb) · line 61

Quoted 7 lines
net/ieee802154/6lowpan/rx.c +0 -1
@@ -56,7 +56,6 @@ static int lowpan_give_skb_to_device(struct sk_buff *skb)
  	int ret;
 
  	skb->protocol = htons(ETH_P_IPV6);
-	skb->pkt_type = PACKET_HOST;
 
  	ret = netif_rx(skb);
  	/* kfree_skb handled by netif_rx, so RX_DROP on failure */

regards
Stefan Schmidt

#42 lore raw
In reply to Alexander Aring

Hello.

Quoted 15 lines · Alexander Aring

Hi,

this patch series contains a rework of 802.15.4 6LoWPAN receive handling. We need to check on some things before which never checked before, like is 802.15.4 dataframe, if we can access skb->data[0] (could be that skb->len is 0 then), etc.

Also various bug fixes like the masking for fragmentation dispatch value which is currently wrong. Also we should again check the dispatch value after successful reassembly a fragment, we currently assume always a iphc header there. This is wrong it could also be a non-compressed header. This can occur if the compressed header is larger than lower interface MTU size, we doesn't react on this while transmit which is another issue. Nevertheless we also don't reach this case at worst-case compression currently.

Quoted 2 lines

I introduced a complete new handling for the dispatch values based on mac80211 datatype receive handling mechanism.

I'm going to review this set over the next days. Just as a heads up.

Quoted 6 lines

This patch series based on bluetooth-next with various pending patches, I uploaded the branch at:

https://github.com/linux-wpan/linux-wpan-next/commits/802154_6lowpan_cleanup2

so everybody can test it.

I tried to apply the patches directly on bluetooth-next but they did not apply. Guess you want to rebase them when sending out a new round. For now I will review the patches here and use the branch you uploaded for testing. Will report back later.

regards
Stefan Schmidt

Tested-by
#43 lore raw

Hello.

Quoted 26 lines · Stefan Schmidt

Hello.

Quoted 15 lines · Alexander Aring

Hi,

this patch series contains a rework of 802.15.4 6LoWPAN receive handling. We need to check on some things before which never checked before, like is 802.15.4 dataframe, if we can access skb->data[0] (could be that skb->len is 0 then), etc.

Also various bug fixes like the masking for fragmentation dispatch value which is currently wrong. Also we should again check the dispatch value after successful reassembly a fragment, we currently assume always a iphc header there. This is wrong it could also be a non-compressed header. This can occur if the compressed header is larger than lower interface MTU size, we doesn't react on this while transmit which is another issue. Nevertheless we also don't reach this case at worst-case compression currently.

Quoted 2 lines

I introduced a complete new handling for the dispatch values based on mac80211 datatype receive handling mechanism.

I'm going to review this set over the next days. Just as a heads up.

Quoted 3 lines

This patch series based on bluetooth-next with various pending patches, I uploaded the branch at:

Quoted 6 lines
Quoted 4 lines

https://github.com/linux-wpan/linux-wpan-next/commits/802154_6lowpan_cleanup2

so everybody can test it.

I tried to apply the patches directly on bluetooth-next but they did not apply. Guess you want to rebase them when sending out a new round. For now I will review the patches here and use the branch you uploaded for testing. Will report back later.

My testing showed no problems with this. You can add a

to the whole series.

regards
Stefan Schmidt