@@ -215,6 +215,11 @@ void ieee802154_fragment(struct ieee802154_fragment_ctx *ctx,
215
215
ctx -> offset = ctx -> processed >> 3 ;
216
216
}
217
217
218
+ static inline uint8_t get_datagram_type (uint8_t * ptr )
219
+ {
220
+ return ptr [0 ] & NET_FRAG_DISPATCH_MASK ;
221
+ }
222
+
218
223
static inline uint16_t get_datagram_size (uint8_t * ptr )
219
224
{
220
225
return ((ptr [0 ] & 0x1F ) << 8 ) | ptr [1 ];
@@ -344,8 +349,7 @@ static inline struct frag_cache *get_reass_cache(uint16_t size, uint16_t tag)
344
349
345
350
static inline void fragment_append (struct net_pkt * pkt , struct net_buf * frag )
346
351
{
347
- if ((frag -> data [0 ] & NET_FRAG_DISPATCH_MASK ) ==
348
- NET_6LO_DISPATCH_FRAG1 ) {
352
+ if (get_datagram_type (frag -> data ) == NET_6LO_DISPATCH_FRAG1 ) {
349
353
/* Always make sure first fragment is inserted first
350
354
* This will be useful for fragment_cached_pkt_len()
351
355
*/
@@ -367,8 +371,7 @@ static inline size_t fragment_cached_pkt_len(struct net_pkt *pkt)
367
371
while (frag ) {
368
372
uint16_t hdr_len = NET_6LO_FRAGN_HDR_LEN ;
369
373
370
- if ((frag -> data [0 ] & NET_FRAG_DISPATCH_MASK ) ==
371
- NET_6LO_DISPATCH_FRAG1 ) {
374
+ if (get_datagram_type (frag -> data ) == NET_6LO_DISPATCH_FRAG1 ) {
372
375
hdr_len = NET_6LO_FRAG1_HDR_LEN ;
373
376
}
374
377
@@ -396,8 +399,7 @@ static inline size_t fragment_cached_pkt_len(struct net_pkt *pkt)
396
399
397
400
static inline uint16_t fragment_offset (struct net_buf * frag )
398
401
{
399
- if ((frag -> data [0 ] & NET_FRAG_DISPATCH_MASK ) ==
400
- NET_6LO_DISPATCH_FRAG1 ) {
402
+ if (get_datagram_type (frag -> data ) == NET_6LO_DISPATCH_FRAG1 ) {
401
403
return 0 ;
402
404
}
403
405
@@ -435,8 +437,7 @@ static inline void fragment_remove_headers(struct net_pkt *pkt)
435
437
while (frag ) {
436
438
uint16_t hdr_len = NET_6LO_FRAGN_HDR_LEN ;
437
439
438
- if ((frag -> data [0 ] & NET_FRAG_DISPATCH_MASK ) ==
439
- NET_6LO_DISPATCH_FRAG1 ) {
440
+ if (get_datagram_type (frag -> data ) == NET_6LO_DISPATCH_FRAG1 ) {
440
441
hdr_len = NET_6LO_FRAG1_HDR_LEN ;
441
442
}
442
443
@@ -486,18 +487,28 @@ static inline enum net_verdict fragment_add_to_cache(struct net_pkt *pkt)
486
487
struct net_buf * frag ;
487
488
uint16_t size ;
488
489
uint16_t tag ;
490
+ uint8_t type ;
491
+
492
+ frag = pkt -> buffer ;
493
+ type = get_datagram_type (frag -> data );
494
+
495
+ if ((type == NET_6LO_DISPATCH_FRAG1 &&
496
+ frag -> len < NET_6LO_FRAG1_HDR_LEN ) ||
497
+ (type == NET_6LO_DISPATCH_FRAGN &&
498
+ frag -> len < NET_6LO_FRAGN_HDR_LEN )) {
499
+ return NET_DROP ;
500
+ }
489
501
490
502
/* Parse total size of packet */
491
- size = get_datagram_size (pkt -> buffer -> data );
503
+ size = get_datagram_size (frag -> data );
492
504
493
505
/* Parse the datagram tag */
494
- tag = get_datagram_tag (pkt -> buffer -> data +
506
+ tag = get_datagram_tag (frag -> data +
495
507
NET_6LO_FRAG_DATAGRAM_SIZE_LEN );
496
508
497
509
/* If there are no fragments in the cache means this frag
498
510
* is the first one. So cache Rx pkt otherwise not.
499
511
*/
500
- frag = pkt -> buffer ;
501
512
pkt -> buffer = NULL ;
502
513
503
514
cache = get_reass_cache (size , tag );
@@ -556,8 +567,7 @@ enum net_verdict ieee802154_reassemble(struct net_pkt *pkt)
556
567
return NET_DROP ;
557
568
}
558
569
559
- if ((pkt -> buffer -> data [0 ] & NET_FRAG_DISPATCH_MASK ) >=
560
- NET_6LO_DISPATCH_FRAG1 ) {
570
+ if (get_datagram_type (pkt -> buffer -> data ) >= NET_6LO_DISPATCH_FRAG1 ) {
561
571
return fragment_add_to_cache (pkt );
562
572
} else {
563
573
NET_DBG ("No frag dispatch (%02x)" , pkt -> buffer -> data [0 ]);
0 commit comments