Commit 5e96855f authored by Tony Cheneau's avatar Tony Cheneau Committed by David S. Miller

6lowpan: Change byte order when storing/accessing to len field

Lenght field should be encoded using big endian byte order, such as intend in the specs.
As it is currently written, the len field would not be decoded properly on an implementation using the correct byte ordering. Hence, it could lead to interroperability issues.

Also, I rewrote the code so that iphc0 argument of lowpan_alloc_new_frame could be removed.
Signed-off-by: default avatarTony Cheneau <tony.cheneau@amnesiak.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4576039f
...@@ -645,7 +645,7 @@ static void lowpan_fragment_timer_expired(unsigned long entry_addr) ...@@ -645,7 +645,7 @@ static void lowpan_fragment_timer_expired(unsigned long entry_addr)
} }
static struct lowpan_fragment * static struct lowpan_fragment *
lowpan_alloc_new_frame(struct sk_buff *skb, u8 iphc0, u8 len, u16 tag) lowpan_alloc_new_frame(struct sk_buff *skb, u8 len, u16 tag)
{ {
struct lowpan_fragment *frame; struct lowpan_fragment *frame;
...@@ -656,7 +656,7 @@ lowpan_alloc_new_frame(struct sk_buff *skb, u8 iphc0, u8 len, u16 tag) ...@@ -656,7 +656,7 @@ lowpan_alloc_new_frame(struct sk_buff *skb, u8 iphc0, u8 len, u16 tag)
INIT_LIST_HEAD(&frame->list); INIT_LIST_HEAD(&frame->list);
frame->length = (iphc0 & 7) | (len << 3); frame->length = len;
frame->tag = tag; frame->tag = tag;
/* allocate buffer for frame assembling */ /* allocate buffer for frame assembling */
...@@ -714,14 +714,18 @@ lowpan_process_data(struct sk_buff *skb) ...@@ -714,14 +714,18 @@ lowpan_process_data(struct sk_buff *skb)
case LOWPAN_DISPATCH_FRAGN: case LOWPAN_DISPATCH_FRAGN:
{ {
struct lowpan_fragment *frame; struct lowpan_fragment *frame;
u8 len, offset; /* slen stores the rightmost 8 bits of the 11 bits length */
u16 tag; u8 slen, offset;
u16 len, tag;
bool found = false; bool found = false;
if (lowpan_fetch_skb_u8(skb, &len) || /* frame length */ if (lowpan_fetch_skb_u8(skb, &slen) || /* frame length */
lowpan_fetch_skb_u16(skb, &tag)) /* fragment tag */ lowpan_fetch_skb_u16(skb, &tag)) /* fragment tag */
goto drop; goto drop;
/* adds the 3 MSB to the 8 LSB to retrieve the 11 bits length */
len = ((iphc0 & 7) << 8) | slen;
/* /*
* check if frame assembling with the same tag is * check if frame assembling with the same tag is
* already in progress * already in progress
...@@ -736,7 +740,7 @@ lowpan_process_data(struct sk_buff *skb) ...@@ -736,7 +740,7 @@ lowpan_process_data(struct sk_buff *skb)
/* alloc new frame structure */ /* alloc new frame structure */
if (!found) { if (!found) {
frame = lowpan_alloc_new_frame(skb, iphc0, len, tag); frame = lowpan_alloc_new_frame(skb, len, tag);
if (!frame) if (!frame)
goto unlock_and_drop; goto unlock_and_drop;
} }
...@@ -1004,8 +1008,8 @@ lowpan_skb_fragmentation(struct sk_buff *skb) ...@@ -1004,8 +1008,8 @@ lowpan_skb_fragmentation(struct sk_buff *skb)
tag = fragment_tag++; tag = fragment_tag++;
/* first fragment header */ /* first fragment header */
head[0] = LOWPAN_DISPATCH_FRAG1 | (payload_length & 0x7); head[0] = LOWPAN_DISPATCH_FRAG1 | ((payload_length >> 8) & 0x7);
head[1] = (payload_length >> 3) & 0xff; head[1] = payload_length & 0xff;
head[2] = tag >> 8; head[2] = tag >> 8;
head[3] = tag & 0xff; head[3] = tag & 0xff;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment