Skip to contentSkip to conversation

Change the UDP Checksum code to work with ARM data alignment.

PATCH New Tom Evans 2 participants 2 messages Aug 26, 2008 1 message not in the archive Networking

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Tom Evans

author
#1 lore raw

PATCH 1/1 Change the UDP Checksum code to work with ARM data alignment.

Quoted 8 lines

From: Ben Warren <[email protected]>
Subject: Re: [U-Boot] ARM: net.c: UDP Checksum code
failing every packet
To: Tom Evans <[email protected]>
Cc: U-Boot <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Quoted 8 lines
Quoted 5 lines · Tom Evans
Quoted 1 line

Ben Warren wrote:

...
Besides which, I've never made a patch before, and couldn't find any instructions on how to do so.

There is good documentation out there, just not where you looked.

I followed Ben's instructions and here's the resulting patch.

I don't have any hardware that is supported in the current distribution, so I can't perform a full compile-run-test pass on this patch. I've run the changes on our modified u-boot setup and it works. I've also changed the distribution Makefile for our cross compiler, added "#define CONFIG_UDP_CHECKSUM 1" to cradle.h, done "make cradle_config ; make" without any errors.

---
  net/net.c |   12 +++++++-----
  1 files changed, 7 insertions(+), 5 deletions(-)
net/net.c +6 -4
index 313d5d8..c8cda77 100644
@@ -1494,10 +1494,12 @@ NetReceive(volatile uchar * inpkt, int len)
 
                         xsum  = ip->ip_p;
                         xsum += (ntohs(ip->udp_len));
-                       xsum += (ntohl(ip->ip_src) >> 16) & 0x0000ffff;
-                       xsum += (ntohl(ip->ip_src) >>  0) & 0x0000ffff;
-                       xsum += (ntohl(ip->ip_dst) >> 16) & 0x0000ffff;
-                       xsum += (ntohl(ip->ip_dst) >>  0) & 0x0000ffff;
+                       tmp = NetReadIP(&ip->ip_src);
+                       xsum += (ntohl(tmp) >> 16) & 0x0000ffff;
+                       xsum += (ntohl(tmp) >>  0) & 0x0000ffff;
+                       tmp = NetReadIP(&ip->ip_dst);
+                       xsum += (ntohl(tmp) >> 16) & 0x0000ffff;
+                       xsum += (ntohl(tmp) >>  0) & 0x0000ffff;
 
                         sumlen = ntohs(ip->udp_len);
                         sumptr = (ushort *) &(ip->udp_src);
@@ -1520,7 +1522,7 @@ NetReceive(volatile uchar * inpkt, int len)
                                 xsum = (xsum & 0x0000ffff) + ((xsum >> 
16) & 0x0000ffff);
                         }
                         if ((xsum != 0x00000000) && (xsum != 0x0000ffff)) {
-                               printf(" UDP wrong checksum %08lx %08x\n",
+                               printf("\nUDP wrong checksum %08lx %08x\n",
                                         xsum, ntohs(ip->udp_xsum));
                                 return;
                         }

--
1.5.5.1

Signature · 10 lines
===
Tom Evans      Tom.Evans at ceos.com.au
CEOS Pty Ltd   www.ceos.com.au
3/17 Burgundy St, Heidelberg,
Victoria 3084, Australia

Phone  (+61 3) 9458 4955
Direct         Unsupported
FAX    (+61 3) 9458 4966
Mobile         0405 776 431
#2 lore raw

PATCH 1/1 Change the UDP Checksum code to work with ARM data alignment.

Dear Tom Evans,

Quoted 2 lines · In message <[email protected]> you wrote:

I followed Ben's instructions and here's the resulting patch.

I'm sorry, but this patch is corrupted and cannot be applied.

net/net.c NetReceive(volatile uchar * inpkt, int len) · line 1500

Quoted 10 lines
net/net.c +0 -4
@@ -1494,10 +1494,12 @@ NetReceive(volatile uchar * inpkt, int len)
 
                         xsum  = ip->ip_p;
                         xsum += (ntohs(ip->udp_len));
-                       xsum += (ntohl(ip->ip_src) >> 16) & 0x0000ffff;
-                       xsum += (ntohl(ip->ip_src) >>  0) & 0x0000ffff;
-                       xsum += (ntohl(ip->ip_dst) >> 16) & 0x0000ffff;
-                       xsum += (ntohl(ip->ip_dst) >>  0) & 0x0000ffff;

In the original code, there were no spaces but TAB characters used for indentation. Someone (you?) must have changed this, and in a way that was not even noticed when you created the patch. This is very strange. Something is severely broken in your setup.

net/net.c NetReceive(volatile uchar * inpkt, int len) · line 1523

Quoted 12 lines
net/net.c +6 -0
+                       tmp = NetReadIP(&ip->ip_src);
+                       xsum += (ntohl(tmp) >> 16) & 0x0000ffff;
+                       xsum += (ntohl(tmp) >>  0) & 0x0000ffff;
+                       tmp = NetReadIP(&ip->ip_dst);
+                       xsum += (ntohl(tmp) >> 16) & 0x0000ffff;
+                       xsum += (ntohl(tmp) >>  0) & 0x0000ffff;
 
                         sumlen = ntohs(ip->udp_len);
                         sumptr = (ushort *) &(ip->udp_src);
@@ -1520,7 +1522,7 @@ NetReceive(volatile uchar * inpkt, int len)
                                 xsum = (xsum & 0x0000ffff) + ((xsum >> 
 16) & 0x0000ffff);

^^^^^^^^^^^^^^^^^^^^

Here your mailer wrapped long lines, which also makes the patch useless.

Please fix and resubmit.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Fascinating, a totally parochial attitude.
	-- Spock, "Metamorphosis", stardate 3219.8