Browse Source

tayga: fix broken ICMP checksum on big-endian machines

This patches fixes wrong ICMP checksum of translated packets on
big-endian machines #16715
The patch is authored by upstream author
Nathan Lutchansky <lutchann@litech.org>
Source of the patch: http://forum.mikrotik.com/viewtopic.php?f=15&t=82329

Signed-off-by: Ondrej Caletka <ondrej@caletka.cz>
Ondřej Caletka 10 years ago
parent
commit
8a90bbadd7
1 changed files with 53 additions and 0 deletions
  1. 53
    0
      ipv6/tayga/patches/002-bigendian_wrong_checksum.patch

+ 53
- 0
ipv6/tayga/patches/002-bigendian_wrong_checksum.patch View File

@@ -0,0 +1,53 @@
1
+--- a/nat64.c
2
++++ b/nat64.c
3
+@@ -19,6 +19,11 @@
4
+ 
5
+ extern struct config *gcfg;
6
+ 
7
++static uint16_t checksum_extend_byte(uint8_t b)
8
++{
9
++	return htons(b << 8);
10
++}
11
++
12
+ static uint16_t ip_checksum(void *d, int c)
13
+ {
14
+ 	uint32_t sum = 0xffff;
15
+@@ -30,7 +35,7 @@ static uint16_t ip_checksum(void *d, int
16
+ 	}
17
+ 
18
+ 	if (c)
19
+-		sum += htons(*((uint8_t *)p) << 8);
20
++		sum += checksum_extend_byte(*((uint8_t *)p));
21
+ 
22
+ 	while (sum > 0xffff)
23
+ 		sum = (sum & 0xffff) + (sum >> 16);
24
+@@ -180,10 +185,12 @@ static int xlate_payload_4to6(struct pkt
25
+ 		cksum = ones_add(p->icmp->cksum, cksum);
26
+ 		if (p->icmp->type == 8) {
27
+ 			p->icmp->type = 128;
28
+-			p->icmp->cksum = ones_add(cksum, ~(128 - 8));
29
++			p->icmp->cksum = ones_add(cksum,
30
++						~checksum_extend_byte(128 - 8));
31
+ 		} else {
32
+ 			p->icmp->type = 129;
33
+-			p->icmp->cksum = ones_add(cksum, ~(129 - 0));
34
++			p->icmp->cksum = ones_add(cksum,
35
++						~checksum_extend_byte(129 - 0));
36
+ 		}
37
+ 		return 0;
38
+ 	case 17:
39
+@@ -668,10 +675,12 @@ static int xlate_payload_6to4(struct pkt
40
+ 		cksum = ones_add(p->icmp->cksum, cksum);
41
+ 		if (p->icmp->type == 128) {
42
+ 			p->icmp->type = 8;
43
+-			p->icmp->cksum = ones_add(cksum, 128 - 8);
44
++			p->icmp->cksum = ones_add(cksum,
45
++						checksum_extend_byte(128 - 8));
46
+ 		} else {
47
+ 			p->icmp->type = 0;
48
+-			p->icmp->cksum = ones_add(cksum, 129 - 0);
49
++			p->icmp->cksum = ones_add(cksum,
50
++						checksum_extend_byte(129 - 0));
51
+ 		}
52
+ 		return 0;
53
+ 	case 17: