Skip to contentSkip to conversation

6lowpan: reimplementation of fragmentation handling

PATCH Superseded Alexander Aring 7 participants 18 messages Feb 26, 2014 2 messages not in the archive

Subsystems (3)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

v4 cover 6lowpan: reimplementation of fragmentation handling

Hi,

this patch series reimplementation the fragmentation handling of 6lowpan accroding to rfc4944 [1].

The first big note is, that the current fragmentation behaviour isn't rfc complaint. The main issue is a wrong datagram_size value which needs to be:
datagram_size = ipv6_payload + ipv6 header + (maybe compressed transport header,
currently only udp is supported)

but the current datagram_size value is calculated as:
datagram_size = ipv6_payload

Fragmentation work in a linux<->linux communication only.

Why reimplementation?

I reimplemted the reassembly side only. The current behaviour is to allocate a skb with the reassembled size and hold all fragments in a list, protected by a spinlock. After we received all fragments (detected by the sum of all fragments, it begins to place all fragments into the allocated skb).

This reassembly implementation has some race condition. Additional I make it more rfc complaint. The current implementation match on the tag value inside the frag header only, but rfc4944 says we need to match on dst addr(mac), src addr(mac), tag value, datagram_size value. [2]

The new reassembly handling use the inet_frag api (I mean the callback interface of ipv6 and ipv4 reassembly). I looked into ipv6 and wanted to see how ipv6 is dealing with reassembly, so I based my code on this implementation.

On the sending side to generate the fragments I improved the current code to use the nearest 8 divided payload. (We can do that, because the mac layer has a dynamic size, so it depends on mac_header how big we can do the payload).

Of course I fix also the reassembly/sending side to be rfc complaint now.

Regards
Alexander Aring

[1] http://tools.ietf.org/html/rfc4944
[2] http://tools.ietf.org/html/rfc4944#section-5.3

changes since v2:
- rework checkpatch code style issue patch.
Merge two pr_debugs into one pr_debug.

changes since v3:
- rename 6lowpan.ko to 6lowpan_rtnl.c in commit msg of patch 5/8.

changes since v4:
- Add a new patch 2/8 to introduce lowpan_uncompress_size function. Also improving this function a little bit.
- Add a new patch 4/8 to change tag value to __be16.
- use skb_header_reset function on FRAG1 only, which should have the lowpan header. See lowpan_get_frag_info function. (slightly improving of fragmentation header parsing).
- changes types of variables to u16 in lowpan_skb_fragmentation.
- use lowpan_uncompress_size instead of storing necessary information in skb control block, this can be destroyed after dev_queue_xmit call. Thanks David for this hint.
- remove Tested-by: Martin Townsend <[email protected]>, because too many funcionality change.

Alexander Aring (8):
6lowpan: add frag information struct
6lowpan: add uncompress header size function 6lowpan: fix fragmentation on sending side 6lowpan: change tag type to __be16
6lowpan: move 6lowpan.c to 6lowpan_rtnl.c 6lowpan: fix some checkpatch issues
net: ns: add ieee802154_6lowpan namespace 6lowpan: handling 6lowpan fragmentation via inet_frag api

 include/net/ieee802154_netdev.h              |   7 +
 include/net/net_namespace.h                  |   4 +
 include/net/netns/ieee802154_6lowpan.h       |  22 ++
 net/ieee802154/6lowpan.h                     | 116 ++++++
 net/ieee802154/{6lowpan.c => 6lowpan_rtnl.c} | 323 +++++----------
 net/ieee802154/Makefile                      |   1 +
 net/ieee802154/reassembly.c                  | 565 +++++++++++++++++++++++++++
 net/ieee802154/reassembly.h                  |  66 ++++
 8 files changed, 868 insertions(+), 236 deletions(-)
 create mode 100644 include/net/netns/ieee802154_6lowpan.h
 rename net/ieee802154/{6lowpan.c => 6lowpan_rtnl.c} (70%)
 create mode 100644 net/ieee802154/reassembly.c
 create mode 100644 net/ieee802154/reassembly.h
Signature · 1 line
1.9.0

A message that is not in the archive (sent off-list or not yet received): 1393430712-11298-1-git-send-email-alex.aring-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH v4 1/8 6lowpan: add frag information struct

This patch adds a 6lowpan fragmentation struct into cb of skb which is necessary to hold fragmentation information.

---
 include/net/ieee802154_netdev.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/net/ieee802154_netdev.h +7 -0
index 8196d5d..97b2e34 100644
@@ -29,6 +29,12 @@
 
 #include <net/af_ieee802154.h>
 
+struct ieee802154_frag_info {
+	__be16 d_tag;
+	u16 d_size;
+	u8 d_offset;
+};
+
 /*
  * A control block of skb passed between the ARPHRD_IEEE802154 device
  * and other stack parts.
@@ -39,6 +45,7 @@ struct ieee802154_mac_cb {
 	struct ieee802154_addr da;
 	u8 flags;
 	u8 seq;
+	struct ieee802154_frag_info frag_info;
 };
 
 static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb)
Signature · 9 lines
1.9.0


------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
#3 lore raw

PATCH v4 4/8 6lowpan: change tag type to __be16

In reply to a message not in the archive
---
 net/ieee802154/6lowpan.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/ieee802154/6lowpan.c +3 -2
index 872c8f9..6b7d17f 100644
@@ -68,7 +68,7 @@ static LIST_HEAD(lowpan_devices);
 struct lowpan_dev_info {
 	struct net_device	*real_dev; /* real WPAN device ptr */
 	struct mutex		dev_list_mtx; /* mutex for list ops */
-	unsigned short		fragment_tag;
+	__be16			fragment_tag;
 };
 
 struct lowpan_dev_record {
@@ -424,7 +424,8 @@ lowpan_skb_fragmentation(struct sk_buff *skb, struct net_device *dev)
 {
 	int err;
 	u16 dgram_offset, dgram_size, payload_length, header_length,
-	    lowpan_size, frag_plen, offset, tag;
+	    lowpan_size, frag_plen, offset;
+	__be16 tag;
 	u8 head[5];
 
 	header_length = skb->mac_len;
Signature · 9 lines
1.9.0


------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
#4 lore raw

PATCH v4 6/8 6lowpan: fix some checkpatch issues

In reply to a message not in the archive

Detected with:

./scripts/checkpatch.pl --strict -f net/ieee802154/6lowpan_rtnl.c

---
 net/ieee802154/6lowpan_rtnl.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)
net/ieee802154/6lowpan_rtnl.c +9 -18
index 6b7d17f..f9c9548 100644
@@ -1,10 +1,8 @@
-/*
- * Copyright 2011, Siemens AG
+/* Copyright 2011, Siemens AG
  * written by Alexander Smirnov <[email protected]>
  */
 
-/*
- * Based on patches from Jon Smirl <[email protected]>
+/* Based on patches from Jon Smirl <[email protected]>
  * Copyright (c) 2011 Jon Smirl <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -15,10 +13,6 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 /* Jon's code is based on 6lowpan implementation for Contiki which is:
@@ -124,13 +118,11 @@ static int lowpan_header_create(struct sk_buff *skb,
 
 	lowpan_header_compress(skb, dev, type, daddr, saddr, len);
 
-	/*
-	 * NOTE1: I'm still unsure about the fact that compression and WPAN
+	/* NOTE1: I'm still unsure about the fact that compression and WPAN
 	 * header are created here and not later in the xmit. So wait for
 	 * an opinion of net maintainers.
 	 */
-	/*
-	 * NOTE2: to be absolutely correct, we must derive PANid information
+	/* NOTE2: to be absolutely correct, we must derive PANid information
 	 * from MAC subif of the 'dev' and 'real_dev' network devices, but
 	 * this isn't implemented in mainline yet, so currently we assign 0xff
 	 */
@@ -145,8 +137,7 @@ static int lowpan_header_create(struct sk_buff *skb,
 	/* intra-PAN communications */
 	da.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
 
-	/*
-	 * if the destination address is the broadcast address, use the
+	/* if the destination address is the broadcast address, use the
 	 * corresponding short address
 	 */
 	if (lowpan_is_addr_broadcast(daddr)) {
@@ -386,7 +377,7 @@ static int lowpan_set_address(struct net_device *dev, void *p)
 
 static int
 lowpan_fragment_xmit(struct sk_buff *skb, u8 *head,
-			int mlen, int plen, int offset, int type)
+		     int mlen, int plen, int offset, int type)
 {
 	struct sk_buff *frag;
 	int hlen;
@@ -478,8 +469,8 @@ lowpan_skb_fragmentation(struct sk_buff *skb, struct net_device *dev)
 		err = lowpan_fragment_xmit(skb, head, header_length, len,
 					   offset, LOWPAN_DISPATCH_FRAGN);
 		if (err) {
-			pr_debug("%s unable to send a subsequent FRAGN packet "
-				 "(tag: %d, offset: %d", __func__, tag, offset);
+			pr_debug("%s unable to send a FRAGN packet. (tag: %d, offset: %d)\n",
+				 __func__, tag, offset);
 			goto exit;
 		}
 
@@ -686,7 +677,7 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
 	lowpan_dev_info(dev)->fragment_tag = 0;
 	mutex_init(&lowpan_dev_info(dev)->dev_list_mtx);
 
-	entry = kzalloc(sizeof(struct lowpan_dev_record), GFP_KERNEL);
+	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
 	if (!entry) {
 		dev_put(real_dev);
 		lowpan_dev_info(dev)->real_dev = NULL;
Signature · 9 lines
1.9.0


------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk

A message that is not in the archive (sent off-list or not yet received): 1393430712-11298-7-git-send-email-alex.aring-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#6 lore raw

Re: [PATCH net-next v4 6/8] 6lowpan: fix some checkpatch issues

Quoted 3 lines · Alexander Aring

Detected with:

./scripts/checkpatch.pl --strict -f net/ieee802154/6lowpan_rtnl.c

Hello Alexander.

Can I suggest to you (and to David) that the
multiline comment style:

/*
* comment
*/

is fine and doesn't need correcting here at the
initial bits of a file before any actual code has
been written?

Assuming David agrees, I'll see about updating
checkpatch to avoid this warning at the beginning
of files.

net/ieee802154/6lowpan_rtnl.c

Quoted 1 line
net/ieee802154/6lowpan_rtnl.c +0 -0

[]

net/ieee802154/6lowpan_rtnl.c line 3

Quoted 6 lines
net/ieee802154/6lowpan_rtnl.c +1 -2
@@ -1,10 +1,8 @@
-/*
- * Copyright 2011, Siemens AG
+/* Copyright 2011, Siemens AG
  * written by Alexander Smirnov <[email protected]>
  */

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool. Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer Customize your own dashboards, set traffic alerts and generate reports. Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk

#7 lore raw

Re: [PATCH net-next v4 6/8] 6lowpan: fix some checkpatch issues

From: Joe Perches <[email protected]>
Date: Wed, 26 Feb 2014 09:24:56 -0800

Quoted 14 lines · Alexander Aring
Quoted 3 lines

Detected with:

./scripts/checkpatch.pl --strict -f net/ieee802154/6lowpan_rtnl.c

Hello Alexander.

Can I suggest to you (and to David) that the
multiline comment style:

/*
* comment
*/

Quoted 7 lines

is fine and doesn't need correcting here at the
initial bits of a file before any actual code has
been written?

Assuming David agrees, I'll see about updating
checkpatch to avoid this warning at the beginning
of files.

I'm largely ambivalent but prefer avoiding that wasted "/*" line.

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool. Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer Customize your own dashboards, set traffic alerts and generate reports. Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk

author maintainer
#8 lore raw

PATCH v4 2/8 6lowpan: add uncompress header size function

In reply to Alexander Aring
---
 net/ieee802154/6lowpan.h | 116 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
net/ieee802154/6lowpan.h +116 -0
index 2b835db..b6ae0bc 100644
@@ -306,6 +306,122 @@ static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data,
 	*hc_ptr += len;
 }
 
+static inline u8 lowpan_addr_mode_size(const u8 addr_mode)
+{
+	switch (addr_mode) {
+	case LOWPAN_IPHC_ADDR_00:
+		return 16;
+	case LOWPAN_IPHC_ADDR_01:
+		return 8;
+	case LOWPAN_IPHC_ADDR_02:
+		return 2;
+	default:
+		return 0;
+	}
+}
+
+static inline u8 lowpan_next_hdr_size(const u8 h_enc, u16 *uncomp_header)
+{
+	u8 ret = 1;
+
+	if ((h_enc & LOWPAN_NHC_UDP_MASK) == LOWPAN_NHC_UDP_ID) {
+		*uncomp_header += sizeof(struct udphdr);
+
+		switch (h_enc & LOWPAN_NHC_UDP_CS_P_11) {
+		case LOWPAN_NHC_UDP_CS_P_00:
+			ret += 4;
+			break;
+		case LOWPAN_NHC_UDP_CS_P_01:
+		case LOWPAN_NHC_UDP_CS_P_10:
+			ret += 3;
+			break;
+		case LOWPAN_NHC_UDP_CS_P_11:
+			ret++;
+			break;
+		default:
+			break;
+		}
+
+		if (!(h_enc & LOWPAN_NHC_UDP_CS_C))
+			ret += 2;
+	}
+
+	return ret;
+}
+
+/**
+ *	lowpan_uncompress_size - returns skb->len size with uncompressed header
+ *	@skb: sk_buff with 6lowpan header inside
+ *	@datagram_offset: optional to get the datagram_offset value
+ *
+ *	Returns the skb->len with uncompressed header
+ */
+static inline u16
+lowpan_uncompress_size(const struct sk_buff *skb, u16 *dgram_offset)
+{
+	u16 ret = 2, uncomp_header = sizeof(struct ipv6hdr);
+	u8 iphc0, iphc1, h_enc;
+
+	iphc0 = skb_network_header(skb)[0];
+	iphc1 = skb_network_header(skb)[1];
+
+	switch ((iphc0 & LOWPAN_IPHC_TF) >> 3) {
+	case 0:
+		ret += 4;
+		break;
+	case 1:
+		ret += 3;
+		break;
+	case 2:
+		ret++;
+		break;
+	default:
+		break;
+	}
+
+	if (!(iphc0 & LOWPAN_IPHC_NH_C))
+		ret++;
+
+	if (!(iphc0 & 0x03))
+		ret++;
+
+	ret += lowpan_addr_mode_size((iphc1 & LOWPAN_IPHC_SAM) >>
+				     LOWPAN_IPHC_SAM_BIT);
+
+	if (iphc1 & LOWPAN_IPHC_M) {
+		switch ((iphc1 & LOWPAN_IPHC_DAM_11) >>
+			LOWPAN_IPHC_DAM_BIT) {
+		case LOWPAN_IPHC_DAM_00:
+			ret += 16;
+			break;
+		case LOWPAN_IPHC_DAM_01:
+			ret += 6;
+			break;
+		case LOWPAN_IPHC_DAM_10:
+			ret += 4;
+			break;
+		case LOWPAN_IPHC_DAM_11:
+			ret++;
+			break;
+		default:
+			break;
+		}
+	} else {
+		ret += lowpan_addr_mode_size((iphc1 & LOWPAN_IPHC_DAM_11) >>
+					     LOWPAN_IPHC_DAM_BIT);
+	}
+
+	if (iphc0 & LOWPAN_IPHC_NH_C) {
+		h_enc = skb_network_header(skb)[ret];
+		ret += lowpan_next_hdr_size(h_enc, &uncomp_header);
+	}
+
+	if (dgram_offset)
+		*dgram_offset = uncomp_header;
+
+	return skb->len + uncomp_header - ret;
+}
+
 typedef int (*skb_delivery_cb)(struct sk_buff *skb, struct net_device *dev);
 
 int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
Signature · 1 line
1.9.0
#9 lore raw

RE: [PATCH net-next v4 2/8] 6lowpan: add uncompress header size function

From: Alexander Aring

Quoted 16 lines
---
 net/ieee802154/6lowpan.h | 116 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
net/ieee802154/6lowpan.h +3 -0
index 2b835db..b6ae0bc 100644
@@ -306,6 +306,122 @@ static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data,
 	*hc_ptr += len;
 }
 
+static inline u8 lowpan_addr_mode_size(const u8 addr_mode)
+{
+	switch (addr_mode) {

net/ieee802154/6lowpan.h static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data, · line 321

Quoted 10 lines
net/ieee802154/6lowpan.h +10 -0
+	case LOWPAN_IPHC_ADDR_00:
+		return 16;
+	case LOWPAN_IPHC_ADDR_01:
+		return 8;
+	case LOWPAN_IPHC_ADDR_02:
+		return 2;
+	default:
+		return 0;
+	}
+}

The compiler will generate much better code if you index an array instead of using a switch statement.

David

author maintainer
#10 lore raw

Re: [PATCH net-next v4 2/8] 6lowpan: add uncompress header size function

Hi David,

thanks for your reply.

Quoted 14 lines · David Laight

From: Alexander Aring

Quoted 13 lines
---
 net/ieee802154/6lowpan.h | 116 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
net/ieee802154/6lowpan.h +0 -0
index 2b835db..b6ae0bc 100644
@@ -306,6 +306,122 @@ static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data,
 	*hc_ptr += len;
 }
 
Quoted 18 lines

net/ieee802154/6lowpan.h static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data, · line 321

Quoted 13 lines
net/ieee802154/6lowpan.h +13 -0
+static inline u8 lowpan_addr_mode_size(const u8 addr_mode)
+{
+	switch (addr_mode) {
+	case LOWPAN_IPHC_ADDR_00:
+		return 16;
+	case LOWPAN_IPHC_ADDR_01:
+		return 8;
+	case LOWPAN_IPHC_ADDR_02:
+		return 2;
+	default:
+		return 0;
+	}
+}

The compiler will generate much better code if you index an array instead of using a switch statement.

You mean something like:

static inline u8 lowpan_addr_mode_size(const u8 addr_mode)

{
        const u8 res[] = { 16, 8, 2, 0 };
        return res[addr_mode];
}

or should I drop the array from the stack and declare it static?

?

- Alex

#11 lore raw

RE: [PATCH net-next v4 2/8] 6lowpan: add uncompress header size function

From: Alexander Aring

Quoted 2 lines · David Laight
Quoted 1 line

From: Alexander Aring

...

Quoted 21 lines
Quoted 8 lines
Quoted 8 lines
net/ieee802154/6lowpan.h +8 -0
+static inline u8 lowpan_addr_mode_size(const u8 addr_mode)
+{
+	switch (addr_mode) {
+	case LOWPAN_IPHC_ADDR_00:
+		return 16;
+	case LOWPAN_IPHC_ADDR_01:
+		return 8;
+	case LOWPAN_IPHC_ADDR_02:
Quoted 10 lines

net/ieee802154/6lowpan.h static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data, · line 321

Quoted 5 lines
net/ieee802154/6lowpan.h +5 -0
+		return 2;
+	default:
+		return 0;
+	}
+}

The compiler will generate much better code if you index an array instead of using a switch statement.

You mean something like:

Quoted 7 lines

static inline u8 lowpan_addr_mode_size(const u8 addr_mode)

{
        const u8 res[] = { 16, 8, 2, 0 };
        return res[addr_mode];
}

or should I drop the array from the stack and declare it static?

You definitely want the array to be static (as well as const). You could also use named initialisers.
If I've got the syntax right that would be:

		static const u8 sizes[] = {
			[LOWPAN_IPHC_ADDR_00] = 16,
			[LOWPAN_IPHC_ADDR_01] = 8,
			[LOWPAN_IPHC_ADDR_02] = 2,
		};
		return sizes[addr_mode];

Whether you need a bound check (or the 4th array index) depends on where the input value comes from.

David

#12 lore raw

Re: [PATCH net-next v4 2/8] 6lowpan: add uncompress header size function

In reply to David Laight
Quoted 1 line · David Laight

From: Alexander Aring

[]

Quoted 1 line

net/ieee802154/6lowpan.h

Quoted 1 line
net/ieee802154/6lowpan.h +0 -0

[]

Quoted 8 lines
Quoted 8 lines
net/ieee802154/6lowpan.h +8 -0
+static inline u8 lowpan_addr_mode_size(const u8 addr_mode)
+{
+	switch (addr_mode) {
+	case LOWPAN_IPHC_ADDR_00:
+		return 16;
+	case LOWPAN_IPHC_ADDR_01:
+		return 8;
+	case LOWPAN_IPHC_ADDR_02:
Quoted 8 lines

net/ieee802154/6lowpan.h static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data, · line 321

Quoted 5 lines
net/ieee802154/6lowpan.h +5 -0
+		return 2;
+	default:
+		return 0;
+	}
+}

The compiler will generate much better code if you index an array instead of using a switch statement.

Are you sure of that?

Perhaps the compiler would inline the assignment
anyway if addr_mode is __builtin_constant_p

gcc 4.8 here does the same thing with:

static inline unsigned char f1(unsigned char a)

{
	switch (a) {
	case 0: return 16;
	case 1: return 8;
	case 2: return 2;
	default: return 0;
	}
}

static inline unsigned char f2(unsigned char a)

{
	static const unsigned char rtns[] = { 16, 8, 2, 0 };

	return rtns[a & 3];
}
#13 lore raw

Re: [PATCH net-next v4 2/8] 6lowpan: add uncompress header size function

Quoted 39 lines · Joe Perches
Quoted 1 line · David Laight

From: Alexander Aring

[]

Quoted 1 line

net/ieee802154/6lowpan.h

Quoted 1 line
net/ieee802154/6lowpan.h +0 -0

[]

Quoted 8 lines
Quoted 8 lines
net/ieee802154/6lowpan.h +8 -0
+static inline u8 lowpan_addr_mode_size(const u8 addr_mode)
+{
+	switch (addr_mode) {
+	case LOWPAN_IPHC_ADDR_00:
+		return 16;
+	case LOWPAN_IPHC_ADDR_01:
+		return 8;
+	case LOWPAN_IPHC_ADDR_02:
Quoted 8 lines

net/ieee802154/6lowpan.h static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data, · line 321

Quoted 5 lines
net/ieee802154/6lowpan.h +5 -0
+		return 2;
+	default:
+		return 0;
+	}
+}

The compiler will generate much better code if you index an array instead of using a switch statement.

Are you sure of that?

Perhaps the compiler would inline the assignment
anyway if addr_mode is __builtin_constant_p

gcc 4.8 here does the same thing with:

static inline unsigned char f1(unsigned char a)

{
	switch (a) {
	case 0: return 16;
	case 1: return 8;
	case 2: return 2;
	default: return 0;
	}
}
Quoted 6 lines

static inline unsigned char f2(unsigned char a)

{
	static const unsigned char rtns[] = { 16, 8, 2, 0 };

	return rtns[a & 3];
}

to make a mask with & 3 is already done, so we don't need that. I am not sure what I should do now, change or not change? :-)

- Alex

------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool. Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer Customize your own dashboards, set traffic alerts and generate reports. Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk

#14 lore raw

Re: [PATCH net-next v4 2/8] 6lowpan: add uncompress header size function

Quoted 1 line · Alexander Aring

On Wed, Feb 26, 2014 at 10:24:45AM -0800, Joe Perches wrote:

[]

Quoted 2 lines
Quoted 2 lines

Perhaps the compiler would inline the assignment
anyway if addr_mode is __builtin_constant_p

[]

Quoted 1 line

I am not sure what I should do now, change or not change? :-)

