linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 bluetooth-next 0/7] 6lowpan: udp compression/uncompression fix
@ 2013-12-17 10:32 Alexander Aring
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 1/7] 6lowpan: fix udp nullpointer dereferencing Alexander Aring
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Alexander Aring @ 2013-12-17 10:32 UTC (permalink / raw)
  To: linux-zigbee-devel; +Cc: werner, linux-bluetooth, Alexander Aring

The current 6LoWPAN udp compression/uncompression is completely broken.
This patch series fix a lot of udp compression/uncompression issues and
add support parsing with lowpan_fetch_skb function.

I already sent this patch series to netdev some time ago. That's why I add a
v2 to this series. Now we doing all 6lowpan things into bluetooth-next to
avoid merge conflicts.

Changes since v2:
 - remove unnecessary casts and brackes, suggested by Werner Almesberger.
 - use pr_debug_ratelimited instead of pr_debug on patch 4/7.

Alexander Aring (7):
  6lowpan: fix udp nullpointer dereferencing
  6lowpan: fix udp compress ordering
  6lowpan: fix udp byte ordering
  6lowpan: add udp warning for elided checksum
  6lowpan: udp use lowpan_fetch_skb function
  6lowpan: udp use subtraction on both conditions
  6lowpan: cleanup udp compress function

 net/ieee802154/6lowpan.h      |  1 +
 net/ieee802154/6lowpan_iphc.c | 79 +++++++++++++++++++++++--------------------
 2 files changed, 43 insertions(+), 37 deletions(-)

-- 
1.8.5.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 bluetooth-next 1/7] 6lowpan: fix udp nullpointer dereferencing
  2013-12-17 10:32 [PATCH v2 bluetooth-next 0/7] 6lowpan: udp compression/uncompression fix Alexander Aring
@ 2013-12-17 10:32 ` Alexander Aring
  2013-12-17 10:58   ` Anderson Lizardo
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 2/7] 6lowpan: fix udp compress ordering Alexander Aring
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Alexander Aring @ 2013-12-17 10:32 UTC (permalink / raw)
  To: linux-zigbee-devel; +Cc: werner, linux-bluetooth, Alexander Aring

Sometimes a nullpointer dereferencing occurs because of using a wrong
pointer arithmetic in udp_uncompression.

This patch changes "**(hc06_ptr + 3)" to the right one "*(*hc06_ptr +
3)". Dereferencing like "**(hc06_ptr + 3)" works in a random case only.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/6lowpan_iphc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ieee802154/6lowpan_iphc.c b/net/ieee802154/6lowpan_iphc.c
index 88e7da5..8bbe28e 100644
--- a/net/ieee802154/6lowpan_iphc.c
+++ b/net/ieee802154/6lowpan_iphc.c
@@ -548,7 +548,7 @@ static void compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
 				LOWPAN_NHC_UDP_4BIT_PORT)) {
 		pr_debug("UDP header: both ports compression to 4 bits\n");
 		**hc06_ptr = LOWPAN_NHC_UDP_CS_P_11;
-		**(hc06_ptr + 1) = /* subtraction is faster */
+		*(*hc06_ptr + 1) = /* subtraction is faster */
 		   (u8)((uh->dest - LOWPAN_NHC_UDP_4BIT_PORT) +
 		       ((uh->source & LOWPAN_NHC_UDP_4BIT_PORT) << 4));
 		*hc06_ptr += 2;
@@ -557,14 +557,14 @@ static void compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
 		pr_debug("UDP header: remove 8 bits of dest\n");
 		**hc06_ptr = LOWPAN_NHC_UDP_CS_P_01;
 		memcpy(*hc06_ptr + 1, &uh->source, 2);
-		**(hc06_ptr + 3) = (u8)(uh->dest - LOWPAN_NHC_UDP_8BIT_PORT);
+		*(*hc06_ptr + 3) = (u8)(uh->dest - LOWPAN_NHC_UDP_8BIT_PORT);
 		*hc06_ptr += 4;
 	} else if ((uh->source & LOWPAN_NHC_UDP_8BIT_MASK) ==
 			LOWPAN_NHC_UDP_8BIT_PORT) {
 		pr_debug("UDP header: remove 8 bits of source\n");
 		**hc06_ptr = LOWPAN_NHC_UDP_CS_P_10;
 		memcpy(*hc06_ptr + 1, &uh->dest, 2);
-		**(hc06_ptr + 3) = (u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT);
+		*(*hc06_ptr + 3) = (u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT);
 		*hc06_ptr += 4;
 	} else {
 		pr_debug("UDP header: can't compress\n");
-- 
1.8.5.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 bluetooth-next 2/7] 6lowpan: fix udp compress ordering
  2013-12-17 10:32 [PATCH v2 bluetooth-next 0/7] 6lowpan: udp compression/uncompression fix Alexander Aring
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 1/7] 6lowpan: fix udp nullpointer dereferencing Alexander Aring
@ 2013-12-17 10:32 ` Alexander Aring
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 3/7] 6lowpan: fix udp byte ordering Alexander Aring
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Alexander Aring @ 2013-12-17 10:32 UTC (permalink / raw)
  To: linux-zigbee-devel; +Cc: werner, linux-bluetooth, Alexander Aring

In case ((ntohs(uh->source) & LOWPAN_NHC_UDP_8BIT_MASK) the order of
uncompression is wrong. It's always first source port then destination
port as second.

See:
http://tools.ietf.org/html/rfc6282#section-4.3.3

"Fields carried in-line (in part or in whole) appear in the same order
as they do in the UDP header format"

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/6lowpan_iphc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ieee802154/6lowpan_iphc.c b/net/ieee802154/6lowpan_iphc.c
index 8bbe28e..0537b33 100644
--- a/net/ieee802154/6lowpan_iphc.c
+++ b/net/ieee802154/6lowpan_iphc.c
@@ -563,8 +563,8 @@ static void compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
 			LOWPAN_NHC_UDP_8BIT_PORT) {
 		pr_debug("UDP header: remove 8 bits of source\n");
 		**hc06_ptr = LOWPAN_NHC_UDP_CS_P_10;
-		memcpy(*hc06_ptr + 1, &uh->dest, 2);
-		*(*hc06_ptr + 3) = (u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT);
+		*(*hc06_ptr + 1) = (u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT);
+		memcpy(*hc06_ptr + 2, &uh->dest, 2);
 		*hc06_ptr += 4;
 	} else {
 		pr_debug("UDP header: can't compress\n");
-- 
1.8.5.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 bluetooth-next 3/7] 6lowpan: fix udp byte ordering
  2013-12-17 10:32 [PATCH v2 bluetooth-next 0/7] 6lowpan: udp compression/uncompression fix Alexander Aring
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 1/7] 6lowpan: fix udp nullpointer dereferencing Alexander Aring
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 2/7] 6lowpan: fix udp compress ordering Alexander Aring
@ 2013-12-17 10:32 ` Alexander Aring
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 4/7] 6lowpan: add udp warning for elided checksum Alexander Aring
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Alexander Aring @ 2013-12-17 10:32 UTC (permalink / raw)
  To: linux-zigbee-devel; +Cc: werner, linux-bluetooth, Alexander Aring

The incoming udp header in lowpan_compress_udp_header function is
already in network byte order.

Everytime we read this values for source and destination port we need
to convert this value to host byte order.

In the outcoming header we need to set this value in network byte order
which the upcoming process assumes.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/6lowpan_iphc.c | 45 +++++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/net/ieee802154/6lowpan_iphc.c b/net/ieee802154/6lowpan_iphc.c
index 0537b33..a7ae340 100644
--- a/net/ieee802154/6lowpan_iphc.c
+++ b/net/ieee802154/6lowpan_iphc.c
@@ -283,20 +283,21 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
 			break;
 		case LOWPAN_NHC_UDP_CS_P_01:
 			memcpy(&uh->source, &skb->data[0], 2);
-			uh->dest =
-			   skb->data[2] + LOWPAN_NHC_UDP_8BIT_PORT;
+			uh->dest = htons(skb->data[2] +
+					 LOWPAN_NHC_UDP_8BIT_PORT);
 			skb_pull(skb, 3);
 			break;
 		case LOWPAN_NHC_UDP_CS_P_10:
-			uh->source = skb->data[0] + LOWPAN_NHC_UDP_8BIT_PORT;
+			uh->source = htons(skb->data[0] +
+					   LOWPAN_NHC_UDP_8BIT_PORT);
 			memcpy(&uh->dest, &skb->data[1], 2);
 			skb_pull(skb, 3);
 			break;
 		case LOWPAN_NHC_UDP_CS_P_11:
-			uh->source =
-			   LOWPAN_NHC_UDP_4BIT_PORT + (skb->data[0] >> 4);
-			uh->dest =
-			   LOWPAN_NHC_UDP_4BIT_PORT + (skb->data[0] & 0x0f);
+			uh->source = htons(LOWPAN_NHC_UDP_4BIT_PORT +
+					   (skb->data[0] >> 4));
+			uh->dest = htons(LOWPAN_NHC_UDP_4BIT_PORT +
+					 (skb->data[0] & 0x0f));
 			skb_pull(skb, 1);
 			break;
 		default:
@@ -306,7 +307,7 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
 		}
 
 		pr_debug("uncompressed UDP ports: src = %d, dst = %d\n",
-			 uh->source, uh->dest);
+			 ntohs(uh->source), ntohs(uh->dest));
 
 		/* copy checksum */
 		memcpy(&uh->check, &skb->data[0], 2);
@@ -318,7 +319,7 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
 		 * frame
 		 */
 		uh->len = htons(skb->len + sizeof(struct udphdr));
-		pr_debug("uncompressed UDP length: src = %d", uh->len);
+		pr_debug("uncompressed UDP length: src = %d", ntohs(uh->len));
 	} else {
 		pr_debug("ERROR: unsupported NH format\n");
 		goto err;
@@ -542,28 +543,30 @@ static void compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
 {
 	struct udphdr *uh = udp_hdr(skb);
 
-	if (((uh->source & LOWPAN_NHC_UDP_4BIT_MASK) ==
-				LOWPAN_NHC_UDP_4BIT_PORT) &&
-	    ((uh->dest & LOWPAN_NHC_UDP_4BIT_MASK) ==
-				LOWPAN_NHC_UDP_4BIT_PORT)) {
+	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");
 		**hc06_ptr = LOWPAN_NHC_UDP_CS_P_11;
 		*(*hc06_ptr + 1) = /* subtraction is faster */
-		   (u8)((uh->dest - LOWPAN_NHC_UDP_4BIT_PORT) +
-		       ((uh->source & LOWPAN_NHC_UDP_4BIT_PORT) << 4));
+		   (u8)((ntohs(uh->dest) - LOWPAN_NHC_UDP_4BIT_PORT) +
+		       ((ntohs(uh->source) & LOWPAN_NHC_UDP_4BIT_PORT) << 4));
 		*hc06_ptr += 2;
-	} else if ((uh->dest & LOWPAN_NHC_UDP_8BIT_MASK) ==
-			LOWPAN_NHC_UDP_8BIT_PORT) {
+	} 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");
 		**hc06_ptr = LOWPAN_NHC_UDP_CS_P_01;
 		memcpy(*hc06_ptr + 1, &uh->source, 2);
-		*(*hc06_ptr + 3) = (u8)(uh->dest - LOWPAN_NHC_UDP_8BIT_PORT);
+		*(*hc06_ptr + 3) = (u8)(ntohs(uh->dest) -
+					LOWPAN_NHC_UDP_8BIT_PORT);
 		*hc06_ptr += 4;
-	} else if ((uh->source & LOWPAN_NHC_UDP_8BIT_MASK) ==
-			LOWPAN_NHC_UDP_8BIT_PORT) {
+	} 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");
 		**hc06_ptr = LOWPAN_NHC_UDP_CS_P_10;
-		*(*hc06_ptr + 1) = (u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT);
+		*(*hc06_ptr + 1) = (u8)(ntohs(uh->source) -
+					LOWPAN_NHC_UDP_8BIT_PORT);
 		memcpy(*hc06_ptr + 2, &uh->dest, 2);
 		*hc06_ptr += 4;
 	} else {
-- 
1.8.5.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 bluetooth-next 4/7] 6lowpan: add udp warning for elided checksum
  2013-12-17 10:32 [PATCH v2 bluetooth-next 0/7] 6lowpan: udp compression/uncompression fix Alexander Aring
                   ` (2 preceding siblings ...)
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 3/7] 6lowpan: fix udp byte ordering Alexander Aring
@ 2013-12-17 10:32 ` Alexander Aring
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 5/7] 6lowpan: udp use lowpan_fetch_skb function Alexander Aring
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Alexander Aring @ 2013-12-17 10:32 UTC (permalink / raw)
  To: linux-zigbee-devel; +Cc: werner, linux-bluetooth, Alexander Aring

Bit 5 of "UDP LOWPAN_NHC Format" indicate that the checksum can be
elided.
The host need to calculate the udp checksum afterwards but this isn't
supported right now.

See:
http://tools.ietf.org/html/rfc6282#section-4.3.3
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/6lowpan.h      |  1 +
 net/ieee802154/6lowpan_iphc.c | 11 ++++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/ieee802154/6lowpan.h b/net/ieee802154/6lowpan.h
index 10909e5..4942c5d 100644
--- a/net/ieee802154/6lowpan.h
+++ b/net/ieee802154/6lowpan.h
@@ -231,6 +231,7 @@
 #define LOWPAN_NHC_UDP_CS_P_10	0xF2 /* source = 0xF0 + 8bit inline,
 					dest = 16 bit inline */
 #define LOWPAN_NHC_UDP_CS_P_11	0xF3 /* source & dest = 0xF0B + 4bit inline */
+#define LOWPAN_NHC_UDP_CS_C	0x04 /* checksum elided */
 
 #ifdef DEBUG
 /* print data in line */
diff --git a/net/ieee802154/6lowpan_iphc.c b/net/ieee802154/6lowpan_iphc.c
index a7ae340..8303c93 100644
--- a/net/ieee802154/6lowpan_iphc.c
+++ b/net/ieee802154/6lowpan_iphc.c
@@ -309,9 +309,14 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
 		pr_debug("uncompressed UDP ports: src = %d, dst = %d\n",
 			 ntohs(uh->source), ntohs(uh->dest));
 
-		/* copy checksum */
-		memcpy(&uh->check, &skb->data[0], 2);
-		skb_pull(skb, 2);
+		/* checksum */
+		if (tmp & LOWPAN_NHC_UDP_CS_C) {
+			pr_debug_ratelimited("checksum elided currently not supported");
+			goto err;
+		} else {
+			memcpy(&uh->check, &skb->data[0], 2);
+			skb_pull(skb, 2);
+		}
 
 		/*
 		 * UDP lenght needs to be infered from the lower layers
-- 
1.8.5.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 bluetooth-next 5/7] 6lowpan: udp use lowpan_fetch_skb function
  2013-12-17 10:32 [PATCH v2 bluetooth-next 0/7] 6lowpan: udp compression/uncompression fix Alexander Aring
                   ` (3 preceding siblings ...)
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 4/7] 6lowpan: add udp warning for elided checksum Alexander Aring
@ 2013-12-17 10:32 ` Alexander Aring
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 6/7] 6lowpan: udp use subtraction on both conditions Alexander Aring
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 7/7] 6lowpan: cleanup udp compress function Alexander Aring
  6 siblings, 0 replies; 11+ messages in thread
From: Alexander Aring @ 2013-12-17 10:32 UTC (permalink / raw)
  To: linux-zigbee-devel; +Cc: werner, linux-bluetooth, Alexander Aring

Cleanup the lowpan_uncompress_udp_header function to use the
lowpan_fetch_skb function.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/6lowpan_iphc.c | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/net/ieee802154/6lowpan_iphc.c b/net/ieee802154/6lowpan_iphc.c
index 8303c93..ee6891f 100644
--- a/net/ieee802154/6lowpan_iphc.c
+++ b/net/ieee802154/6lowpan_iphc.c
@@ -265,40 +265,37 @@ lowpan_uncompress_multicast_daddr(struct sk_buff *skb,
 static int
 uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
 {
-	u8 tmp;
+	bool fail;
+	u8 tmp = 0, val = 0;
 
 	if (!uh)
 		goto err;
 
-	if (lowpan_fetch_skb_u8(skb, &tmp))
-		goto err;
+	fail = lowpan_fetch_skb(skb, &tmp, 1);
 
 	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:
-			memcpy(&uh->source, &skb->data[0], 2);
-			memcpy(&uh->dest, &skb->data[2], 2);
-			skb_pull(skb, 4);
+			fail |= lowpan_fetch_skb(skb, &uh->source, 2);
+			fail |= lowpan_fetch_skb(skb, &uh->dest, 2);
 			break;
 		case LOWPAN_NHC_UDP_CS_P_01:
-			memcpy(&uh->source, &skb->data[0], 2);
-			uh->dest = htons(skb->data[2] +
-					 LOWPAN_NHC_UDP_8BIT_PORT);
-			skb_pull(skb, 3);
+			fail |= lowpan_fetch_skb(skb, &uh->source, 2);
+			fail |= lowpan_fetch_skb(skb, &val, 1);
+			uh->dest = htons(val + LOWPAN_NHC_UDP_8BIT_PORT);
 			break;
 		case LOWPAN_NHC_UDP_CS_P_10:
-			uh->source = htons(skb->data[0] +
-					   LOWPAN_NHC_UDP_8BIT_PORT);
-			memcpy(&uh->dest, &skb->data[1], 2);
-			skb_pull(skb, 3);
+			fail |= lowpan_fetch_skb(skb, &val, 1);
+			uh->source = htons(val + LOWPAN_NHC_UDP_8BIT_PORT);
+			fail |= lowpan_fetch_skb(skb, &uh->dest, 2);
 			break;
 		case LOWPAN_NHC_UDP_CS_P_11:
+			fail |= lowpan_fetch_skb(skb, &val, 1);
 			uh->source = htons(LOWPAN_NHC_UDP_4BIT_PORT +
-					   (skb->data[0] >> 4));
+					   (val >> 4));
 			uh->dest = htons(LOWPAN_NHC_UDP_4BIT_PORT +
-					 (skb->data[0] & 0x0f));
-			skb_pull(skb, 1);
+					 (val & 0x0f));
 			break;
 		default:
 			pr_debug("ERROR: unknown UDP format\n");
@@ -314,8 +311,7 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
 			pr_debug_ratelimited("checksum elided currently not supported");
 			goto err;
 		} else {
-			memcpy(&uh->check, &skb->data[0], 2);
-			skb_pull(skb, 2);
+			fail |= lowpan_fetch_skb(skb, &uh->check, 2);
 		}
 
 		/*
@@ -330,6 +326,9 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
 		goto err;
 	}
 
+	if (fail)
+		goto err;
+
 	return 0;
 err:
 	return -EINVAL;
-- 
1.8.5.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 bluetooth-next 6/7] 6lowpan: udp use subtraction on both conditions
  2013-12-17 10:32 [PATCH v2 bluetooth-next 0/7] 6lowpan: udp compression/uncompression fix Alexander Aring
                   ` (4 preceding siblings ...)
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 5/7] 6lowpan: udp use lowpan_fetch_skb function Alexander Aring
@ 2013-12-17 10:32 ` Alexander Aring
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 7/7] 6lowpan: cleanup udp compress function Alexander Aring
  6 siblings, 0 replies; 11+ messages in thread
From: Alexander Aring @ 2013-12-17 10:32 UTC (permalink / raw)
  To: linux-zigbee-devel; +Cc: werner, linux-bluetooth, Alexander Aring

Cleanup code to handle both calculation in the same way.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/6lowpan_iphc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ieee802154/6lowpan_iphc.c b/net/ieee802154/6lowpan_iphc.c
index ee6891f..d49cc1b 100644
--- a/net/ieee802154/6lowpan_iphc.c
+++ b/net/ieee802154/6lowpan_iphc.c
@@ -555,7 +555,7 @@ static void compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
 		**hc06_ptr = LOWPAN_NHC_UDP_CS_P_11;
 		*(*hc06_ptr + 1) = /* subtraction is faster */
 		   (u8)((ntohs(uh->dest) - LOWPAN_NHC_UDP_4BIT_PORT) +
-		       ((ntohs(uh->source) & LOWPAN_NHC_UDP_4BIT_PORT) << 4));
+		       ((ntohs(uh->source) - LOWPAN_NHC_UDP_4BIT_PORT) << 4));
 		*hc06_ptr += 2;
 	} else if ((ntohs(uh->dest) & LOWPAN_NHC_UDP_8BIT_MASK) ==
 		   LOWPAN_NHC_UDP_8BIT_PORT) {
-- 
1.8.5.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 bluetooth-next 7/7] 6lowpan: cleanup udp compress function
  2013-12-17 10:32 [PATCH v2 bluetooth-next 0/7] 6lowpan: udp compression/uncompression fix Alexander Aring
                   ` (5 preceding siblings ...)
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 6/7] 6lowpan: udp use subtraction on both conditions Alexander Aring
@ 2013-12-17 10:32 ` Alexander Aring
  6 siblings, 0 replies; 11+ messages in thread
From: Alexander Aring @ 2013-12-17 10:32 UTC (permalink / raw)
  To: linux-zigbee-devel; +Cc: werner, linux-bluetooth, Alexander Aring

This patch remove unnecessary casts and brackets in compress_udp_header
function.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/6lowpan_iphc.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/net/ieee802154/6lowpan_iphc.c b/net/ieee802154/6lowpan_iphc.c
index d49cc1b..78bbb76 100644
--- a/net/ieee802154/6lowpan_iphc.c
+++ b/net/ieee802154/6lowpan_iphc.c
@@ -553,24 +553,22 @@ static void compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
 	     LOWPAN_NHC_UDP_4BIT_PORT)) {
 		pr_debug("UDP header: both ports compression to 4 bits\n");
 		**hc06_ptr = LOWPAN_NHC_UDP_CS_P_11;
-		*(*hc06_ptr + 1) = /* subtraction is faster */
-		   (u8)((ntohs(uh->dest) - LOWPAN_NHC_UDP_4BIT_PORT) +
-		       ((ntohs(uh->source) - LOWPAN_NHC_UDP_4BIT_PORT) << 4));
+		*(*hc06_ptr + 1) = ntohs(uh->dest) - LOWPAN_NHC_UDP_4BIT_PORT +
+				   ((ntohs(uh->source) -
+				     LOWPAN_NHC_UDP_4BIT_PORT) << 4);
 		*hc06_ptr += 2;
 	} 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");
 		**hc06_ptr = LOWPAN_NHC_UDP_CS_P_01;
 		memcpy(*hc06_ptr + 1, &uh->source, 2);
-		*(*hc06_ptr + 3) = (u8)(ntohs(uh->dest) -
-					LOWPAN_NHC_UDP_8BIT_PORT);
+		*(*hc06_ptr + 3) = ntohs(uh->dest) - LOWPAN_NHC_UDP_8BIT_PORT;
 		*hc06_ptr += 4;
 	} 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");
 		**hc06_ptr = LOWPAN_NHC_UDP_CS_P_10;
-		*(*hc06_ptr + 1) = (u8)(ntohs(uh->source) -
-					LOWPAN_NHC_UDP_8BIT_PORT);
+		*(*hc06_ptr + 1) = ntohs(uh->source) - LOWPAN_NHC_UDP_8BIT_PORT;
 		memcpy(*hc06_ptr + 2, &uh->dest, 2);
 		*hc06_ptr += 4;
 	} else {
-- 
1.8.5.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 bluetooth-next 1/7] 6lowpan: fix udp nullpointer dereferencing
  2013-12-17 10:32 ` [PATCH v2 bluetooth-next 1/7] 6lowpan: fix udp nullpointer dereferencing Alexander Aring
@ 2013-12-17 10:58   ` Anderson Lizardo
  2013-12-17 11:06     ` Alexander Aring
  0 siblings, 1 reply; 11+ messages in thread
From: Anderson Lizardo @ 2013-12-17 10:58 UTC (permalink / raw)
  To: Alexander Aring; +Cc: linux-zigbee-devel, werner, BlueZ development

Hi Alexander,

On Tue, Dec 17, 2013 at 6:32 AM, Alexander Aring <alex.aring@gmail.com> wrote:
> Sometimes a nullpointer dereferencing occurs because of using a wrong
> pointer arithmetic in udp_uncompression.
>
> This patch changes "**(hc06_ptr + 3)" to the right one "*(*hc06_ptr +
> 3)". Dereferencing like "**(hc06_ptr + 3)" works in a random case only.

And why not use hc06_ptr[0][3] ? IMHO it is more readable and the
arithmetic is the same (as far as I know).

Best Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 bluetooth-next 1/7] 6lowpan: fix udp nullpointer dereferencing
  2013-12-17 10:58   ` Anderson Lizardo
