aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipx/af_ipx.c
diff options
context:
space:
mode:
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)