Skip to content

Commit 5e96855

Browse files
tcheneaudavem330
authored andcommitted
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: Tony Cheneau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4576039 commit 5e96855

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

net/ieee802154/6lowpan.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ static void lowpan_fragment_timer_expired(unsigned long entry_addr)
645645
}
646646

647647
static struct lowpan_fragment *
648-
lowpan_alloc_new_frame(struct sk_buff *skb, u8 iphc0, u8 len, u16 tag)
648+
lowpan_alloc_new_frame(struct sk_buff *skb, u8 len, u16 tag)
649649
{
650650
struct lowpan_fragment *frame;
651651

@@ -656,7 +656,7 @@ lowpan_alloc_new_frame(struct sk_buff *skb, u8 iphc0, u8 len, u16 tag)
656656

657657
INIT_LIST_HEAD(&frame->list);
658658

659-
frame->length = (iphc0 & 7) | (len << 3);
659+
frame->length = len;
660660
frame->tag = tag;
661661

662662
/* allocate buffer for frame assembling */
@@ -714,14 +714,18 @@ lowpan_process_data(struct sk_buff *skb)
714714
case LOWPAN_DISPATCH_FRAGN:
715715
{
716716
struct lowpan_fragment *frame;
717-
u8 len, offset;
718-
u16 tag;
717+
/* slen stores the rightmost 8 bits of the 11 bits length */
718+
u8 slen, offset;
719+
u16 len, tag;
719720
bool found = false;
720721

721-
if (lowpan_fetch_skb_u8(skb, &len) || /* frame length */
722+
if (lowpan_fetch_skb_u8(skb, &slen) || /* frame length */
722723
lowpan_fetch_skb_u16(skb, &tag)) /* fragment tag */
723724
goto drop;
724725

726+
/* adds the 3 MSB to the 8 LSB to retrieve the 11 bits length */
727+
len = ((iphc0 & 7) << 8) | slen;
728+
725729
/*
726730
* check if frame assembling with the same tag is
727731
* already in progress
@@ -736,7 +740,7 @@ lowpan_process_data(struct sk_buff *skb)
736740

737741
/* alloc new frame structure */
738742
if (!found) {
739-
frame = lowpan_alloc_new_frame(skb, iphc0, len, tag);
743+
frame = lowpan_alloc_new_frame(skb, len, tag);
740744
if (!frame)
741745
goto unlock_and_drop;
742746
}
@@ -1004,8 +1008,8 @@ lowpan_skb_fragmentation(struct sk_buff *skb)
10041008
tag = fragment_tag++;
10051009

10061010
/* first fragment header */
1007-
head[0] = LOWPAN_DISPATCH_FRAG1 | (payload_length & 0x7);
1008-
head[1] = (payload_length >> 3) & 0xff;
1011+
head[0] = LOWPAN_DISPATCH_FRAG1 | ((payload_length >> 8) & 0x7);
1012+
head[1] = payload_length & 0xff;
10091013
head[2] = tag >> 8;
10101014
head[3] = tag & 0xff;
10111015

0 commit comments

Comments
 (0)