aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipx/af_ipx.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2006-11-03 03:28:23 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-11-05 17:11:25 -0500
commit02e60370d4dac83f22d5ae75d5512bcb9a3f24b7 (patch)
tree3952d784c9d7c061a5ff7c0e23277783f10e55d2 /net/ipx/af_ipx.c
parent4833ed094097323f5f219820f6ebdc8dd66f501f (diff)
[IPX]: Annotate and fix IPX checksum
Calculation of IPX checksum got buggered about 2.4.0. The old variant mangled the packet; that got fixed, but calculation itself got buggered. Restored the correct logics, fixed a subtle breakage we used to have even back then: if the sum is 0 mod 0xffff, we want to return 0, not 0xffff. The latter has special meaning for IPX (cheksum disabled). Observation (and obvious fix) nicked from history of FreeBSD ipx_cksum.c... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipx/af_ipx.c')
-rw-r--r--net/ipx/af_ipx.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/net/ipx/af_ipx.c b/net/ipx/af_ipx.c
index c272a38af325..76c661566dfd 100644
--- a/net/ipx/af_ipx.c
+++ b/net/ipx/af_ipx.c
@@ -1234,27 +1234,27 @@ static int ipxitf_ioctl(unsigned int cmd, void __user *arg)
1234/* Note: We assume ipx_tctrl==0 and htons(length)==ipx_pktsize */ 1234/* Note: We assume ipx_tctrl==0 and htons(length)==ipx_pktsize */
1235/* This functions should *not* mess with packet contents */ 1235/* This functions should *not* mess with packet contents */
1236 1236
1237__u16 ipx_cksum(struct ipxhdr *packet, int length) 1237__be16 ipx_cksum(struct ipxhdr *packet, int length)
1238{ 1238{
1239 /* 1239 /*
1240 * NOTE: sum is a net byte order quantity, which optimizes the 1240 * NOTE: sum is a net byte order quantity, which optimizes the
1241 * loop. This only works on big and little endian machines. (I 1241 * loop. This only works on big and little endian machines. (I
1242 * don't know of a machine that isn't.) 1242 * don't know of a machine that isn't.)
1243 */ 1243 */
1244 /* start at ipx_dest - We skip the checksum field and start with 1244 /* handle the first 3 words separately; checksum should be skipped
1245 * ipx_type before the loop, not considering ipx_tctrl in the calc */ 1245 * and ipx_tctrl masked out */
1246 __u16 *p = (__u16 *)&packet->ipx_dest; 1246 __u16 *p = (__u16 *)packet;
1247 __u32 i = (length >> 1) - 1; /* Number of complete words */ 1247 __u32 sum = p[1] + (p[2] & (__force u16)htons(0x00ff));
1248 __u32 sum = packet->ipx_type << sizeof(packet->ipx_tctrl); 1248 __u32 i = (length >> 1) - 3; /* Number of remaining complete words */
1249 1249
1250 /* Loop through all complete words except the checksum field, 1250 /* Loop through them */
1251 * ipx_type (accounted above) and ipx_tctrl (not used in the cksum) */ 1251 p += 3;
1252 while (--i) 1252 while (i--)
1253 sum += *p++; 1253 sum += *p++;
1254 1254
1255 /* Add on the last part word if it exists */ 1255 /* Add on the last part word if it exists */
1256 if (packet->ipx_pktsize & htons(1)) 1256 if (packet->ipx_pktsize & htons(1))
1257 sum += ntohs(0xff00) & *p; 1257 sum += (__force u16)htons(0xff00) & *p;
1258 1258
1259 /* Do final fixup */ 1259 /* Do final fixup */
1260 sum = (sum & 0xffff) + (sum >> 16); 1260 sum = (sum & 0xffff) + (sum >> 16);
@@ -1263,7 +1263,14 @@ __u16 ipx_cksum(struct ipxhdr *packet, int length)
1263 if (sum >= 0x10000) 1263 if (sum >= 0x10000)
1264 sum++; 1264 sum++;
1265 1265
1266 return ~sum; 1266 /*
1267 * Leave 0 alone; we don't want 0xffff here. Note that we can't get
1268 * here with 0x10000, so this check is the same as ((__u16)sum)
1269 */
1270 if (sum)
1271 sum = ~sum;
1272
1273 return (__force __be16)sum;
1267} 1274}
1268 1275
1269const char *ipx_frame_name(__be16 frame) 1276const char *ipx_frame_name(__be16 frame)