Skip to contentSkip to conversation

ieee802154: 6lowpan: change datagram var types

PATCH In review Alexander Aring 2 participants 6 messages Sep 30, 2015

Subsystems (2)
lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

PATCH 1/3 ieee802154: 6lowpan: change datagram var types

This patch changes datagram size variable from u16 type to unsigned int. The reason is that an IPv6 header has an MAX_UIN16 payload length, but the datagram size is payload + IPv6 header length. This avoids overflows at some places.

---
 net/ieee802154/6lowpan/6lowpan_i.h  | 4 ++--
 net/ieee802154/6lowpan/reassembly.c | 2 +-
 net/ieee802154/6lowpan/tx.c         | 8 ++++----
 3 files changed, 7 insertions(+), 7 deletions(-)
net/ieee802154/6lowpan/6lowpan_i.h +2 -2
index b4e17a7..10d44d0 100644
@@ -18,7 +18,7 @@ typedef unsigned __bitwise__ lowpan_rx_result;
 
 struct lowpan_create_arg {
 	u16 tag;
-	u16 d_size;
+	unsigned int d_size;
 	const struct ieee802154_addr *src;
 	const struct ieee802154_addr *dst;
 };
@@ -29,7 +29,7 @@ struct lowpan_frag_queue {
 	struct inet_frag_queue	q;
 
 	u16			tag;
-	u16			d_size;
+	unsigned int		d_size;
 	struct ieee802154_addr	saddr;
 	struct ieee802154_addr	daddr;
 };
net/ieee802154/6lowpan/reassembly.c +1 -1
index 12e8cf4..af663cb 100644
@@ -37,7 +37,7 @@ static struct inet_frags lowpan_frags;
 static int lowpan_frag_reasm(struct lowpan_frag_queue *fq,
 			     struct sk_buff *prev, struct net_device *ldev);
 
