mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] net: fix checksum verification
@ 2013-08-11  4:35 Baruch Siach
  2013-08-12  5:59 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Baruch Siach @ 2013-08-11  4:35 UTC (permalink / raw)
  To: barebox

Checksum calculation on data including its own checksum (as is the case with
IP headers) should give 0xffff before bit flipping. Current code works well
for the correct checksum case, but fails to identify errors.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
Untested.

v2: net_checksum() doesn't flip bits. Fix accordingly.

 net/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/net.c b/net/net.c
index 0bd9084..058a4d3 100644
--- a/net/net.c
+++ b/net/net.c
@@ -41,7 +41,7 @@ static unsigned int net_ip_id;
 
 int net_checksum_ok(unsigned char *ptr, int len)
 {
-	return net_checksum(ptr, len) + 1;
+	return net_checksum(ptr, len) == 0xffff;
 }
 
 uint16_t net_checksum(unsigned char *ptr, int len)
-- 
1.8.4.rc1


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

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

* Re: [PATCH v2] net: fix checksum verification
  2013-08-11  4:35 [PATCH v2] net: fix checksum verification Baruch Siach
@ 2013-08-12  5:59 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2013-08-12  5:59 UTC (permalink / raw)
  To: Baruch Siach; +Cc: barebox

On Sun, Aug 11, 2013 at 07:35:45AM +0300, Baruch Siach wrote:
> Checksum calculation on data including its own checksum (as is the case with
> IP headers) should give 0xffff before bit flipping. Current code works well
> for the correct checksum case, but fails to identify errors.
> 
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>

Applied, thanks

Sascha

> ---
> Untested.
> 
> v2: net_checksum() doesn't flip bits. Fix accordingly.
> 
>  net/net.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/net.c b/net/net.c
> index 0bd9084..058a4d3 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -41,7 +41,7 @@ static unsigned int net_ip_id;
>  
>  int net_checksum_ok(unsigned char *ptr, int len)
>  {
> -	return net_checksum(ptr, len) + 1;
> +	return net_checksum(ptr, len) == 0xffff;
>  }
>  
>  uint16_t net_checksum(unsigned char *ptr, int len)
> -- 
> 1.8.4.rc1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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

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

end of thread, other threads:[~2013-08-12  5:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-11  4:35 [PATCH v2] net: fix checksum verification Baruch Siach
2013-08-12  5:59 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox