summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlin Nastac <alin.nastac@gmail.com>2019-10-08 12:54:11 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2019-10-09 12:14:23 +0200
commitbd7b0115c11870d3a97b8c0ed25498b6eed2aa8f (patch)
tree77c18fa2011241fe1aa94568e34a9f456767abec
parent62fb3c7201157026956255228392d0c52e1e294e (diff)
checksum: Fix TCP/UDP checksum computation on big endian archesHEADmaster
On big endian arches UDP/TCP checksum is incorrectly computed when payload length is odd. Signed-off-by: Alin Nastac <alin.nastac@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/extra/checksum.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/extra/checksum.c b/src/extra/checksum.c
index 4d52a99..42389aa 100644
--- a/src/extra/checksum.c
+++ b/src/extra/checksum.c
@@ -11,6 +11,7 @@
#include <stdio.h>
#include <stdbool.h>
+#include <endian.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
@@ -26,8 +27,13 @@ uint16_t nfq_checksum(uint32_t sum, uint16_t *buf, int size)
sum += *buf++;
size -= sizeof(uint16_t);
}
- if (size)
- sum += *(uint8_t *)buf;
+ if (size) {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ sum += (uint16_t)*(uint8_t *)buf << 8;
+#else
+ sum += (uint16_t)*(uint8_t *)buf;
+#endif
+ }
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >>16);