1 --- a/src/extra/checksum.c
2 +++ b/src/extra/checksum.c
9 #include <netinet/ip.h>
10 #include <netinet/ip6.h>
11 @@ -26,8 +27,13 @@ uint16_t checksum(uint32_t sum, uint16_t
13 size -= sizeof(uint16_t);
16 - sum += *(uint8_t *)buf;
18 +#if __BYTE_ORDER == __BIG_ENDIAN
19 + sum += (uint16_t)*(uint8_t *)buf << 8;
21 + sum += (uint16_t)*(uint8_t *)buf;
25 sum = (sum >> 16) + (sum & 0xffff);
27 @@ -35,7 +41,7 @@ uint16_t checksum(uint32_t sum, uint16_t
28 return (uint16_t)(~sum);
31 -uint16_t checksum_tcpudp_ipv4(struct iphdr *iph)
32 +uint16_t checksum_tcpudp_ipv4(struct iphdr *iph, uint16_t protocol_id)
35 uint32_t iph_len = iph->ihl*4;
36 @@ -46,13 +52,13 @@ uint16_t checksum_tcpudp_ipv4(struct iph
37 sum += (iph->saddr) & 0xFFFF;
38 sum += (iph->daddr >> 16) & 0xFFFF;
39 sum += (iph->daddr) & 0xFFFF;
40 - sum += htons(IPPROTO_TCP);
41 + sum += htons(protocol_id);
44 return checksum(sum, (uint16_t *)payload, len);
47 -uint16_t checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr)
48 +uint16_t checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr, uint16_t protocol_id)
51 uint32_t hdr_len = (uint32_t *)transport_hdr - (uint32_t *)ip6h;
52 @@ -68,7 +74,7 @@ uint16_t checksum_tcpudp_ipv6(struct ip6
53 sum += (ip6h->ip6_dst.s6_addr16[i] >> 16) & 0xFFFF;
54 sum += (ip6h->ip6_dst.s6_addr16[i]) & 0xFFFF;
56 - sum += htons(IPPROTO_TCP);
57 + sum += htons(protocol_id);
58 sum += htons(ip6h->ip6_plen);
60 return checksum(sum, (uint16_t *)payload, len);
63 @@ -91,7 +91,7 @@ nfq_tcp_compute_checksum_ipv4(struct tcp
65 /* checksum field in header needs to be zero for calculation. */
67 - tcph->check = checksum_tcpudp_ipv4(iph);
68 + tcph->check = checksum_tcpudp_ipv4(iph, IPPROTO_TCP);
70 EXPORT_SYMBOL(nfq_tcp_compute_checksum_ipv4);
72 @@ -105,7 +105,7 @@ nfq_tcp_compute_checksum_ipv6(struct tcp
74 /* checksum field in header needs to be zero for calculation. */
76 - tcph->check = checksum_tcpudp_ipv6(ip6h, tcph);
77 + tcph->check = checksum_tcpudp_ipv6(ip6h, tcph, IPPROTO_TCP);
79 EXPORT_SYMBOL(nfq_tcp_compute_checksum_ipv6);
83 @@ -91,7 +91,7 @@ nfq_udp_compute_checksum_ipv4(struct udp
85 /* checksum field in header needs to be zero for calculation. */
87 - udph->check = checksum_tcpudp_ipv4(iph);
88 + udph->check = checksum_tcpudp_ipv4(iph, IPPROTO_UDP);
90 EXPORT_SYMBOL(nfq_udp_compute_checksum_ipv4);
92 @@ -110,7 +110,7 @@ nfq_udp_compute_checksum_ipv6(struct udp
94 /* checksum field in header needs to be zero for calculation. */
96 - udph->check = checksum_tcpudp_ipv6(ip6h, udph);
97 + udph->check = checksum_tcpudp_ipv6(ip6h, udph, IPPROTO_UDP);
99 EXPORT_SYMBOL(nfq_udp_compute_checksum_ipv6);
103 @@ -13,8 +13,8 @@ struct iphdr;
106 uint16_t checksum(uint32_t sum, uint16_t *buf, int size);
107 -uint16_t checksum_tcpudp_ipv4(struct iphdr *iph);
108 -uint16_t checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr);
109 +uint16_t checksum_tcpudp_ipv4(struct iphdr *iph, uint16_t protocol_id);
110 +uint16_t checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr, uint16_t protocol_id);