Skip to contentSkip to conversation

6lowpan: iphc: cleanups

PATCH In review Alexander Aring 2 participants 6 messages Nov 17, 2015 – Nov 25, 2015

Subsystems (4)
lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

cover 6lowpan: iphc: cleanups

Hi,

These two patches are from the current RFC of stateful compression support. It has nothing todo with stateful compression, I send it now as PATCH so it can be applied before.

- Alex

Alexander Aring (2):
6lowpan: iphc: add check for reserved values
6lowpan: iphc: remove handling when dam is zero

 net/6lowpan/iphc.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
Signature · 1 line
2.6.1
author maintainer
#1 lore raw

PATCH 1/2 6lowpan: iphc: add check for reserved values

This patch adds a check on reserved values for IPHC header. We should at first check on these fields instead of doing parsing before. Afterwards we can be sure there are no reserved values anymore. The reserved bits doesn't contain reserved values for NHC headers. This need to be handled inside the next layer.

---
 net/6lowpan/iphc.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
net/6lowpan/iphc.c +16 -1
index 346b5c1..13f5424 100644
@@ -455,6 +455,20 @@ static const u8 lowpan_ttl_values[] = {
 	[LOWPAN_IPHC_HLIM_11] = 255,
 };
 
+static inline bool lowpan_iphc_is_reserved(u8 iphc1)
+{
+	switch (iphc1 & (LOWPAN_IPHC_DAC | LOWPAN_IPHC_M |
+			 LOWPAN_IPHC_DAM_MASK)) {
+	case LOWPAN_IPHC_DAC | LOWPAN_IPHC_DAM_00:
+	case LOWPAN_IPHC_DAC | LOWPAN_IPHC_M | LOWPAN_IPHC_DAM_01:
+	case LOWPAN_IPHC_DAC | LOWPAN_IPHC_M | LOWPAN_IPHC_DAM_10:
+	case LOWPAN_IPHC_DAC | LOWPAN_IPHC_M | LOWPAN_IPHC_DAM_11:
+		return true;
+	default:
+		return false;
+	}
+}
+
 int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
 			     const void *daddr, const void *saddr)
 {
@@ -466,7 +480,8 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
 		       skb->data, skb->len);
 
 	if (lowpan_fetch_skb(skb, &iphc0, sizeof(iphc0)) ||
-	    lowpan_fetch_skb(skb, &iphc1, sizeof(iphc1)))
+	    lowpan_fetch_skb(skb, &iphc1, sizeof(iphc1)) ||
+	    lowpan_iphc_is_reserved(iphc1))
 		return -EINVAL;
 
 	/* another if the CID flag is set */
Signature · 1 line
2.6.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH bluetooth-next 1/2] 6lowpan: iphc: add check for reserved values

Hello.

Quoted 37 lines · Alexander Aring

This patch adds a check on reserved values for IPHC header. We should at first check on these fields instead of doing parsing before. Afterwards we can be sure there are no reserved values anymore. The reserved bits doesn't contain reserved values for NHC headers. This need to be handled inside the next layer.

---
  net/6lowpan/iphc.c | 17 ++++++++++++++++-
  1 file changed, 16 insertions(+), 1 deletion(-)
net/6lowpan/iphc.c +14 -0
index 346b5c1..13f5424 100644
@@ -455,6 +455,20 @@ static const u8 lowpan_ttl_values[] = {
  	[LOWPAN_IPHC_HLIM_11] = 255,
  };
 
+static inline bool lowpan_iphc_is_reserved(u8 iphc1)
+{
+	switch (iphc1 & (LOWPAN_IPHC_DAC | LOWPAN_IPHC_M |
+			 LOWPAN_IPHC_DAM_MASK)) {
+	case LOWPAN_IPHC_DAC | LOWPAN_IPHC_DAM_00:
+	case LOWPAN_IPHC_DAC | LOWPAN_IPHC_M | LOWPAN_IPHC_DAM_01:
+	case LOWPAN_IPHC_DAC | LOWPAN_IPHC_M | LOWPAN_IPHC_DAM_10:
+	case LOWPAN_IPHC_DAC | LOWPAN_IPHC_M | LOWPAN_IPHC_DAM_11:
+		return true;
+	default:
+		return false;
+	}
+}
+
  int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
  			     const void *daddr, const void *saddr)
  {

net/6lowpan/iphc.c int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev, · line 487

Quoted 9 lines
net/6lowpan/iphc.c +2 -1
@@ -466,7 +480,8 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
  		       skb->data, skb->len);
 
  	if (lowpan_fetch_skb(skb, &iphc0, sizeof(iphc0)) ||
-	    lowpan_fetch_skb(skb, &iphc1, sizeof(iphc1)))
+	    lowpan_fetch_skb(skb, &iphc1, sizeof(iphc1)) ||
+	    lowpan_iphc_is_reserved(iphc1))
  		return -EINVAL;
 
  	/* another if the CID flag is set */

regards
Stefan Schmidt

author maintainer
#3 lore raw

PATCH 2/2 6lowpan: iphc: remove handling when dam is zero

In reply to Alexander Aring

This patch removes handling of LOWPAN_IPHC_DAM_00 inside the lowpan_compress_addr_64 function. The case of LOWPAN_IPHC_DAM_00 can never occur. there exists a if branch which use LOWPAN_IPHC_DAM_11 and LOWPAN_IPHC_DAM_10 and inside the else branch LOWPAN_IPHC_DAM_01. So LOWPAN_IPHC_DAM_00 can never occur.

---
 net/6lowpan/iphc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/6lowpan/iphc.c +1 -2
index 13f5424..f7f175c 100644
@@ -594,7 +594,6 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
 EXPORT_SYMBOL_GPL(lowpan_header_decompress);
 
 static const u8 lowpan_iphc_dam_to_sam_value[] = {
-	[LOWPAN_IPHC_DAM_00] = LOWPAN_IPHC_SAM_00,
 	[LOWPAN_IPHC_DAM_01] = LOWPAN_IPHC_SAM_01,
 	[LOWPAN_IPHC_DAM_10] = LOWPAN_IPHC_SAM_10,
 	[LOWPAN_IPHC_DAM_11] = LOWPAN_IPHC_SAM_11,
@@ -603,7 +602,7 @@ static const u8 lowpan_iphc_dam_to_sam_value[] = {
 static u8 lowpan_compress_addr_64(u8 **hc_ptr, const struct in6_addr *ipaddr,
 				  const unsigned char *lladdr, bool sam)
 {
-	u8 dam = LOWPAN_IPHC_DAM_00;
+	u8 dam;
 
 	if (is_addr_mac_addr_based(ipaddr, lladdr)) {
 		dam = LOWPAN_IPHC_DAM_11; /* 0-bits */
Signature · 1 line
2.6.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH bluetooth-next 2/2] 6lowpan: iphc: remove handling when dam is zero

Hello.

Quoted 5 lines · Alexander Aring

This patch removes handling of LOWPAN_IPHC_DAM_00 inside the lowpan_compress_addr_64 function. The case of LOWPAN_IPHC_DAM_00 can never occur. there exists a if branch which use LOWPAN_IPHC_DAM_11 and LOWPAN_IPHC_DAM_10 and inside the else branch LOWPAN_IPHC_DAM_01. So LOWPAN_IPHC_DAM_00 can never occur.

Agreed the DAM_00 case means no compressions and carry the 128 bit address in line. We never call lowpan_compress_addr_64() for this case so removing this case which is never used is fine.

Quoted 18 lines
---
  net/6lowpan/iphc.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
net/6lowpan/iphc.c +0 -1
index 13f5424..f7f175c 100644
@@ -594,7 +594,6 @@ int lowpan_header_decompress(struct sk_buff *skb, const struct net_device *dev,
  EXPORT_SYMBOL_GPL(lowpan_header_decompress);
 
  static const u8 lowpan_iphc_dam_to_sam_value[] = {
-	[LOWPAN_IPHC_DAM_00] = LOWPAN_IPHC_SAM_00,
  	[LOWPAN_IPHC_DAM_01] = LOWPAN_IPHC_SAM_01,
  	[LOWPAN_IPHC_DAM_10] = LOWPAN_IPHC_SAM_10,
  	[LOWPAN_IPHC_DAM_11] = LOWPAN_IPHC_SAM_11,

net/6lowpan/iphc.c static const u8 lowpan_iphc_dam_to_sam_value[] = { · line 608

Quoted 8 lines
net/6lowpan/iphc.c +1 -1
@@ -603,7 +602,7 @@ static const u8 lowpan_iphc_dam_to_sam_value[] = {
  static u8 lowpan_compress_addr_64(u8 **hc_ptr, const struct in6_addr *ipaddr,
  				  const unsigned char *lladdr, bool sam)
  {
-	u8 dam = LOWPAN_IPHC_DAM_00;
+	u8 dam;
 
  	if (is_addr_mac_addr_based(ipaddr, lladdr)) {
  		dam = LOWPAN_IPHC_DAM_11; /* 0-bits */

regards
Stefan Schmidt

author maintainer
#5 lore raw
In reply to Alexander Aring
Quoted 6 lines · Alexander Aring

Hi,

These two patches are from the current RFC of stateful compression support. It has nothing todo with stateful compression, I send it now as PATCH so it can be applied before.

ping :-)

- Alex