summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-03-16 00:09:31 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-03-16 00:09:31 +0000
commitacaab5c7cb917271d8f1119b8f939b88c86b80fd (patch)
treef447dacc2f57442d1df8ee855c2f711bc39260f5
parente7fa349439a23696eac35a4a74c27f1357ec6a97 (diff)
downloadnuttx-acaab5c7cb917271d8f1119b8f939b88c86b80fd.tar.gz
nuttx-acaab5c7cb917271d8f1119b8f939b88c86b80fd.tar.bz2
nuttx-acaab5c7cb917271d8f1119b8f939b88c86b80fd.zip
Fix calculation of checksum on outgoing ping responses
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1617 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/ChangeLog1
-rw-r--r--nuttx/Documentation/NuttX.html1
-rw-r--r--nuttx/include/net/uip/uip-arch.h2
-rw-r--r--nuttx/include/net/uip/uip-icmp.h2
-rw-r--r--nuttx/net/uip/uip_chksum.c6
-rw-r--r--nuttx/net/uip/uip_icmpinput.c20
-rw-r--r--nuttx/net/uip/uip_icmpsend.c2
7 files changed, 19 insertions, 15 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 746be8fb7..2245ad3a0 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -657,3 +657,4 @@
* examples/nsh: A debug option was left on that can (and does) cause
infinite loops and stack overflows.
+ * net/uip: Correct calculation of checksum on ICMP ping response.
diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html
index 7d565de74..ff04cad7f 100644
--- a/nuttx/Documentation/NuttX.html
+++ b/nuttx/Documentation/NuttX.html
@@ -1348,6 +1348,7 @@ nuttx-0.4.4 2009-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
* examples/nsh: A debug option was left on that can (and does) cause
infinite loops and stack overflows.
+ * net/uip: Correct calculation of checksum on ICMP ping response.
pascal-0.1.3 2009-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
diff --git a/nuttx/include/net/uip/uip-arch.h b/nuttx/include/net/uip/uip-arch.h
index 80e574efa..3409f1416 100644
--- a/nuttx/include/net/uip/uip-arch.h
+++ b/nuttx/include/net/uip/uip-arch.h
@@ -366,7 +366,7 @@ extern uint16 uip_ipchksum(struct uip_driver_s *dev);
extern uint16 uip_tcpchksum(struct uip_driver_s *dev);
extern uint16 uip_udpchksum(struct uip_driver_s *dev);
-extern uint16 uip_icmpchksum(struct uip_driver_s *dev);
+extern uint16 uip_icmpchksum(struct uip_driver_s *dev, int len);
#endif /* __UIP_ARCH_H */
diff --git a/nuttx/include/net/uip/uip-icmp.h b/nuttx/include/net/uip/uip-icmp.h
index 67d6941d3..e6b52b07c 100644
--- a/nuttx/include/net/uip/uip-icmp.h
+++ b/nuttx/include/net/uip/uip-icmp.h
@@ -2,7 +2,7 @@
* net/uip/uip-icmp.h
* Header file for the uIP ICMP stack.
*
- * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* This logic was leveraged from uIP which also has a BSD-style license:
diff --git a/nuttx/net/uip/uip_chksum.c b/nuttx/net/uip/uip_chksum.c
index defb5b479..45e8894b3 100644
--- a/nuttx/net/uip/uip_chksum.c
+++ b/nuttx/net/uip/uip_chksum.c
@@ -229,11 +229,11 @@ uint16 uip_udpchksum(struct uip_driver_s *dev)
/* Calculate the checksum of the ICMP message */
-#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING)
-uint16 uip_icmpchksum(struct uip_driver_s *dev)
+#if defined(CONFIG_NET_ICMP)
+uint16 uip_icmpchksum(struct uip_driver_s *dev, int len)
{
struct uip_icmpip_hdr *picmp = ICMPBUF;
- return uip_chksum((uint16*)&picmp->type, dev->d_sndlen);
+ return uip_chksum((uint16*)&picmp->type, len);
}
#endif
diff --git a/nuttx/net/uip/uip_icmpinput.c b/nuttx/net/uip/uip_icmpinput.c
index 52352c700..f2edcbcb5 100644
--- a/nuttx/net/uip/uip_icmpinput.c
+++ b/nuttx/net/uip/uip_icmpinput.c
@@ -131,22 +131,24 @@ void uip_icmpinput(struct uip_driver_s *dev)
}
#endif
- picmp->type = ICMP_ECHO_REPLY;
+ /* Change the ICMP type */
- if (picmp->icmpchksum >= HTONS(0xffff - (ICMP_ECHO_REPLY << 8)))
- {
- picmp->icmpchksum += HTONS(ICMP_ECHO_REPLY << 8) + 1;
- }
- else
- {
- picmp->icmpchksum += HTONS(ICMP_ECHO_REPLY << 8);
- }
+ picmp->type = ICMP_ECHO_REPLY;
/* Swap IP addresses. */
uiphdr_ipaddr_copy(picmp->destipaddr, picmp->srcipaddr);
uiphdr_ipaddr_copy(picmp->srcipaddr, &dev->d_ipaddr);
+ /* Recalculate the ICMP checksum */
+
+ picmp->icmpchksum = 0;
+ picmp->icmpchksum = ~uip_icmpchksum(dev, (((uint16)picmp->len[0] << 8) | (uint16)picmp->len[1]) - UIP_IPH_LEN);
+ if (picmp->icmpchksum == 0)
+ {
+ picmp->icmpchksum = 0xffff;
+ }
+
nvdbg("Outgoing ICMP packet length: %d (%d)\n",
dev->d_len, (picmp->len[0] << 8) | picmp->len[1]);
diff --git a/nuttx/net/uip/uip_icmpsend.c b/nuttx/net/uip/uip_icmpsend.c
index 6acbf3176..0c3784e95 100644
--- a/nuttx/net/uip/uip_icmpsend.c
+++ b/nuttx/net/uip/uip_icmpsend.c
@@ -150,7 +150,7 @@ void uip_icmpsend(struct uip_driver_s *dev, uip_ipaddr_t *destaddr)
/* Calculate the ICMP checksum. */
picmp->icmpchksum = 0;
- picmp->icmpchksum = ~(uip_icmpchksum(dev));
+ picmp->icmpchksum = ~(uip_icmpchksum(dev, dev->d_sndlen));
if (picmp->icmpchksum == 0)
{
picmp->icmpchksum = 0xffff;