3
3
* written by Alexander Smirnov <[email protected] >
4
4
*/
5
5
6
- /*
7
- * Based on patches from Jon Smirl <[email protected] >
6
+ /* Based on patches from Jon Smirl <[email protected] >
8
7
* Copyright (c) 2011 Jon Smirl <[email protected] >
9
8
*
10
9
* This program is free software; you can redistribute it and/or modify
58
57
#include <net/ipv6.h>
59
58
#include <net/af_ieee802154.h>
60
59
61
- /*
62
- * Uncompress address function for source and
60
+ /* Uncompress address function for source and
63
61
* destination address(non-multicast).
64
62
*
65
63
* address_mode is sam value or dam value.
66
64
*/
67
65
static int uncompress_addr (struct sk_buff * skb ,
68
- struct in6_addr * ipaddr , const u8 address_mode ,
69
- const u8 * lladdr , const u8 addr_type ,
70
- const u8 addr_len )
66
+ struct in6_addr * ipaddr , const u8 address_mode ,
67
+ const u8 * lladdr , const u8 addr_type ,
68
+ const u8 addr_len )
71
69
{
72
70
bool fail ;
73
71
@@ -140,13 +138,12 @@ static int uncompress_addr(struct sk_buff *skb,
140
138
return 0 ;
141
139
}
142
140
143
- /*
144
- * Uncompress address function for source context
141
+ /* Uncompress address function for source context
145
142
* based address(non-multicast).
146
143
*/
147
144
static int uncompress_context_based_src_addr (struct sk_buff * skb ,
148
- struct in6_addr * ipaddr ,
149
- const u8 sam )
145
+ struct in6_addr * ipaddr ,
146
+ const u8 sam )
150
147
{
151
148
switch (sam ) {
152
149
case LOWPAN_IPHC_ADDR_00 :
@@ -175,13 +172,13 @@ static int uncompress_context_based_src_addr(struct sk_buff *skb,
175
172
}
176
173
177
174
static int skb_deliver (struct sk_buff * skb , struct ipv6hdr * hdr ,
178
- struct net_device * dev , skb_delivery_cb deliver_skb )
175
+ struct net_device * dev , skb_delivery_cb deliver_skb )
179
176
{
180
177
struct sk_buff * new ;
181
178
int stat ;
182
179
183
- new = skb_copy_expand (skb , sizeof (struct ipv6hdr ), skb_tailroom ( skb ),
184
- GFP_ATOMIC );
180
+ new = skb_copy_expand (skb , sizeof (struct ipv6hdr ),
181
+ skb_tailroom ( skb ), GFP_ATOMIC );
185
182
kfree_skb (skb );
186
183
187
184
if (!new )
@@ -196,7 +193,7 @@ static int skb_deliver(struct sk_buff *skb, struct ipv6hdr *hdr,
196
193
new -> dev = dev ;
197
194
198
195
raw_dump_table (__func__ , "raw skb data dump before receiving" ,
199
- new -> data , new -> len );
196
+ new -> data , new -> len );
200
197
201
198
stat = deliver_skb (new , dev );
202
199
@@ -210,8 +207,8 @@ static int skb_deliver(struct sk_buff *skb, struct ipv6hdr *hdr,
210
207
*/
211
208
static int
212
209
lowpan_uncompress_multicast_daddr (struct sk_buff * skb ,
213
- struct in6_addr * ipaddr ,
214
- const u8 dam )
210
+ struct in6_addr * ipaddr ,
211
+ const u8 dam )
215
212
{
216
213
bool fail ;
217
214
@@ -314,8 +311,7 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
314
311
fail |= lowpan_fetch_skb (skb , & uh -> check , 2 );
315
312
}
316
313
317
- /*
318
- * UDP lenght needs to be infered from the lower layers
314
+ /* UDP lenght needs to be infered from the lower layers
319
315
* here, we obtain the hint from the remaining size of the
320
316
* frame
321
317
*/
@@ -338,16 +334,17 @@ uncompress_udp_header(struct sk_buff *skb, struct udphdr *uh)
338
334
static const u8 lowpan_ttl_values [] = { 0 , 1 , 64 , 255 };
339
335
340
336
int lowpan_process_data (struct sk_buff * skb , struct net_device * dev ,
341
- const u8 * saddr , const u8 saddr_type , const u8 saddr_len ,
342
- const u8 * daddr , const u8 daddr_type , const u8 daddr_len ,
343
- u8 iphc0 , u8 iphc1 , skb_delivery_cb deliver_skb )
337
+ const u8 * saddr , const u8 saddr_type ,
338
+ const u8 saddr_len , const u8 * daddr ,
339
+ const u8 daddr_type , const u8 daddr_len ,
340
+ u8 iphc0 , u8 iphc1 , skb_delivery_cb deliver_skb )
344
341
{
345
342
struct ipv6hdr hdr = {};
346
343
u8 tmp , num_context = 0 ;
347
344
int err ;
348
345
349
346
raw_dump_table (__func__ , "raw skb data dump uncompressed" ,
350
- skb -> data , skb -> len );
347
+ skb -> data , skb -> len );
351
348
352
349
/* another if the CID flag is set */
353
350
if (iphc1 & LOWPAN_IPHC_CID ) {
@@ -360,8 +357,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
360
357
361
358
/* Traffic Class and Flow Label */
362
359
switch ((iphc0 & LOWPAN_IPHC_TF ) >> 3 ) {
363
- /*
364
- * Traffic Class and FLow Label carried in-line
360
+ /* Traffic Class and FLow Label carried in-line
365
361
* ECN + DSCP + 4-bit Pad + Flow Label (4 bytes)
366
362
*/
367
363
case 0 : /* 00b */
@@ -374,8 +370,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
374
370
hdr .flow_lbl [0 ] = ((tmp >> 2 ) & 0x30 ) | (tmp << 6 ) |
375
371
(hdr .flow_lbl [0 ] & 0x0f );
376
372
break ;
377
- /*
378
- * Traffic class carried in-line
373
+ /* Traffic class carried in-line
379
374
* ECN + DSCP (1 byte), Flow Label is elided
380
375
*/
381
376
case 2 : /* 10b */
@@ -385,8 +380,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
385
380
hdr .priority = ((tmp >> 2 ) & 0x0f );
386
381
hdr .flow_lbl [0 ] = ((tmp << 6 ) & 0xC0 ) | ((tmp >> 2 ) & 0x30 );
387
382
break ;
388
- /*
389
- * Flow Label carried in-line
383
+ /* Flow Label carried in-line
390
384
* ECN + 2-bit Pad + Flow Label (3 bytes), DSCP is elided
391
385
*/
392
386
case 1 : /* 01b */
@@ -415,9 +409,9 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
415
409
}
416
410
417
411
/* Hop Limit */
418
- if ((iphc0 & 0x03 ) != LOWPAN_IPHC_TTL_I )
412
+ if ((iphc0 & 0x03 ) != LOWPAN_IPHC_TTL_I ) {
419
413
hdr .hop_limit = lowpan_ttl_values [iphc0 & 0x03 ];
420
- else {
414
+ } else {
421
415
if (lowpan_fetch_skb_u8 (skb , & (hdr .hop_limit )))
422
416
goto drop ;
423
417
}
@@ -429,12 +423,12 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
429
423
/* Source address context based uncompression */
430
424
pr_debug ("SAC bit is set. Handle context based source address.\n" );
431
425
err = uncompress_context_based_src_addr (
432
- skb , & hdr .saddr , tmp );
426
+ skb , & hdr .saddr , tmp );
433
427
} else {
434
428
/* Source address uncompression */
435
429
pr_debug ("source address stateless compression\n" );
436
430
err = uncompress_addr (skb , & hdr .saddr , tmp , saddr ,
437
- saddr_type , saddr_len );
431
+ saddr_type , saddr_len );
438
432
}
439
433
440
434
/* Check on error of previous branch */
@@ -457,9 +451,9 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
457
451
}
458
452
} else {
459
453
err = uncompress_addr (skb , & hdr .daddr , tmp , daddr ,
460
- daddr_type , daddr_len );
454
+ daddr_type , daddr_len );
461
455
pr_debug ("dest: stateless compression mode %d dest %pI6c\n" ,
462
- tmp , & hdr .daddr );
456
+ tmp , & hdr .daddr );
463
457
if (err )
464
458
goto drop ;
465
459
}
@@ -468,11 +462,11 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
468
462
if (iphc0 & LOWPAN_IPHC_NH_C ) {
469
463
struct udphdr uh ;
470
464
struct sk_buff * new ;
465
+
471
466
if (uncompress_udp_header (skb , & uh ))
472
467
goto drop ;
473
468
474
- /*
475
- * replace the compressed UDP head by the uncompressed UDP
469
+ /* replace the compressed UDP head by the uncompressed UDP
476
470
* header
477
471
*/
478
472
new = skb_copy_expand (skb , sizeof (struct udphdr ),
@@ -489,7 +483,7 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
489
483
skb_copy_to_linear_data (skb , & uh , sizeof (struct udphdr ));
490
484
491
485
raw_dump_table (__func__ , "raw UDP header dump" ,
492
- (u8 * )& uh , sizeof (uh ));
486
+ (u8 * )& uh , sizeof (uh ));
493
487
494
488
hdr .nexthdr = UIP_PROTO_UDP ;
495
489
}
@@ -504,8 +498,8 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
504
498
hdr .version , ntohs (hdr .payload_len ), hdr .nexthdr ,
505
499
hdr .hop_limit , & hdr .daddr );
506
500
507
- raw_dump_table (__func__ , "raw header dump" , ( u8 * ) & hdr ,
508
- sizeof (hdr ));
501
+ raw_dump_table (__func__ , "raw header dump" ,
502
+ ( u8 * ) & hdr , sizeof (hdr ));
509
503
510
504
return skb_deliver (skb , & hdr , dev , deliver_skb );
511
505
@@ -516,8 +510,8 @@ int lowpan_process_data(struct sk_buff *skb, struct net_device *dev,
516
510
EXPORT_SYMBOL_GPL (lowpan_process_data );
517
511
518
512
static u8 lowpan_compress_addr_64 (u8 * * hc06_ptr , u8 shift ,
519
- const struct in6_addr * ipaddr ,
520
- const unsigned char * lladdr )
513
+ const struct in6_addr * ipaddr ,
514
+ const unsigned char * lladdr )
521
515
{
522
516
u8 val = 0 ;
523
517
@@ -530,14 +524,14 @@ static u8 lowpan_compress_addr_64(u8 **hc06_ptr, u8 shift,
530
524
* hc06_ptr += 2 ;
531
525
val = 2 ; /* 16-bits */
532
526
raw_dump_inline (NULL , "Compressed ipv6 addr is (16 bits)" ,
533
- * hc06_ptr - 2 , 2 );
527
+ * hc06_ptr - 2 , 2 );
534
528
} else {
535
529
/* do not compress IID => xxxx::IID */
536
530
memcpy (* hc06_ptr , & ipaddr -> s6_addr16 [4 ], 8 );
537
531
* hc06_ptr += 8 ;
538
532
val = 1 ; /* 64-bits */
539
533
raw_dump_inline (NULL , "Compressed ipv6 addr is (64 bits)" ,
540
- * hc06_ptr - 8 , 8 );
534
+ * hc06_ptr - 8 , 8 );
541
535
}
542
536
543
537
return rol8 (val , shift );
@@ -601,8 +595,8 @@ static void compress_udp_header(u8 **hc06_ptr, struct sk_buff *skb)
601
595
}
602
596
603
597
int lowpan_header_compress (struct sk_buff * skb , struct net_device * dev ,
604
- unsigned short type , const void * _daddr ,
605
- const void * _saddr , unsigned int len )
598
+ unsigned short type , const void * _daddr ,
599
+ const void * _saddr , unsigned int len )
606
600
{
607
601
u8 tmp , iphc0 , iphc1 , * hc06_ptr ;
608
602
struct ipv6hdr * hdr ;
@@ -616,14 +610,13 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
616
610
617
611
pr_debug ("IPv6 header dump:\n\tversion = %d\n\tlength = %d\n"
618
612
"\tnexthdr = 0x%02x\n\thop_lim = %d\n\tdest = %pI6c\n" ,
619
- hdr -> version , ntohs (hdr -> payload_len ), hdr -> nexthdr ,
620
- hdr -> hop_limit , & hdr -> daddr );
613
+ hdr -> version , ntohs (hdr -> payload_len ), hdr -> nexthdr ,
614
+ hdr -> hop_limit , & hdr -> daddr );
621
615
622
616
raw_dump_table (__func__ , "raw skb network header dump" ,
623
- skb_network_header (skb ), sizeof (struct ipv6hdr ));
617
+ skb_network_header (skb ), sizeof (struct ipv6hdr ));
624
618
625
- /*
626
- * As we copy some bit-length fields, in the IPHC encoding bytes,
619
+ /* As we copy some bit-length fields, in the IPHC encoding bytes,
627
620
* we sometimes use |=
628
621
* If the field is 0, and the current bit value in memory is 1,
629
622
* this does not work. We therefore reset the IPHC encoding here
@@ -639,11 +632,10 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
639
632
(unsigned char * )_daddr , IEEE802154_ADDR_LEN );
640
633
641
634
raw_dump_table (__func__ ,
642
- "sending raw skb network uncompressed packet" ,
643
- skb -> data , skb -> len );
635
+ "sending raw skb network uncompressed packet" ,
636
+ skb -> data , skb -> len );
644
637
645
- /*
646
- * Traffic class, flow label
638
+ /* Traffic class, flow label
647
639
* If flow label is 0, compress it. If traffic class is 0, compress it
648
640
* We have to process both in the same time as the offset of traffic
649
641
* class depends on the presence of version and flow label
@@ -654,11 +646,11 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
654
646
tmp = ((tmp & 0x03 ) << 6 ) | (tmp >> 2 );
655
647
656
648
if (((hdr -> flow_lbl [0 ] & 0x0F ) == 0 ) &&
657
- (hdr -> flow_lbl [1 ] == 0 ) && (hdr -> flow_lbl [2 ] == 0 )) {
649
+ (hdr -> flow_lbl [1 ] == 0 ) && (hdr -> flow_lbl [2 ] == 0 )) {
658
650
/* flow label can be compressed */
659
651
iphc0 |= LOWPAN_IPHC_FL_C ;
660
652
if ((hdr -> priority == 0 ) &&
661
- ((hdr -> flow_lbl [0 ] & 0xF0 ) == 0 )) {
653
+ ((hdr -> flow_lbl [0 ] & 0xF0 ) == 0 )) {
662
654
/* compress (elide) all */
663
655
iphc0 |= LOWPAN_IPHC_TC_C ;
664
656
} else {
@@ -669,7 +661,7 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
669
661
} else {
670
662
/* Flow label cannot be compressed */
671
663
if ((hdr -> priority == 0 ) &&
672
- ((hdr -> flow_lbl [0 ] & 0xF0 ) == 0 )) {
664
+ ((hdr -> flow_lbl [0 ] & 0xF0 ) == 0 )) {
673
665
/* compress only traffic class */
674
666
iphc0 |= LOWPAN_IPHC_TC_C ;
675
667
* hc06_ptr = (tmp & 0xc0 ) | (hdr -> flow_lbl [0 ] & 0x0F );
@@ -695,8 +687,7 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
695
687
hc06_ptr += 1 ;
696
688
}
697
689
698
- /*
699
- * Hop limit
690
+ /* Hop limit
700
691
* if 1: compress, encoding is 01
701
692
* if 64: compress, encoding is 10
702
693
* if 255: compress, encoding is 11
@@ -793,7 +784,7 @@ int lowpan_header_compress(struct sk_buff *skb, struct net_device *dev,
793
784
pr_debug ("header len %d skb %u\n" , (int )(hc06_ptr - head ), skb -> len );
794
785
795
786
raw_dump_table (__func__ , "raw skb data dump compressed" ,
796
- skb -> data , skb -> len );
787
+ skb -> data , skb -> len );
797
788
return 0 ;
798
789
}
799
790
EXPORT_SYMBOL_GPL (lowpan_header_compress );
0 commit comments