@ 2013-12-17 11:06     ` Alexander Aring
  2013-12-17 11:25       ` Alexander Aring
  0 siblings, 1 reply; 11+ messages in thread
From: Alexander Aring @ 2013-12-17 11:06 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: linux-zigbee-devel, werner, BlueZ development

On Tue, Dec 17, 2013 at 06:58:12AM -0400, Anderson Lizardo wrote:
> Hi Alexander,
> 
> On Tue, Dec 17, 2013 at 6:32 AM, Alexander Aring <alex.aring@gmail.com> wrote:
> > Sometimes a nullpointer dereferencing occurs because of using a wrong
> > pointer arithmetic in udp_uncompression.
> >
> > This patch changes "**(hc06_ptr + 3)" to the right one "*(*hc06_ptr +
> > 3)". Dereferencing like "**(hc06_ptr + 3)" works in a random case only.
> 
> And why not use hc06_ptr[0][3] ? IMHO it is more readable and the
> arithmetic is the same (as far as I know).
>

mhh maybe we change it to *hc06_ptr[3] ? Otherwise we have always
something like [0][#] for access.

- Alex

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 bluetooth-next 1/7] 6lowpan: fix udp nullpointer dereferencing
  2013-12-17 11:06     ` Alexander Aring
@ 2013-12-17 11:25       ` Alexander Aring
  0 siblings, 0 replies; 11+ messages in thread
From: Alexander Aring @ 2013-12-17 11:25 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: linux-zigbee-devel, werner, BlueZ development

On Tue, Dec 17, 2013 at 12:06:01PM +0100, Alexander Aring wrote:
> On Tue, Dec 17, 2013 at 06:58:12AM -0400, Anderson Lizardo wrote:
> > Hi Alexander,
> > 
> > On Tue, Dec 17, 2013 at 6:32 AM, Alexander Aring <alex.aring@gmail.com> wrote:
> > > Sometimes a nullpointer dereferencing occurs because of using a wrong
> > > pointer arithmetic in udp_uncompression.
> > >
> > > This patch changes "**(hc06_ptr + 3)" to the right one "*(*hc06_ptr +
> > > 3)". Dereferencing like "**(hc06_ptr + 3)" works in a random case only.
> > 
> > And why not use hc06_ptr[0][3] ? IMHO it is more readable and the
> > arithmetic is the same (as far as I know).
> >
> 
> mhh maybe we change it to *hc06_ptr[3] ? Otherwise we have always
> something like [0][#] for access.
> 
meant (*hc06_ptr)[3] here, but I have a better idea to add a function
wich sets some data and increment it automatically. Will send v3 with
that soon.

- Alex

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-12-17 11:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-17 10:32 [PATCH v2 bluetooth-next 0/7] 6lowpan: udp compression/uncompression fix Alexander Aring
2013-12-17 10:32 ` [PATCH v2 bluetooth-next 1/7] 6lowpan: fix udp nullpointer dereferencing Alexander Aring
2013-12-17 10:58   ` Anderson Lizardo
2013-12-17 11:06     ` Alexander Aring
2013-12-17 11:25       ` Alexander Aring
2013-12-17 10:32 ` [PATCH v2 bluetooth-next 2/7] 6lowpan: fix udp compress ordering Alexander Aring
2013-12-17 10:32 ` [PATCH v2 bluetooth-next 3/7] 6lowpan: fix udp byte ordering Alexander Aring
2013-12-17 10:32 ` [PATCH v2 bluetooth-next 4/7] 6lowpan: add udp warning for elided checksum Alexander Aring
2013-12-17 10:32 ` [PATCH v2 bluetooth-next 5/7] 6lowpan: udp use lowpan_fetch_skb function Alexander Aring
2013-12-17 10:32 ` [PATCH v2 bluetooth-next 6/7] 6lowpan: udp use subtraction on both conditions Alexander Aring
2013-12-17 10:32 ` [PATCH v2 bluetooth-next 7/7] 6lowpan: cleanup udp compress function Alexander Aring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).