Whatever you choose will be fine with me.

maintainer
#15 lore raw

Re: [PATCH net-next v4 2/8] 6lowpan: add uncompress header size function

In reply to David Laight

From: David Laight <[email protected]>
Date: Wed, 26 Feb 2014 16:10:05 +0000

Quoted 14 lines

From: Alexander Aring

Quoted 13 lines
---
 net/ieee802154/6lowpan.h | 116 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
net/ieee802154/6lowpan.h +0 -0
index 2b835db..b6ae0bc 100644
@@ -306,6 +306,122 @@ static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data,
 	*hc_ptr += len;
 }
 
Quoted 16 lines

net/ieee802154/6lowpan.h static inline void lowpan_push_hc_data(u8 **hc_ptr, const void *data, · line 321

Quoted 13 lines
net/ieee802154/6lowpan.h +13 -0
+static inline u8 lowpan_addr_mode_size(const u8 addr_mode)
+{
+	switch (addr_mode) {
+	case LOWPAN_IPHC_ADDR_00:
+		return 16;
+	case LOWPAN_IPHC_ADDR_01:
+		return 8;
+	case LOWPAN_IPHC_ADDR_02:
+		return 2;
+	default:
+		return 0;
+	}
+}

The compiler will generate much better code if you index an array instead of using a switch statement.

And please mark the array const :-)

author maintainer
#16 lore raw

PATCH v4 3/8 6lowpan: fix fragmentation on sending side

In reply to Alexander Aring

This patch fix the fragmentation on sending side according to rfc4944.

Also add improvement to use the full payload of a PDU which calculate the nearest divided to 8 payload length for the fragmentation datagram size attribute.

The main issue is that the datagram size of fragmentation header use the ipv6 payload length, but rfc4944 says it's the ipv6 payload length inclusive network header size (and transport header size if compressed).

---
 net/ieee802154/6lowpan.c | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)
net/ieee802154/6lowpan.c +27 -10
index 8edfea5..872c8f9 100644
@@ -422,44 +422,60 @@ lowpan_fragment_xmit(struct sk_buff *skb, u8 *head,
 static int
 lowpan_skb_fragmentation(struct sk_buff *skb, struct net_device *dev)
 {
-	int  err, header_length, payload_length, tag, offset = 0;
+	int err;
+	u16 dgram_offset, dgram_size, payload_length, header_length,
+	    lowpan_size, frag_plen, offset, tag;
 	u8 head[5];
 
 	header_length = skb->mac_len;
 	payload_length = skb->len - header_length;
 	tag = lowpan_dev_info(dev)->fragment_tag++;
+	lowpan_size = skb_network_header_len(skb);
+	dgram_size = lowpan_uncompress_size(skb, &dgram_offset) -
+		     header_length;
 
 	/* first fragment header */
-	head[0] = LOWPAN_DISPATCH_FRAG1 | ((payload_length >> 8) & 0x7);
-	head[1] = payload_length & 0xff;
+	head[0] = LOWPAN_DISPATCH_FRAG1 | ((dgram_size >> 8) & 0x7);
+	head[1] = dgram_size & 0xff;
 	head[2] = tag >> 8;
 	head[3] = tag & 0xff;
 
-	err = lowpan_fragment_xmit(skb, head, header_length, LOWPAN_FRAG_SIZE,
-				   0, LOWPAN_DISPATCH_FRAG1);
+	/* calc the nearest payload length(divided to 8) for first fragment
+	 * which fits into a IEEE802154_MTU
+	 */
+	frag_plen = round_down(IEEE802154_MTU - header_length -
+			       LOWPAN_FRAG1_HEAD_SIZE - lowpan_size -
+			       IEEE802154_MFR_SIZE, 8);
 
+	err = lowpan_fragment_xmit(skb, head, header_length,
+				   frag_plen + lowpan_size, 0,
+				   LOWPAN_DISPATCH_FRAG1);
 	if (err) {
 		pr_debug("%s unable to send FRAG1 packet (tag: %d)",
 			 __func__, tag);
 		goto exit;
 	}
 
-	offset = LOWPAN_FRAG_SIZE;
+	offset = lowpan_size + frag_plen;
+	dgram_offset += frag_plen;
 
 	/* next fragment header */
 	head[0] &= ~LOWPAN_DISPATCH_FRAG1;
 	head[0] |= LOWPAN_DISPATCH_FRAGN;
 
+	frag_plen = round_down(IEEE802154_MTU - header_length -
+			       LOWPAN_FRAGN_HEAD_SIZE - IEEE802154_MFR_SIZE, 8);
+
 	while (payload_length - offset > 0) {
-		int len = LOWPAN_FRAG_SIZE;
+		int len = frag_plen;
 
-		head[4] = offset / 8;
+		head[4] = dgram_offset >> 3;
 
 		if (payload_length - offset < len)
 			len = payload_length - offset;
 
-		err = lowpan_fragment_xmit(skb, head, header_length,
-					   len, offset, LOWPAN_DISPATCH_FRAGN);
+		err = lowpan_fragment_xmit(skb, head, header_length, len,
+					   offset, LOWPAN_DISPATCH_FRAGN);
 		if (err) {
 			pr_debug("%s unable to send a subsequent FRAGN packet "
 				 "(tag: %d, offset: %d", __func__, tag, offset);
@@ -467,6 +483,7 @@ lowpan_skb_fragmentation(struct sk_buff *skb, struct net_device *dev)
 		}
 
 		offset += len;
+		dgram_offset += len;
 	}
 
 exit:
Signature · 1 line
1.9.0
author maintainer
#17 lore raw

PATCH v4 5/8 6lowpan: move 6lowpan.c to 6lowpan_rtnl.c

In reply to Alexander Aring

We have a 6lowpan.c file and 6lowpan.ko file. To avoid confusing we should move 6lowpan.c to 6lowpan_rtnl.c. Then we can support multiple source files for 6lowpan module.

---
 net/ieee802154/{6lowpan.c => 6lowpan_rtnl.c} | 0
 net/ieee802154/Makefile                      | 1 +
 2 files changed, 1 insertion(+)
 rename net/ieee802154/{6lowpan.c => 6lowpan_rtnl.c} (100%)
net/ieee802154/6lowpan_rtnl.c renamed from net/ieee802154/6lowpan.c +0 -0
similarity index 100%
rename from net/ieee802154/6lowpan.c
rename to net/ieee802154/6lowpan_rtnl.c
net/ieee802154/Makefile +1 -0
index e8f0588..3d08adf 100644
@@ -2,5 +2,6 @@ obj-$(CONFIG_IEEE802154) += ieee802154.o af_802154.o
 obj-$(CONFIG_IEEE802154_6LOWPAN) += 6lowpan.o
 obj-$(CONFIG_6LOWPAN_IPHC) += 6lowpan_iphc.o
 
+6lowpan-y := 6lowpan_rtnl.o
 ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o
 af_802154-y := af_ieee802154.o raw.o dgram.o
Signature · 1 line
1.9.0
author maintainer
#18 lore raw

PATCH v4 7/8 net: ns: add ieee802154_6lowpan namespace

In reply to Alexander Aring

This patch adds necessary ieee802154 6lowpan namespace to provide the inet_frag information. This is a initial support for handling 6lowpan fragmentation with the inet_frag api.

---
 include/net/net_namespace.h            |  4 ++++
 include/net/netns/ieee802154_6lowpan.h | 13 +++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 include/net/netns/ieee802154_6lowpan.h
include/net/net_namespace.h +4 -0
index 991dcd9..79387f7 100644
@@ -15,6 +15,7 @@
 #include <net/netns/packet.h>
 #include <net/netns/ipv4.h>
 #include <net/netns/ipv6.h>
+#include <net/netns/ieee802154_6lowpan.h>
 #include <net/netns/sctp.h>
 #include <net/netns/dccp.h>
 #include <net/netns/netfilter.h>
@@ -90,6 +91,9 @@ struct net {
 #if IS_ENABLED(CONFIG_IPV6)
 	struct netns_ipv6	ipv6;
 #endif
+#if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN)
+	struct netns_ieee802154_lowpan	ieee802154_lowpan;
+#endif
 #if defined(CONFIG_IP_SCTP) || defined(CONFIG_IP_SCTP_MODULE)
 	struct netns_sctp	sctp;
 #endif
include/net/netns/ieee802154_6lowpan.h new file +13 -0
new file mode 100644
index 0000000..88110b7
@@ -0,0 +1,13 @@
+/*
+ * ieee802154 6lowpan in net namespaces
+ */
+
+#include <net/inet_frag.h>
+
+#ifndef __NETNS_IEEE802154_6LOWPAN_H__
+#define __NETNS_IEEE802154_6LOWPAN_H__
+
+struct netns_ieee802154_lowpan {
+};
+
+#endif
Signature · 1 line
1.9.0
author maintainer
#19 lore raw

PATCH v4 8/8 6lowpan: handling 6lowpan fragmentation via inet_frag api

In reply to Alexander Aring

This patch drops the current way of 6lowpan fragmentation on receiving side and replace it with a implementation which use the inet_frag api. The old fragmentation handling has some race conditions and isn't rfc4944 compatible. Also adding support to match fragments on destination and source address which is missing in the current implementation.

This patch add also a lookup function for uncompressed 6LoWPAN header size. This is needed to estimate the real size of fragmented packet.

---
 include/net/netns/ieee802154_6lowpan.h |   9 +
 net/ieee802154/6lowpan_rtnl.c          | 256 +++------------
 net/ieee802154/Makefile                |   2 +-
 net/ieee802154/reassembly.c            | 565 +++++++++++++++++++++++++++++++++
 net/ieee802154/reassembly.h            |  66 ++++
 5 files changed, 690 insertions(+), 208 deletions(-)
 create mode 100644 net/ieee802154/reassembly.c
 create mode 100644 net/ieee802154/reassembly.h
include/net/netns/ieee802154_6lowpan.h +9 -0
index 88110b7..079030c 100644
@@ -7,7 +7,16 @@
 #ifndef __NETNS_IEEE802154_6LOWPAN_H__
 #define __NETNS_IEEE802154_6LOWPAN_H__
 
+struct netns_sysctl_lowpan {
+#ifdef CONFIG_SYSCTL
+	struct ctl_table_header *frags_hdr;
+#endif
+};
+
 struct netns_ieee802154_lowpan {
+	struct netns_sysctl_lowpan sysctl;
+	struct netns_frags	frags;
+	u16			max_dsize;
 };
 
 #endif
net/ieee802154/6lowpan_rtnl.c +49 -207

340 lines not on this page · raw message

net/ieee802154/Makefile +1 -1
index 3d08adf..b113fc4 100644
@@ -2,6 +2,6 @@ obj-$(CONFIG_IEEE802154) += ieee802154.o af_802154.o
 obj-$(CONFIG_IEEE802154_6LOWPAN) += 6lowpan.o
 obj-$(CONFIG_6LOWPAN_IPHC) += 6lowpan_iphc.o
 
-6lowpan-y := 6lowpan_rtnl.o
+6lowpan-y := 6lowpan_rtnl.o reassembly.o
 ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o
 af_802154-y := af_ieee802154.o raw.o dgram.o
net/ieee802154/reassembly.c new file +565 -0

565 lines not on this page · raw message

net/ieee802154/reassembly.h new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
1.9.0