-static unsigned int lowpan_hash_frag(u16 tag, u16 d_size,
+static unsigned int lowpan_hash_frag(u16 tag, unsigned int d_size,
 				     const struct ieee802154_addr *saddr,
 				     const struct ieee802154_addr *daddr)
 {
net/ieee802154/6lowpan/tx.c +4 -4
index 7e0563e..5ecf8af 100644
@@ -131,8 +131,8 @@ 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 *ldev,
-		       const struct ieee802154_hdr *wpan_hdr, u16 dgram_size,
-		       u16 dgram_offset)
+		       const struct ieee802154_hdr *wpan_hdr,
+		       unsigned int dgram_size, unsigned int dgram_offset)
 {
 	__be16 frag_tag;
 	u8 frag_hdr[5];
@@ -194,7 +194,7 @@ err:
 }
 
 static int lowpan_header(struct sk_buff *skb, struct net_device *ldev,
-			 u16 *dgram_size, u16 *dgram_offset)
+			 unsigned int *dgram_size, unsigned int *dgram_offset)
 {
 	struct wpan_dev *wpan_dev = lowpan_dev_info(ldev)->wdev->ieee802154_ptr;
 	struct ieee802154_addr sa, da;
@@ -244,7 +244,7 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
 {
 	struct ieee802154_hdr wpan_hdr;
 	int max_single, ret;
-	u16 dgram_size, dgram_offset;
+	unsigned int dgram_size, dgram_offset;
 
 	pr_debug("package xmit\n");
 
Signature · 1 line
2.6.0
author maintainer
#1 lore raw

PATCH 2/3 ieee802154: 6lowpan: don't skip first dsn while fragmentation

This patch fixes the data frame sequence numer (dsn) while 6lowpan fragmentation for frag1. Currently we create one 802.15.4 header at first, then check if it's match into one frame and at the end construct many fragments and calling wpan_dev_hard_header for each of them, inclusive for the first fragment. This will make the first generated header to garbage, instead we copying this header for frag1 instead of generate a new one which skips one dsn.

---
 net/ieee802154/6lowpan/tx.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
net/ieee802154/6lowpan/tx.c +17 -10
index 5ecf8af..3b665e1 100644
@@ -79,7 +79,7 @@ int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev,
 
 static struct sk_buff*
 lowpan_alloc_frag(struct sk_buff *skb, int size,
-		  const struct ieee802154_hdr *master_hdr)
+		  const struct ieee802154_hdr *master_hdr, bool frag1)
 {
 	struct net_device *wdev = lowpan_dev_info(skb->dev)->wdev;
 	struct sk_buff *frag;
@@ -95,11 +95,17 @@ lowpan_alloc_frag(struct sk_buff *skb, int size,
 		skb_reset_network_header(frag);
 		*mac_cb(frag) = *mac_cb(skb);
 
-		rc = wpan_dev_hard_header(frag, wdev, &master_hdr->dest,
-					  &master_hdr->source, size);
-		if (rc < 0) {
-			kfree_skb(frag);
-			return ERR_PTR(rc);
+		if (frag1) {
+			memcpy(skb_put(frag, skb->mac_len),
+			       skb_mac_header(skb), skb->mac_len);
+		} else {
+			rc = wpan_dev_hard_header(frag, wdev,
+						  &master_hdr->dest,
+						  &master_hdr->source, size);
+			if (rc < 0) {
+				kfree_skb(frag);
+				return ERR_PTR(rc);
+			}
 		}
 	} else {
 		frag = ERR_PTR(-ENOMEM);
@@ -111,13 +117,13 @@ lowpan_alloc_frag(struct sk_buff *skb, int size,
 static int
 lowpan_xmit_fragment(struct sk_buff *skb, const struct ieee802154_hdr *wpan_hdr,
 		     u8 *frag_hdr, int frag_hdrlen,
-		     int offset, int len)
+		     int offset, int len, bool frag1)
 {
 	struct sk_buff *frag;
 
 	raw_dump_inline(__func__, " fragment header", frag_hdr, frag_hdrlen);
 
-	frag = lowpan_alloc_frag(skb, frag_hdrlen + len, wpan_hdr);
+	frag = lowpan_alloc_frag(skb, frag_hdrlen + len, wpan_hdr, frag1);
 	if (IS_ERR(frag))
 		return PTR_ERR(frag);
 
@@ -156,7 +162,8 @@ lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *ldev,
 
 	rc = lowpan_xmit_fragment(skb, wpan_hdr, frag_hdr,
 				  LOWPAN_FRAG1_HEAD_SIZE, 0,
-				  frag_len + skb_network_header_len(skb));
+				  frag_len + skb_network_header_len(skb),
+				  true);
 	if (rc) {
 		pr_debug("%s unable to send FRAG1 packet (tag: %d)",
 			 __func__, ntohs(frag_tag));
@@ -177,7 +184,7 @@ lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *ldev,
 
 		rc = lowpan_xmit_fragment(skb, wpan_hdr, frag_hdr,
 					  LOWPAN_FRAGN_HEAD_SIZE, skb_offset,
-					  frag_len);
+					  frag_len, false);
 		if (rc) {
 			pr_debug("%s unable to send a FRAGN packet. (tag: %d, offset: %d)\n",
 				 __func__, ntohs(frag_tag), skb_offset);
Signature · 1 line
2.6.0
#2 lore raw

Re: [PATCH bluetooth-next 2/3] ieee802154: 6lowpan: don't skip first dsn while fragmentation

Hi Alex,

Quoted 8 lines

This patch fixes the data frame sequence numer (dsn) while 6lowpan fragmentation for frag1. Currently we create one 802.15.4 header at first, then check if it's match into one frame and at the end construct many fragments and calling wpan_dev_hard_header for each of them, inclusive for the first fragment. This will make the first generated header to garbage, instead we copying this header for frag1 instead of generate a new one which skips one dsn.

Quoted 4 lines

---
net/ieee802154/6lowpan/tx.c | 27 +++++++++++++++++----------

1 file changed, 17 insertions(+), 10 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

author maintainer
#3 lore raw

PATCH 3/3 ieee802154: 6lowpan: add tx/rx stats

In reply to Alexander Aring

This patch adds support for increment transmit and receive stats. The meaning of these stats are IPv6 based, which shows the stats after running the 6lowpan adaptation layer (uncompression/compression, fragmentation handling) on receive and before the adaptation layer when transmit.

---
 net/ieee802154/6lowpan/rx.c | 2 ++
 net/ieee802154/6lowpan/tx.c | 4 ++++
 2 files changed, 6 insertions(+)
net/ieee802154/6lowpan/rx.c +2 -0
index b1fd47d..65d55e0 100644
@@ -29,6 +29,8 @@
 static int lowpan_give_skb_to_device(struct sk_buff *skb)
 {
 	skb->protocol = htons(ETH_P_IPV6);
+	skb->dev->stats.rx_packets++;
+	skb->dev->stats.rx_bytes += skb->len;
 
 	return netif_rx(skb);
 }
net/ieee802154/6lowpan/tx.c +4 -0
index 3b665e1..5736302 100644
@@ -192,6 +192,8 @@ lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *ldev,
 		}
 	} while (skb_unprocessed > frag_cap);
 
+	ldev->stats.tx_packets++;
+	ldev->stats.tx_bytes += dgram_size;
 	consume_skb(skb);
 	return NET_XMIT_SUCCESS;
 
@@ -277,6 +279,8 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
 
 	if (skb_tail_pointer(skb) - skb_network_header(skb) <= max_single) {
 		skb->dev = lowpan_dev_info(ldev)->wdev;
+		ldev->stats.tx_packets++;
+		ldev->stats.tx_bytes += dgram_size;
 		return dev_queue_xmit(skb);
 	} else {
 		netdev_tx_t rc;
Signature · 1 line
2.6.0
#4 lore raw

Re: [PATCH bluetooth-next 3/3] ieee802154: 6lowpan: add tx/rx stats

Hi Alex,

Quoted 11 lines

This patch adds support for increment transmit and receive stats. The meaning of these stats are IPv6 based, which shows the stats after running the 6lowpan adaptation layer (uncompression/compression, fragmentation handling) on receive and before the adaptation layer when transmit.

---
net/ieee802154/6lowpan/rx.c | 2 ++
net/ieee802154/6lowpan/tx.c | 4 ++++

2 files changed, 6 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel

#5 lore raw
In reply to Alexander Aring

Hi Alex,

Quoted 11 lines

This patch changes datagram size variable from u16 type to unsigned int. The reason is that an IPv6 header has an MAX_UIN16 payload length, but the datagram size is payload + IPv6 header length. This avoids overflows at some places.

---

net/ieee802154/6lowpan/6lowpan_i.h  | 4 ++--
net/ieee802154/6lowpan/reassembly.c | 2 +-
net/ieee802154/6lowpan/tx.c         | 8 ++++----
3 files changed, 7 insertions(+), 7 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel