All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] net: fix checksum verification
Date: Fri, 9 Aug 2013 10:57:35 +0200	[thread overview]
Message-ID: <20130809085735.GD26614@pengutronix.de> (raw)
In-Reply-To: <20130809085019.GT6104@pengutronix.de>

On Fri, Aug 09, 2013 at 10:50:19AM +0200, Uwe Kleine-König wrote:
> > D'oh. There's a bug indeed. For a good packet net_checksum returns
> > 0xffff (all ones in an u16). So the check should be:
> > 
> > 	return net_checksum(ptr, len) == 0xffff;
> with
> 
> 	return net_checksum(ptr, len) + 1
> 
> net_checksum_ok returns always something >0 (i.e. success) because both
> summands are converted to unsigned, and so never catches an error[1],
> does it?
> 
> > U-Boot has this instead:
> > 
> > 	return !((net_checksum(ptr, len) + 1) & 0xfffe);
> > 
> > From what I see both above should be equivalent so I wonder why U-Boot
> > has such a complicated code here. Some compiler optimization or is this
> > something I don't see?
> This isn't equivalent. The U-Boot code returns 1 iff net_checksum
> returns 0 or 0xffff; 0 otherwise.

Hm, indeed. Which brings me to my next question: In which cases does
net_checksum() return 0 and the result can be considered ok?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2013-08-09  8:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-09  4:01 [PATCH] net: fix checksum verification Baruch Siach
2013-08-09  7:32 ` Sascha Hauer
2013-08-09  8:50   ` Uwe Kleine-König
2013-08-09  8:57     ` Sascha Hauer [this message]
2013-08-09 10:16   ` Baruch Siach

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=20130809085735.GD26614@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /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.