Re: [PATCH] net: fix checksum verification

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Aug 09, 2013 at 07:01:24AM +0300, Baruch Siach wrote:
> Checksum verification on data including its own checksum (as is the case with
> IP headers) should give zero. Current code works well for the correct checksum
> case, but fails to identify (most) errors.
> 
> Signed-off-by: Baruch Siach <baruch@xxxxxxxxxx>
> ---
> 
> Untested. From code inspection only.
> 
>  net/net.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/net.c b/net/net.c
> index 0bd9084..bd7a578 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) == 0;

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;

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?

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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux