netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ftp.linux.org.uk>
To: David Miller <davem@davemloft.net>
Cc: dlstevens@us.ibm.com, brian.haley@hp.com, netdev@vger.kernel.org,
	netdev-owner@vger.kernel.org
Subject: Re: [PATCH] IPv6: only modify checksum for UDP
Date: Tue, 14 Nov 2006 01:18:33 +0000	[thread overview]
Message-ID: <20061114011833.GV29920@ftp.linux.org.uk> (raw)
In-Reply-To: <20061113.165058.15265737.davem@davemloft.net>

On Mon, Nov 13, 2006 at 04:50:58PM -0800, David Miller wrote:
> From: David Stevens <dlstevens@us.ibm.com>
> Date: Fri, 10 Nov 2006 09:54:58 -0800
> 
> > The Internet checksum is defined as a 1's-complement sum, so if  the
> > alternate 0 does not have a special meaning in a protocol, then by
> > 1's-complement arithmetic, 0 == ~0.

Nope.  It isn't.

> >         So, it looks to me without the remapping that a valid checksum
> > may also fail, if it is simply computed in a different way (or on a 
> > different
> > architecture) such that one gets 0 and one gets ~0 as un-modified answers.
> >         Since we're checking for equality on 2's-complement machines,
> > I think the easiest thing is to still re-map it. Otherwise, instead of 
> > testing
> > for 0, we have to test for both 0 and ~0 in the validity checks, right?
> 
> Puzzling :-)  Then why is the transformation only performed for
> UDP in the ipv4 stack?  It seems by your logic TCP would need
> to either do the "if (sum==0) sum=~0;"  thing or it would need
> to accept both "0" and "~0" in the checksum checking path.

The check is "1's compelement sum of entire packet (including the checksum)
is 0xffff".  So unless *everything* *else* in the packet is 0, 0x0000 and
0xffff in checksum are the same.  And for very obvious reasons "everything
else is 0" won't be recognized as valid packet anyway...

The following is true:
	for any x except 0 we have x # 0xffff equal to x
	for any x we have x # 0 equal to x
	x # y is 0 if and only if both x and y are 0.

So unless the sum of all words except the checksum is 0 (i.e. all words
are except the checksum are 0), 0 and 0xffff in checksum will result in
the same total sums.

  reply	other threads:[~2006-11-14  1:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-08 22:13 why do we mangle checksums for v6 ICMP? Al Viro
2006-11-08 22:28 ` Al Viro
2006-11-09 17:32 ` Brian Haley
2006-11-09 23:14   ` David Miller
2006-11-10 16:24     ` [PATCH] IPv6: only modify checksum for UDP Brian Haley
2006-11-10 17:54       ` David Stevens
2006-11-14  0:50         ` David Miller
2006-11-14  1:18           ` Al Viro [this message]
2006-11-14  1:44           ` David Stevens
2006-11-14  1:52             ` Al Viro
2006-11-10 22:55       ` David Miller
2006-11-10 23:17         ` Nivedita Singhvi
2006-11-10 23:26           ` David Miller
2006-11-10 23:36             ` Nivedita Singhvi
2006-11-12  1:30             ` Brian Haley
2006-11-10 16:25     ` [PATCH] IPv6: optimize echo reply checksum calculation Brian Haley
2006-11-10 17:34       ` Al Viro
2006-11-10 17:51         ` Brian Haley
2006-11-10 18:05           ` Al Viro
2006-11-10 18:20             ` Al Viro
2006-11-10 19:04               ` Brian Haley
2006-11-10 19:17                 ` Al Viro
2006-11-10 21:06                   ` Brian Haley
2006-11-11  1:45                     ` Al Viro
2006-11-11 18:07     ` why do we mangle checksums for v6 ICMP? Bill Fink
2006-11-13  7:04       ` David Miller

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=20061114011833.GV29920@ftp.linux.org.uk \
    --to=viro@ftp.linux.org.uk \
    --cc=brian.haley@hp.com \
    --cc=davem@davemloft.net \
    --cc=dlstevens@us.ibm.com \
    --cc=netdev-owner@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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 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).