Skip to contentSkip to conversation

6lowpan: introduce generic next header compression layer

RFC In review Alexander Aring 1 participant 11 messages Aug 9, 2014 – Aug 10, 2014

Subsystems (4)
lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

cover 6lowpan: introduce generic next header compression layer

Hi,

this patch series introduce a generic interface for the 6LoWPAN header compression. Inside the 6LoWPAN header there is a variable length next header id if the compression bit inside the IPHC header is set. [0] This implementation use a red-black tree to find the nhc structure with the received variable length nhc id. Then it call the uncompression callback on received side. On sending side it used the nexthdr attribute of IPv6 header and call the compression callback on sending side.

We currently support only one next header compression, this is UDP. The callbacks for compression and uncompression contains the necessary informations to do UDP compression/uncompression only. If you need more informations inside the callbacks feel free to change it while supporting new next header compression formats.

It's just a basic support to handle this in a more generic way instead of hacking everything in iphc.c file.

Also adding basic support for RFC6282 next header compression values. We don't these, but we should drop these packets then instead sending garbage to next layer.

It's currently RFC, if nobody screams I will send "real" patches. Maybe we can do some things better.

- Alex

[0] http://tools.ietf.org/html/rfc6282#section-4.1

Alexander Aring (8):
6lowpan: add generic nhc layer interface
6lowpan: nhc layer udp compression
6lowpan: add hop-by-hop options skeleton
6lowpan: add routing skeleton
6lowpan: add fragment skeleton
6lowpan: add destination options skeleton
6lowpan: add mobility skeleton
6lowpan: add ipv6 skeleton

 net/6lowpan/Makefile     |   1 +
 net/6lowpan/iphc.c       | 184 +++++-------------------------------
 net/6lowpan/nhc/Makefile |  10 ++
 net/6lowpan/nhc/core.c   | 238 +++++++++++++++++++++++++++++++++++++++++++++++
 net/6lowpan/nhc/core.h   | 122 ++++++++++++++++++++++++
 net/6lowpan/nhc/dest.c   |  49 ++++++++++
 net/6lowpan/nhc/dest.h   |  11 +++
 net/6lowpan/nhc/frag.c   |  49 ++++++++++
 net/6lowpan/nhc/frag.h   |  11 +++
 net/6lowpan/nhc/hop.c    |  48 ++++++++++
 net/6lowpan/nhc/hop.h    |  11 +++
 net/6lowpan/nhc/ipv6.c   |  48 ++++++++++
 net/6lowpan/nhc/ipv6.h   |  11 +++
 net/6lowpan/nhc/mobil.c  |  49 ++++++++++
 net/6lowpan/nhc/mobil.h  |  11 +++
 net/6lowpan/nhc/route.c  |  48 ++++++++++
 net/6lowpan/nhc/route.h  |  11 +++
 net/6lowpan/nhc/udp.c    | 173 ++++++++++++++++++++++++++++++++++
 net/6lowpan/nhc/udp.h    |   9 ++
 19 files changed, 931 insertions(+), 163 deletions(-)
 create mode 100644 net/6lowpan/nhc/Makefile
 create mode 100644 net/6lowpan/nhc/core.c
 create mode 100644 net/6lowpan/nhc/core.h
 create mode 100644 net/6lowpan/nhc/dest.c
 create mode 100644 net/6lowpan/nhc/dest.h
 create mode 100644 net/6lowpan/nhc/frag.c
 create mode 100644 net/6lowpan/nhc/frag.h
 create mode 100644 net/6lowpan/nhc/hop.c
 create mode 100644 net/6lowpan/nhc/hop.h
 create mode 100644 net/6lowpan/nhc/ipv6.c
 create mode 100644 net/6lowpan/nhc/ipv6.h
 create mode 100644 net/6lowpan/nhc/mobil.c
 create mode 100644 net/6lowpan/nhc/mobil.h
 create mode 100644 net/6lowpan/nhc/route.c
 create mode 100644 net/6lowpan/nhc/route.h
 create mode 100644 net/6lowpan/nhc/udp.c
 create mode 100644 net/6lowpan/nhc/udp.h
Signature · 1 line
2.0.3
author maintainer
#1 lore raw

RFC 1/8 6lowpan: add generic nhc layer interface

This patch adds a generic next header compression layer interface. There exists various methods to do a header compression after 6LoWPAN header to save payload. This introduce a generic nhc header which allow a simple adding of a new header compression format instead of a static implementation inside the 6LoWPAN header compression and uncompression function.

