netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checksum: Fix TCP/UDP checksum computation on big endian arches
@ 2019-10-08 10:54 Alin Nastac
  2019-10-09 10:15 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Alin Nastac @ 2019-10-08 10:54 UTC (permalink / raw)
  To: netfilter-devel

On big endian arches UDP/TCP checksum is incorrectly computed when
payload length is odd.

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
---
 src/extra/checksum.c | 10 ++++++++--
 1 file 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);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] checksum: Fix TCP/UDP checksum computation on big endian arches
  2019-10-08 10:54 [PATCH] checksum: Fix TCP/UDP checksum computation on big endian arches Alin Nastac
@ 2019-10-09 10:15 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2019-10-09 10:15 UTC (permalink / raw)
  To: Alin Nastac; +Cc: netfilter-devel

On Tue, Oct 08, 2019 at 12:54:11PM +0200, Alin Nastac wrote:
> On big endian arches UDP/TCP checksum is incorrectly computed when
> payload length is odd.

Applied, thanks Alin.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-09 10:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-08 10:54 [PATCH] checksum: Fix TCP/UDP checksum computation on big endian arches Alin Nastac
2019-10-09 10:15 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).