px5g: remove legacy polarssl support
[oweals/openwrt.git] / package / libs / libnetfilter-queue / patches / 100-checksum_computation.patch
1 --- a/src/extra/checksum.c
2 +++ b/src/extra/checksum.c
3 @@ -11,6 +11,7 @@
4  
5  #include <stdio.h>
6  #include <stdbool.h>
7 +#include <endian.h>
8  #include <arpa/inet.h>
9  #include <netinet/ip.h>
10  #include <netinet/ip6.h>
11 @@ -26,8 +27,13 @@ uint16_t nfq_checksum(uint32_t sum, uint16_t *buf, int size)
12                 sum += *buf++;
13                 size -= sizeof(uint16_t);
14         }
15 -       if (size)
16 -               sum += *(uint8_t *)buf;
17 +       if (size) {
18 +#if __BYTE_ORDER == __BIG_ENDIAN
19 +               sum += (uint16_t)*(uint8_t *)buf << 8;
20 +#else
21 +               sum += (uint16_t)*(uint8_t *)buf;
22 +#endif
23 +       }
24  
25         sum = (sum >> 16) + (sum & 0xffff);
26         sum += (sum >>16);
27 @@ -35,7 +41,7 @@ uint16_t nfq_checksum(uint32_t sum, uint16_t *buf, int size)
28         return (uint16_t)(~sum);
29  }
30  
31 -uint16_t nfq_checksum_tcpudp_ipv4(struct iphdr *iph)
32 +uint16_t nfq_checksum_tcpudp_ipv4(struct iphdr *iph, uint16_t protocol_id)
33  {
34         uint32_t sum = 0;
35         uint32_t iph_len = iph->ihl*4;
36 @@ -46,13 +52,13 @@ uint16_t nfq_checksum_tcpudp_ipv4(struct iphdr *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);
42         sum += htons(len);
43  
44         return nfq_checksum(sum, (uint16_t *)payload, len);
45  }
46  
47 -uint16_t nfq_checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr)
48 +uint16_t nfq_checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr, uint16_t protocol_id)
49  {
50         uint32_t sum = 0;
51         uint32_t hdr_len = (uint32_t *)transport_hdr - (uint32_t *)ip6h;
52 @@ -68,7 +74,7 @@ uint16_t nfq_checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr)
53                 sum += (ip6h->ip6_dst.s6_addr16[i] >> 16) & 0xFFFF;
54                 sum += (ip6h->ip6_dst.s6_addr16[i]) & 0xFFFF;
55         }
56 -       sum += htons(IPPROTO_TCP);
57 +       sum += htons(protocol_id);
58         sum += htons(ip6h->ip6_plen);
59  
60         return nfq_checksum(sum, (uint16_t *)payload, len);
61 diff --git a/src/extra/tcp.c b/src/extra/tcp.c
62 index d1cd79d..a66f392 100644
63 --- a/src/extra/tcp.c
64 +++ b/src/extra/tcp.c
65 @@ -96,7 +96,7 @@ nfq_tcp_compute_checksum_ipv4(struct tcphdr *tcph, struct iphdr *iph)
66  {
67         /* checksum field in header needs to be zero for calculation. */
68         tcph->check = 0;
69 -       tcph->check = nfq_checksum_tcpudp_ipv4(iph);
70 +       tcph->check = nfq_checksum_tcpudp_ipv4(iph, IPPROTO_TCP);
71  }
72  EXPORT_SYMBOL(nfq_tcp_compute_checksum_ipv4);
73  
74 @@ -110,7 +110,7 @@ nfq_tcp_compute_checksum_ipv6(struct tcphdr *tcph, struct ip6_hdr *ip6h)
75  {
76         /* checksum field in header needs to be zero for calculation. */
77         tcph->check = 0;
78 -       tcph->check = nfq_checksum_tcpudp_ipv6(ip6h, tcph);
79 +       tcph->check = nfq_checksum_tcpudp_ipv6(ip6h, tcph, IPPROTO_TCP);
80  }
81  EXPORT_SYMBOL(nfq_tcp_compute_checksum_ipv6);
82  
83 --- a/src/extra/udp.c
84 +++ b/src/extra/udp.c
85 @@ -96,7 +96,7 @@ nfq_udp_compute_checksum_ipv4(struct udphdr *udph, struct iphdr *iph)
86  {
87         /* checksum field in header needs to be zero for calculation. */
88         udph->check = 0;
89 -       udph->check = nfq_checksum_tcpudp_ipv4(iph);
90 +       udph->check = nfq_checksum_tcpudp_ipv4(iph, IPPROTO_UDP);
91  }
92  EXPORT_SYMBOL(nfq_udp_compute_checksum_ipv4);
93  
94 @@ -115,7 +115,7 @@ nfq_udp_compute_checksum_ipv6(struct udphdr *udph, struct ip6_hdr *ip6h)
95  {
96         /* checksum field in header needs to be zero for calculation. */
97         udph->check = 0;
98 -       udph->check = nfq_checksum_tcpudp_ipv6(ip6h, udph);
99 +       udph->check = nfq_checksum_tcpudp_ipv6(ip6h, udph, IPPROTO_UDP);
100  }
101  EXPORT_SYMBOL(nfq_udp_compute_checksum_ipv6);
102  
103 --- a/src/internal.h
104 +++ b/src/internal.h
105 @@ -15,8 +15,8 @@ struct iphdr;
106  struct ip6_hdr;
107  
108  uint16_t nfq_checksum(uint32_t sum, uint16_t *buf, int size);
109 -uint16_t nfq_checksum_tcpudp_ipv4(struct iphdr *iph);
110 -uint16_t nfq_checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr);
111 +uint16_t nfq_checksum_tcpudp_ipv4(struct iphdr *iph, uint16_t protocol_id);
112 +uint16_t nfq_checksum_tcpudp_ipv6(struct ip6_hdr *ip6h, void *transport_hdr, uint16_t protocol_id);
113  
114  struct pkt_buff {
115         uint8_t *mac_header;