---
 net/6lowpan/Makefile     |   1 +
 net/6lowpan/nhc/Makefile |   3 +
 net/6lowpan/nhc/core.c   | 180 +++++++++++++++++++++++++++++++++++++++++++++++
 net/6lowpan/nhc/core.h   | 122 ++++++++++++++++++++++++++++++++
 4 files changed, 306 insertions(+)
 create mode 100644 net/6lowpan/nhc/Makefile
 create mode 100644 net/6lowpan/nhc/core.c
 create mode 100644 net/6lowpan/nhc/core.h
net/6lowpan/Makefile +1 -0
index 415886b..d23d569 100644
@@ -1,3 +1,4 @@
 obj-$(CONFIG_6LOWPAN) := 6lowpan.o
+obj-$(CONFIG_6LOWPAN) += nhc/
 
 6lowpan-y := iphc.o
net/6lowpan/nhc/Makefile new file +3 -0
new file mode 100644
index 0000000..5fe76e47
@@ -0,0 +1,3 @@
+obj-$(CONFIG_6LOWPAN) += nhc.o
+
+nhc-y := core.o
net/6lowpan/nhc/core.c new file +180 -0

180 lines not on this page · raw message

net/6lowpan/nhc/core.h new file +122 -0

122 lines not on this page · raw message

Signature · 1 line
2.0.3
author maintainer
#4 lore raw

RFC 2/8 6lowpan: nhc layer udp compression

In reply to Alexander Aring

This patch move UDP header compression and uncompression into the generic 6LoWPAN nhc header compression layer and activate the nhc compression via the new nhc layer.

---
 net/6lowpan/iphc.c       | 184 ++++++-----------------------------------------
 net/6lowpan/nhc/Makefile |   3 +-
 net/6lowpan/nhc/core.c   |   4 +-
 net/6lowpan/nhc/udp.c    | 173 ++++++++++++++++++++++++++++++++++++++++++++
 net/6lowpan/nhc/udp.h    |   9 +++
 5 files changed, 208 insertions(+), 165 deletions(-)
 create mode 100644 net/6lowpan/nhc/udp.c
 create mode 100644 net/6lowpan/nhc/udp.h
net/6lowpan/iphc.c +21 -163
index 142eef5..a2ed820 100644
@@ -57,6 +57,8 @@
 #include <net/ipv6.h>
 #include <net/af_ieee802154.h>
 
+#include "nhc/core.h"
+
 /* Uncompress address function for source and
  * destination address(non-multicast).
  *
@@ -258,77 +260,6 @@ static int lowpan_uncompress_multicast_daddr(struct sk_buff *skb,
 	return 0;
 }
 
-static int uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
-{
-	bool fail;
-	u8 tmp = 0, val = 0;
-
-	fail = lowpan_fetch_skb(skb, &tmp, sizeof(tmp));
-
-	if ((tmp & LOWPAN_NHC_UDP_MASK) == LOWPAN_NHC_UDP_ID) {
-		pr_debug("UDP header uncompression\n");
-		switch (tmp & LOWPAN_NHC_UDP_CS_P_11) {
-		case LOWPAN_NHC_UDP_CS_P_00:
-			fail |= lowpan_fetch_skb(skb, &uh->source,
-						 sizeof(uh->source));
-			fail |= lowpan_fetch_skb(skb, &uh->dest,
-						 sizeof(uh->dest));
-			break;
-		case LOWPAN_NHC_UDP_CS_P_01:
-			fail |= lowpan_fetch_skb(skb, &uh->source,
-						 sizeof(uh->source));
-			fail |= lowpan_fetch_skb(skb, &val, sizeof(val));
-			uh->dest = htons(val + LOWPAN_NHC_UDP_8BIT_PORT);
-			break;
-		case LOWPAN_NHC_UDP_CS_P_10:
-			fail |= lowpan_fetch_skb(skb, &val, sizeof(val));
-			uh->source = htons(val + LOWPAN_NHC_UDP_8BIT_PORT);
-			fail |= lowpan_fetch_skb(skb, &uh->dest,
-						 sizeof(uh->dest));
-			break;
-		case LOWPAN_NHC_UDP_CS_P_11:
-			fail |= lowpan_fetch_skb(skb, &val, sizeof(val));
-			uh->source = htons(LOWPAN_NHC_UDP_4BIT_PORT +
-					   (val >> 4));
-			uh->dest = htons(LOWPAN_NHC_UDP_4BIT_PORT +
-					 (val & 0x0f));
-			break;
-		default:
-			pr_debug("ERROR: unknown UDP format\n");
-			goto err;
-		}
-
-		pr_debug("uncompressed UDP ports: src = %d, dst = %d\n",
-			 ntohs(uh->source), ntohs(uh->dest));
-
-		/* checksum */
-		if (tmp & LOWPAN_NHC_UDP_CS_C) {
-			pr_debug_ratelimited("checksum elided currently not supported\n");
-			goto err;
-		} else {
-			fail |= lowpan_fetch_skb(skb, &uh->check,
-						 sizeof(uh->check));
-		}
-
-		/* UDP length needs to be infered from the lower layers
-		 * here, we obtain the hint from the remaining size of the
-		 * frame
-		 */
-		uh->len = htons(skb->len + sizeof(struct udphdr));
-		pr_debug("uncompressed UDP length: src = %d", ntohs(uh->len));
-	} else {
-		pr_debug("ERROR: unsupported NH format\n");
-		goto err;
-	}
-
-	if (fail)
-		goto err;
-
-	return 0;
-err:
-	return -EINVAL;
-}
-
 /* TTL uncompression values */
 static const u8 lowpan_ttl_values[] = { 0, 1, 64, 255 };
 
@@ -457,34 +388,10 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
 			goto drop;
 	}
 
-	/* UDP data uncompression */
 	if (iphc0 & LOWPAN_IPHC_NH_C) {
-		struct udphdr uh;
-		struct sk_buff *new;
-
-		if (uncompress_udp_header(skb, &uh))
+		err = lowpan_nhc_do_uncompression(&skb, &hdr);
+		if (err < 0)
 			goto drop;
-
-		/* replace the compressed UDP head by the uncompressed UDP
-		 * header
-		 */
-		new = skb_copy_expand(skb, sizeof(struct udphdr),
-				      skb_tailroom(skb), GFP_ATOMIC);
-		kfree_skb(skb);
-
-		if (!new)
-			return -ENOMEM;
-
-		skb = new;
-
-		skb_push(skb, sizeof(struct udphdr));
-		skb_reset_transport_header(skb);
-		skb_copy_to_linear_data(skb, &uh, sizeof(struct udphdr));
-
-		raw_dump_table(__func__, "raw UDP header dump",
-			       (u8 *)&uh, sizeof(uh));
-
-		hdr.nexthdr = UIP_PROTO_UDP;
 	}
 
 	hdr.payload_len = htons(skb->len);
@@ -533,68 +440,12 @@ static u8 lowpan_compress_addr_64(u8 **hc_ptr, u8 shift,
 	return rol8(val, shift);
 }
 
-static void compress_udp_header(u8 **hc_ptr, struct sk_buff *skb)
-{
-	struct udphdr *uh = udp_hdr(skb);
-	u8 tmp;
-
-	if (((ntohs(uh->source) & LOWPAN_NHC_UDP_4BIT_MASK) ==
-	     LOWPAN_NHC_UDP_4BIT_PORT) &&
-	    ((ntohs(uh->dest) & LOWPAN_NHC_UDP_4BIT_MASK) ==
-	     LOWPAN_NHC_UDP_4BIT_PORT)) {
-		pr_debug("UDP header: both ports compression to 4 bits\n");
-		/* compression value */
-		tmp = LOWPAN_NHC_UDP_CS_P_11;
-		lowpan_push_hc_data(hc_ptr, &tmp, sizeof(tmp));
-		/* source and destination port */
-		tmp = ntohs(uh->dest) - LOWPAN_NHC_UDP_4BIT_PORT +
-		      ((ntohs(uh->source) - LOWPAN_NHC_UDP_4BIT_PORT) << 4);
-		lowpan_push_hc_data(hc_ptr, &tmp, sizeof(tmp));
-	} else if ((ntohs(uh->dest) & LOWPAN_NHC_UDP_8BIT_MASK) ==
-			LOWPAN_NHC_UDP_8BIT_PORT) {
-		pr_debug("UDP header: remove 8 bits of dest\n");
-		/* compression value */
-		tmp = LOWPAN_NHC_UDP_CS_P_01;
-		lowpan_push_hc_data(hc_ptr, &tmp, sizeof(tmp));
-		/* source port */
-		lowpan_push_hc_data(hc_ptr, &uh->source, sizeof(uh->source));
-		/* destination port */
-		tmp = ntohs(uh->dest) - LOWPAN_NHC_UDP_8BIT_PORT;
-		lowpan_push_hc_data(hc_ptr, &tmp, sizeof(tmp));
-	} else if ((ntohs(uh->source) & LOWPAN_NHC_UDP_8BIT_MASK) ==
-			LOWPAN_NHC_UDP_8BIT_PORT) {
-		pr_debug("UDP header: remove 8 bits of source\n");
-		/* compression value */
-		tmp = LOWPAN_NHC_UDP_CS_P_10;
-		lowpan_push_hc_data(hc_ptr, &tmp, sizeof(tmp));
-		/* source port */
-		tmp = ntohs(uh->source) - LOWPAN_NHC_UDP_8BIT_PORT;
-		lowpan_push_hc_data(hc_ptr, &tmp, sizeof(tmp));
-		/* destination port */
-		lowpan_push_hc_data(hc_ptr, &uh->dest, sizeof(uh->dest));
-	} else {
-		pr_debug("UDP header: can't compress\n");
-		/* compression value */
-		tmp = LOWPAN_NHC_UDP_CS_P_00;
-		lowpan_push_hc_data(hc_ptr, &tmp, sizeof(tmp));
-		/* source port */
-		lowpan_push_hc_data(hc_ptr, &uh->source, sizeof(uh->source));
-		/* destination port */
-		lowpan_push_hc_data(hc_ptr, &uh->dest, sizeof(uh->dest));
-	}
-
-	/* checksum is always inline */
-	lowpan_push_hc_data(hc_ptr, &uh->check, sizeof(uh->check));
-
-	/* skip the UDP header */
-	skb_pull(skb, sizeof(struct udphdr));
-}
-
 int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
 			   unsigned short type, const void *_daddr,
 			   const void *_saddr, unsigned int len)
 {
 	u8 tmp, iphc0, iphc1, *hc_ptr;
+	struct lowpan_nhc *nhc;
 	struct ipv6hdr *hdr;
 	u8 head[100] = {};
 	int addr_type;
@@ -672,13 +523,10 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
 		}
 	}
 
-	/* NOTE: payload length is always compressed */
-
-	/* Next Header is compress if UDP */
-	if (hdr->nexthdr == UIP_PROTO_UDP)
+	nhc = lowpan_search_nhc_by_nexthdr(hdr->nexthdr);
+	if (nhc)
 		iphc0 |= LOWPAN_IPHC_NH_C;
-
-	if ((iphc0 & LOWPAN_IPHC_NH_C) == 0)
+	else
 		lowpan_push_hc_data(&hc_ptr, &hdr->nexthdr,
 				    sizeof(hdr->nexthdr));
 
@@ -766,9 +614,7 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
 		}
 	}
 
-	/* UDP header compression */
-	if (hdr->nexthdr == UIP_PROTO_UDP)
-		compress_udp_header(&hc_ptr, skb);
+	lowpan_nhc_do_compression(nhc, skb, &hc_ptr, &iphc0);
 
 	head[0] = iphc0;
 	head[1] = iphc1;
@@ -786,4 +632,16 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
 }
 EXPORT_SYMBOL_GPL(lowpan_header_compress);
 
+static int __init iphc_init_module(void)
+{
+	return lowpan_init_nhc();
+}
+
+static void __exit iphc_cleanup_module(void)
+{
+	lowpan_cleanup_nhc();
+}
+
 MODULE_LICENSE("GPL");
+module_init(iphc_init_module);
+module_exit(iphc_cleanup_module);
net/6lowpan/nhc/Makefile +2 -1
index 5fe76e47..07431c2 100644
@@ -1,3 +1,4 @@
 obj-$(CONFIG_6LOWPAN) += nhc.o
 
-nhc-y := core.o
+nhc-y := core.o \
+	 udp.o
net/6lowpan/nhc/core.c +3 -1
index 0bf103d..0f98132 100644
@@ -15,6 +15,7 @@
 #include <net/ipv6.h>
 
 #include "core.h"
+#include "udp.h"
 
 static struct rb_root rb_root = RB_ROOT;
 static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX];
@@ -172,9 +173,10 @@ EXPORT_SYMBOL(lowpan_del_nhc);
 
 int lowpan_init_nhc(void)
 {
-	return 0;
+	return lowpan_init_nhc_udp();
 }
 
 void lowpan_cleanup_nhc(void)
 {
+	lowpan_cleanup_nhc_udp();
 }
net/6lowpan/nhc/udp.c new file +173 -0

173 lines not on this page · raw message

net/6lowpan/nhc/udp.h new file +9 -0
new file mode 100644
index 0000000..ae99448
@@ -0,0 +1,9 @@
+#ifndef __6LOWPAN_NHC_UDP_H
+#define __6LOWPAN_NHC_UDP_H
+
+#define LOWPAN_NHC_UDP_LEN	1
+
+int lowpan_init_nhc_udp(void);
+void lowpan_cleanup_nhc_udp(void);
+
+#endif /* __6LOWPAN_NHC_UDP_H */
Signature · 1 line
2.0.3
author maintainer
#5 lore raw

RFC 3/8 6lowpan: add hop-by-hop options skeleton

In reply to Alexander Aring

Currenlty not support. Received packets with this nhc id should be dropped.

---
 net/6lowpan/nhc/Makefile |  3 ++-
 net/6lowpan/nhc/core.c   | 18 +++++++++++++++++-
 net/6lowpan/nhc/hop.c    | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/6lowpan/nhc/hop.h    | 11 +++++++++++
 4 files changed, 78 insertions(+), 2 deletions(-)
 create mode 100644 net/6lowpan/nhc/hop.c
 create mode 100644 net/6lowpan/nhc/hop.h
net/6lowpan/nhc/Makefile +2 -1
index 07431c2..b82135a 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_6LOWPAN) += nhc.o
 
 nhc-y := core.o \
-	 udp.o
+	 udp.o \
+	 hop.o
net/6lowpan/nhc/core.c +17 -1
index 0f98132..80ed357 100644
@@ -16,6 +16,7 @@
 
 #include "core.h"
 #include "udp.h"
+#include "hop.h"
 
 static struct rb_root rb_root = RB_ROOT;
 static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX];
@@ -173,10 +174,25 @@ EXPORT_SYMBOL(lowpan_del_nhc);
 
 int lowpan_init_nhc(void)
 {
-	return lowpan_init_nhc_udp();
+	int ret;
+
+	ret = lowpan_init_nhc_udp();
+	if (ret < 0)
+		goto out;
+
+	ret = lowpan_init_nhc_hop();
+	if (ret < 0)
+		goto hop_fail;
+out:
+	return ret;
+
+hop_fail:
+	lowpan_cleanup_nhc_udp();
+	goto out;
 }
 
 void lowpan_cleanup_nhc(void)
 {
 	lowpan_cleanup_nhc_udp();
+	lowpan_cleanup_nhc_hop();
 }
net/6lowpan/nhc/hop.c new file +48 -0

48 lines not on this page · raw message

net/6lowpan/nhc/hop.h new file +11 -0
new file mode 100644
index 0000000..c03fc58
@@ -0,0 +1,11 @@
+#ifndef __6LOWPAN_NHC_HOP_H
+#define __6LOWPAN_NHC_HOP_H
+
+#define LOWPAN_NHC_HOP_LEN	1
+#define LOWPAN_NHC_HOP_ID_0	0xe0
+#define LOWPAN_NHC_HOP_MASK_0	0xfe
+
+int lowpan_init_nhc_hop(void);
+void lowpan_cleanup_nhc_hop(void);
+
+#endif /* __6LOWPAN_NHC_HOP_H */
Signature · 1 line
2.0.3
author maintainer
#6 lore raw

RFC 4/8 6lowpan: add routing skeleton

In reply to Alexander Aring

Currenlty not support. Received packets with this nhc id should be dropped.

---
 net/6lowpan/nhc/Makefile |  3 ++-
 net/6lowpan/nhc/core.c   |  8 ++++++++
 net/6lowpan/nhc/route.c  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/6lowpan/nhc/route.h  | 11 +++++++++++
 4 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 net/6lowpan/nhc/route.c
 create mode 100644 net/6lowpan/nhc/route.h
net/6lowpan/nhc/Makefile +2 -1
index b82135a..81aa18d 100644
@@ -2,4 +2,5 @@ obj-$(CONFIG_6LOWPAN) += nhc.o
 
 nhc-y := core.o \
 	 udp.o \
-	 hop.o
+	 hop.o \
+	 route.o
net/6lowpan/nhc/core.c +8 -0
index 80ed357..db499bb 100644
@@ -17,6 +17,7 @@
 #include "core.h"
 #include "udp.h"
 #include "hop.h"
+#include "route.h"
 
 static struct rb_root rb_root = RB_ROOT;
 static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX];
@@ -183,9 +184,15 @@ int lowpan_init_nhc(void)
 	ret = lowpan_init_nhc_hop();
 	if (ret < 0)
 		goto hop_fail;
+
+	ret = lowpan_init_nhc_route();
+	if (ret < 0)
+		goto route_fail;
 out:
 	return ret;
 
+route_fail:
+	lowpan_cleanup_nhc_hop();
 hop_fail:
 	lowpan_cleanup_nhc_udp();
 	goto out;
@@ -195,4 +202,5 @@ void lowpan_cleanup_nhc(void)
 {
 	lowpan_cleanup_nhc_udp();
 	lowpan_cleanup_nhc_hop();
+	lowpan_cleanup_nhc_route();
 }
net/6lowpan/nhc/route.c new file +48 -0

48 lines not on this page · raw message

net/6lowpan/nhc/route.h new file +11 -0
new file mode 100644
index 0000000..78cd6b5
@@ -0,0 +1,11 @@
+#ifndef __6LOWPAN_NHC_ROUTE_H
+#define __6LOWPAN_NHC_ROUTE_H
+
+#define LOWPAN_NHC_ROUTE_LEN	1
+#define LOWPAN_NHC_ROUTE_ID_0	0xe2
+#define LOWPAN_NHC_ROUTE_MASK_0	0xfe
+
+int lowpan_init_nhc_route(void);
+void lowpan_cleanup_nhc_route(void);
+
+#endif /* __6LOWPAN_NHC_ROUTE_H */
Signature · 1 line
2.0.3
author maintainer
#7 lore raw

RFC 5/8 6lowpan: add fragment skeleton

In reply to Alexander Aring

Currenlty not support. Received packets with this nhc id should be dropped.

---
 net/6lowpan/nhc/Makefile |  3 ++-
 net/6lowpan/nhc/core.c   |  8 ++++++++
 net/6lowpan/nhc/frag.c   | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/6lowpan/nhc/frag.h   | 11 +++++++++++
 4 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 net/6lowpan/nhc/frag.c
 create mode 100644 net/6lowpan/nhc/frag.h
net/6lowpan/nhc/Makefile +2 -1
index 81aa18d..e524c57 100644
@@ -3,4 +3,5 @@ obj-$(CONFIG_6LOWPAN) += nhc.o
 nhc-y := core.o \
 	 udp.o \
 	 hop.o \
-	 route.o
+	 route.o \
+	 frag.o
net/6lowpan/nhc/core.c +8 -0
index db499bb..728dd06 100644
@@ -18,6 +18,7 @@
 #include "udp.h"
 #include "hop.h"
 #include "route.h"
+#include "frag.h"
 
 static struct rb_root rb_root = RB_ROOT;
 static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX];
@@ -188,9 +189,15 @@ int lowpan_init_nhc(void)
 	ret = lowpan_init_nhc_route();
 	if (ret < 0)
 		goto route_fail;
+
+	ret = lowpan_init_nhc_frag();
+	if (ret < 0)
+		goto frag_fail;
 out:
 	return ret;
 
+frag_fail:
+	lowpan_cleanup_nhc_route();
 route_fail:
 	lowpan_cleanup_nhc_hop();
 hop_fail:
@@ -203,4 +210,5 @@ void lowpan_cleanup_nhc(void)
 	lowpan_cleanup_nhc_udp();
 	lowpan_cleanup_nhc_hop();
 	lowpan_cleanup_nhc_route();
+	lowpan_cleanup_nhc_frag();
 }
net/6lowpan/nhc/frag.c new file +49 -0

49 lines not on this page · raw message

net/6lowpan/nhc/frag.h new file +11 -0
new file mode 100644
index 0000000..e760720
@@ -0,0 +1,11 @@
+#ifndef __6LOWPAN_NHC_FRAG_H
+#define __6LOWPAN_NHC_FRAG_H
+
+#define LOWPAN_NHC_FRAG_LEN	1
+#define LOWPAN_NHC_FRAG_ID_0	0xe4
+#define LOWPAN_NHC_FRAG_MASK_0	0xfe
+
+int lowpan_init_nhc_frag(void);
+void lowpan_cleanup_nhc_frag(void);
+
+#endif /* __6LOWPAN_NHC_FRAG_H */
Signature · 1 line
2.0.3
author maintainer
#8 lore raw

RFC 6/8 6lowpan: add destination options skeleton

In reply to Alexander Aring

Currenlty not support. Received packets with this nhc id should be dropped.

---
 net/6lowpan/nhc/Makefile |  3 ++-
 net/6lowpan/nhc/core.c   |  8 ++++++++
 net/6lowpan/nhc/dest.c   | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/6lowpan/nhc/dest.h   | 11 +++++++++++
 4 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 net/6lowpan/nhc/dest.c
 create mode 100644 net/6lowpan/nhc/dest.h
net/6lowpan/nhc/Makefile +2 -1
index e524c57..1b67930 100644
@@ -4,4 +4,5 @@ nhc-y := core.o \
 	 udp.o \
 	 hop.o \
 	 route.o \
-	 frag.o
+	 frag.o \
+	 dest.o
net/6lowpan/nhc/core.c +8 -0
index 728dd06..73d9e1e 100644
@@ -19,6 +19,7 @@
 #include "hop.h"
 #include "route.h"
 #include "frag.h"
+#include "dest.h"
 
 static struct rb_root rb_root = RB_ROOT;
 static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX];
@@ -193,9 +194,15 @@ int lowpan_init_nhc(void)
 	ret = lowpan_init_nhc_frag();
 	if (ret < 0)
 		goto frag_fail;
+
+	ret = lowpan_init_nhc_dest();
+	if (ret < 0)
+		goto dest_fail;
 out:
 	return ret;
 
+dest_fail:
+	lowpan_cleanup_nhc_frag();
 frag_fail:
 	lowpan_cleanup_nhc_route();
 route_fail:
@@ -211,4 +218,5 @@ void lowpan_cleanup_nhc(void)
 	lowpan_cleanup_nhc_hop();
 	lowpan_cleanup_nhc_route();
 	lowpan_cleanup_nhc_frag();
+	lowpan_cleanup_nhc_dest();
 }
net/6lowpan/nhc/dest.c new file +49 -0

49 lines not on this page · raw message

net/6lowpan/nhc/dest.h new file +11 -0
new file mode 100644
index 0000000..f537e3f
@@ -0,0 +1,11 @@
+#ifndef __6LOWPAN_NHC_DEST_H
+#define __6LOWPAN_NHC_DEST_H
+
+#define LOWPAN_NHC_DEST_LEN	1
+#define LOWPAN_NHC_DEST_ID_0	0xe6
+#define LOWPAN_NHC_DEST_MASK_0	0xfe
+
+int lowpan_init_nhc_dest(void);
+void lowpan_cleanup_nhc_dest(void);
+
+#endif /* __6LOWPAN_NHC_DEST_H */
Signature · 1 line
2.0.3
author maintainer
#9 lore raw

RFC 7/8 6lowpan: add mobility skeleton

In reply to Alexander Aring

Currenlty not support. Received packets with this nhc id should be dropped.

---
 net/6lowpan/nhc/Makefile |  3 ++-
 net/6lowpan/nhc/core.c   |  8 ++++++++
 net/6lowpan/nhc/mobil.c  | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/6lowpan/nhc/mobil.h  | 11 +++++++++++
 4 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 net/6lowpan/nhc/mobil.c
 create mode 100644 net/6lowpan/nhc/mobil.h
net/6lowpan/nhc/Makefile +2 -1
index 1b67930..9915c31 100644
@@ -5,4 +5,5 @@ nhc-y := core.o \
 	 hop.o \
 	 route.o \
 	 frag.o \
-	 dest.o
+	 dest.o \
+	 mobil.o
net/6lowpan/nhc/core.c +8 -0
index 73d9e1e..1ee9750 100644
@@ -20,6 +20,7 @@
 #include "route.h"
 #include "frag.h"
 #include "dest.h"
+#include "mobil.h"
 
 static struct rb_root rb_root = RB_ROOT;
 static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX];
@@ -198,9 +199,15 @@ int lowpan_init_nhc(void)
 	ret = lowpan_init_nhc_dest();
 	if (ret < 0)
 		goto dest_fail;
+
+	ret = lowpan_init_nhc_mobil();
+	if (ret < 0)
+		goto mobil_fail;
 out:
 	return ret;
 
+mobil_fail:
+	lowpan_cleanup_nhc_dest();
 dest_fail:
 	lowpan_cleanup_nhc_frag();
 frag_fail:
@@ -219,4 +226,5 @@ void lowpan_cleanup_nhc(void)
 	lowpan_cleanup_nhc_route();
 	lowpan_cleanup_nhc_frag();
 	lowpan_cleanup_nhc_dest();
+	lowpan_cleanup_nhc_mobil();
 }
net/6lowpan/nhc/mobil.c new file +49 -0

49 lines not on this page · raw message

net/6lowpan/nhc/mobil.h new file +11 -0
new file mode 100644
index 0000000..fcfdb55
@@ -0,0 +1,11 @@
+#ifndef __6LOWPAN_NHC_MOBIL_H
+#define __6LOWPAN_NHC_MOBIL_H
+
+#define LOWPAN_NHC_MOBIL_LEN	1
+#define LOWPAN_NHC_MOBIL_ID_0	0xe8
+#define LOWPAN_NHC_MOBIL_MASK_0	0xfe
+
+int lowpan_init_nhc_mobil(void);
+void lowpan_cleanup_nhc_mobil(void);
+
+#endif /* __6LOWPAN_NHC_MOBIL_H */
Signature · 1 line
2.0.3
author maintainer
#10 lore raw

RFC 8/8 6lowpan: add ipv6 skeleton

In reply to Alexander Aring

Currenlty not support. Received packets with this nhc id should be dropped.

---
 net/6lowpan/nhc/Makefile |  3 ++-
 net/6lowpan/nhc/core.c   |  8 ++++++++
 net/6lowpan/nhc/ipv6.c   | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/6lowpan/nhc/ipv6.h   | 11 +++++++++++
 4 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 net/6lowpan/nhc/ipv6.c
 create mode 100644 net/6lowpan/nhc/ipv6.h
net/6lowpan/nhc/Makefile +2 -1
index 9915c31..4d91480 100644
@@ -6,4 +6,5 @@ nhc-y := core.o \
 	 route.o \
 	 frag.o \
 	 dest.o \
-	 mobil.o
+	 mobil.o \
+	 ipv6.o
net/6lowpan/nhc/core.c +8 -0
index 1ee9750..66907ff 100644
@@ -21,6 +21,7 @@
 #include "frag.h"
 #include "dest.h"
 #include "mobil.h"
