All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Netfilter Development Mailinglist <netfilter-devel@lists.netfilter.org>
Subject: Re: [PATCH NFSIM]: Fix invalid IP checksums on 64bit
Date: Fri, 07 Jan 2005 02:25:57 +0100	[thread overview]
Message-ID: <41DDE525.8020103@trash.net> (raw)
In-Reply-To: <41DD4B67.6010205@trash.net>

[-- Attachment #1: Type: text/plain, Size: 440 bytes --]

Patrick McHardy wrote:

> IP checksums are calculated wrong on 64 bit because too large types 
> are used.
> This patch fixes them and a couple of unrelated 
> snprintf-sizeof-warnings in the
> same file. I still get invalid TCP checksums, but couldn't locate the 
> problem yet.
>
I found the real bug, my previous fix just hid it. This patch fixes
all checksum problems, the calculated checksum are equal to the ones
of a 32-bit binary.


[-- Attachment #2: 6.diff --]
[-- Type: text/x-patch, Size: 1203 bytes --]

Index: core/ipv4/ipv4.c
===================================================================
--- core/ipv4/ipv4.c	(revision 3579)
+++ core/ipv4/ipv4.c	(working copy)
@@ -600,7 +600,7 @@
 		if (count) {
 		        unsigned long carry = 0;
 			do {
-				unsigned long w = *(unsigned long *) buff;
+				unsigned int w = *(unsigned int *) buff;
 				count--;
 				buff += 4;
 				result += carry;
@@ -819,7 +819,7 @@
 	switch (iph->protocol) {
 	case IPPROTO_ICMP:
 		icmph = (struct icmphdr *)(iph + 1);
-		ptr += sprintf(ptr, "%u %u ",
+		ptr += sprintf(ptr, "%Zu %u ",
 		       iplen - sizeof(struct icmphdr), iph->protocol);
 
 		if (len < sizeof(struct icmphdr)) {
@@ -855,7 +855,7 @@
 
 	case IPPROTO_UDP:
 		udph = (struct udphdr *)(iph + 1);
-		ptr += sprintf(ptr, "%u %u ",
+		ptr += sprintf(ptr, "%Zu %u ",
 		       iplen - sizeof(struct udphdr), iph->protocol);
 
 		if (len < sizeof(struct udphdr)) {
@@ -891,7 +891,7 @@
 		tcph = (struct tcphdr *)(iph + 1);
 		if (len < sizeof(struct tcphdr)) {
 			/* Assume no tcp options... */
-			ptr += sprintf(ptr, "%u %u ",
+			ptr += sprintf(ptr, "%Zu %u ",
 				       iplen - sizeof(*tcph), iph->protocol);
 
 			ptr += sprintf(ptr, "-TRUNCATED-");

      reply	other threads:[~2005-01-07  1:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-06 14:29 [PATCH NFSIM]: Fix invalid IP checksums on 64bit Patrick McHardy
2005-01-07  1:25 ` Patrick McHardy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41DDE525.8020103@trash.net \
    --to=kaber@trash.net \
    --cc=netfilter-devel@lists.netfilter.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.