+#include "ipv6.h"
 
 static struct rb_root rb_root = RB_ROOT;
 static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX];
@@ -203,9 +204,15 @@ int lowpan_init_nhc(void)
 	ret = lowpan_init_nhc_mobil();
 	if (ret < 0)
 		goto mobil_fail;
+
+	ret = lowpan_init_nhc_ipv6();
+	if (ret < 0)
+		goto ipv6_fail;
 out:
 	return ret;
 
+ipv6_fail:
+	lowpan_cleanup_nhc_mobil();
 mobil_fail:
 	lowpan_cleanup_nhc_dest();
 dest_fail:
@@ -227,4 +234,5 @@ void lowpan_cleanup_nhc(void)
 	lowpan_cleanup_nhc_frag();
 	lowpan_cleanup_nhc_dest();
 	lowpan_cleanup_nhc_mobil();
+	lowpan_cleanup_nhc_ipv6();
 }
net/6lowpan/nhc/ipv6.c new file +48 -0

48 lines not on this page · raw message

net/6lowpan/nhc/ipv6.h new file +11 -0
new file mode 100644
index 0000000..defc183
@@ -0,0 +1,11 @@
+#ifndef __6LOWPAN_NHC_IPV6_H
+#define __6LOWPAN_NHC_IPV6_H
+
+#define LOWPAN_NHC_IPV6_LEN	1
+#define LOWPAN_NHC_IPV6_ID_0	0xee
+#define LOWPAN_NHC_IPV6_MASK_0	0xfe
+
+int lowpan_init_nhc_ipv6(void);
+void lowpan_cleanup_nhc_ipv6(void);
+
+#endif /* __6LOWPAN_NHC_IPV6_H */
Signature · 1 line
2.0.3
author maintainer
#2 lore raw

Re: [RFC bluetooth-next 1/8] 6lowpan: add generic nhc layer interface

In reply to Alexander Aring

Hi,

On Sat, Aug 09, 2014 at 09:02:16PM +0200, Alexander Aring wrote:
...

Quoted 7 lines
net/6lowpan/nhc/core.h new file +7 -0
+
+/**
+ * LOWPAN_NHC - helper macro to generate nh id fields and lowpan_nhc struct
+ *
+ * @varname: variable name of the lowpan_nhc struct.
+ * @nhcname: const char * of common header compression name.
+ * @nexthdr: ipv6 nexthdr field for the header compression.

net/6lowpan/nhc/core.h line 26

Quoted 10 lines
net/6lowpan/nhc/core.h new file +10 -0
+ * @nhidsetup: callback to setup id and mask values.
+ * @nhidlen: len for the next header id and mask, should be always the same.
+ * @nhuncompress: callback for uncompression call.
+ * @nhcompress: callback for compression call.
+ */
+#define LOWPAN_NHC(varname, nhcname, nhnexthdr,	\
+		   nhidsetup, nhidlen,		\
+		   nhuncompress, nhcompress)	\
+	static u8 name##_val[nhidlen];		\
+	static u8 name##_mask[nhidlen];		\

this should be varname instead name. I will fix it for the next version.

net/6lowpan/nhc/core.h line 37

Quoted 11 lines
net/6lowpan/nhc/core.h new file +11 -0
+	static struct lowpan_nhc varname = {	\
+		.name		= nhcname,	\
+		.nexthdr	= nhnexthdr,	\
+		.id		= name##_val,	\
+		.idmask		= name##_mask,	\
+		.idlen		= nhidlen,	\
+		.idsetup	= nhidsetup,	\
+		.uncompress	= nhuncompress,	\
+		.compress	= nhcompress,	\
+	}
+

- Alex

author maintainer
#3 lore raw

Re: [RFC bluetooth-next 1/8] 6lowpan: add generic nhc layer interface

In reply to Alexander Aring

On Sat, Aug 09, 2014 at 09:02:16PM +0200, Alexander Aring wrote:
....

net/6lowpan/nhc/core.c line 136

Quoted 12 lines
net/6lowpan/nhc/core.c new file +12 -0
+
+	nhc = lowpan_search_nhc_by_nhcid(*skb);
+	if (nhc) {
+		ret = nhc->uncompress(skb);
+		if (!ret) {
+			skb_reset_transport_header(*skb);
+			hdr->nexthdr = nhc->nexthdr;
+		} else if (ret == -ENOTSUPP) {
+			net_warn_ratelimited("%s received %s which is not supported.\n",
+					     (*skb)->dev->name, nhc->name);
+		}
+	}

here we need a else branch and return -ENOENT or something similar to drop the packet afterwards.

Thanks Phoebe for the hint.

- Alex