summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-01-14 18:34:28 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-01-14 18:34:28 -0600
commit647a5c02c6f0d2871c0308c6f2e5916110136792 (patch)
tree15f73da4bad73c9ec01612f7f3f99ad1eb4f9322
parente24204e4982296058d0185c2a52f89af18a5142d (diff)
downloadpx4-nuttx-647a5c02c6f0d2871c0308c6f2e5916110136792.tar.gz
px4-nuttx-647a5c02c6f0d2871c0308c6f2e5916110136792.tar.bz2
px4-nuttx-647a5c02c6f0d2871c0308c6f2e5916110136792.zip
Networking: A few more IPv6-related fixes
-rw-r--r--nuttx/include/nuttx/net/ip.h26
-rw-r--r--nuttx/net/icmpv6/icmpv6_input.c3
-rw-r--r--nuttx/net/udp/udp_send.c5
-rw-r--r--nuttx/net/utils/net_chksum.c40
-rw-r--r--nuttx/net/utils/utils.h16
5 files changed, 58 insertions, 32 deletions
diff --git a/nuttx/include/nuttx/net/ip.h b/nuttx/include/nuttx/net/ip.h
index f3a16efb7..d2deb8f41 100644
--- a/nuttx/include/nuttx/net/ip.h
+++ b/nuttx/include/nuttx/net/ip.h
@@ -257,17 +257,23 @@ struct net_iphdr_s
* addr2 The second IP address.
*/
+#define net_ipv6addr_cmp(addr1, addr2) \
+ (addr1 == addr2)
+#define net_ipv6addr_hdrcmp(addr1, addr2) \
+ net_ipv6addr_cmp(net_ip4addr_conv32(addr1), net_ip4addr_conv32(addr2))
+
+#define net_ipv4addr_cmp(addr1, addr2) \
+ (memcmp(&addr1, &addr2, sizeof(net_ip6addr_t)) == 0)
+#define net_ipv4addr_hdrcmp(addr1, addr2) \
+ net_ipv4addr_cmp(addr1, addr2)
+
#ifndef CONFIG_NET_IPv6
-# define net_ipaddr_cmp(addr1, addr2) \
- (addr1 == addr2)
-# define net_ipaddr_hdrcmp(addr1, addr2) \
- net_ipaddr_cmp(net_ip4addr_conv32(addr1), net_ip4addr_conv32(addr2))
-#else /* !CONFIG_NET_IPv6 */
-# define net_ipaddr_cmp(addr1, addr2) \
- (memcmp(&addr1, &addr2, sizeof(net_ip6addr_t)) == 0)
-# define net_ipaddr_hdrcmp(addr1, addr2) \
- net_ipaddr_cmp(addr, addr2)
-#endif /* !CONFIG_NET_IPv6 */
+# define net_ipaddr_cmp(addr1, addr2) net_ipv6addr_cmp(addr1, addr2)
+# define net_ipaddr_hdrcmp(addr1, addr2) net_ipv6addr_hdrcmp(addr1, addr2)
+#else
+# define net_ipaddr_cmp(addr1, addr2) net_ipv4addr_cmp(addr1, addr2)
+# define net_ipaddr_hdrcmp(addr1, addr2) net_ipv4addr_hdrcmp(addr1, addr2
+#endif
/* Compare two IP addresses under a netmask. The mask is used to mask
* out the bits that are to be compared: Buts within the mask much
diff --git a/nuttx/net/icmpv6/icmpv6_input.c b/nuttx/net/icmpv6/icmpv6_input.c
index f93dee7f3..1bc1e4bc3 100644
--- a/nuttx/net/icmpv6/icmpv6_input.c
+++ b/nuttx/net/icmpv6/icmpv6_input.c
@@ -128,7 +128,8 @@ void icmpv6_input(FAR struct net_driver_s *dev)
{
/* Save the sender's address in our neighbor list. */
- net_neighbor_add(picmp->srcipaddr, &(picmp->options[2]));
+ net_neighbor_add(picmp->srcipaddr,
+ (FAR struct net_neighbor_addr_s *)&(picmp->options[2]));
}
/* We should now send a neighbor advertisement back to where the
diff --git a/nuttx/net/udp/udp_send.c b/nuttx/net/udp/udp_send.c
index acb7bddb6..658e826ba 100644
--- a/nuttx/net/udp/udp_send.c
+++ b/nuttx/net/udp/udp_send.c
@@ -44,6 +44,7 @@
#include <nuttx/config.h>
#if defined(CONFIG_NET) && defined(CONFIG_NET_UDP)
+#include <string.h>
#include <debug.h>
#include <arpa/inet.h>
@@ -121,8 +122,8 @@ void udp_send(struct net_driver_s *dev, struct udp_conn_s *conn)
pudpbuf->flow = 0x00;
pudpbuf->len[0] = (dev->d_sndlen >> 8);
pudpbuf->len[1] = (dev->d_sndlen & 0xff);
- pudpbuf->nexthdr = IP_PROTO_UDP;
- pudpbuf->hoplimit = conn->ttl;
+ pudpbuf->proto = IP_PROTO_UDP;
+ pudpbuf->ttl = conn->ttl;
net_ipaddr_copy(pudpbuf->srcipaddr, &dev->d_ipaddr);
net_ipaddr_copy(pudpbuf->destipaddr, &conn->ripaddr);
diff --git a/nuttx/net/utils/net_chksum.c b/nuttx/net/utils/net_chksum.c
index f2183665e..b77e10569 100644
--- a/nuttx/net/utils/net_chksum.c
+++ b/nuttx/net/utils/net_chksum.c
@@ -54,8 +54,9 @@
* Pre-processor Definitions
****************************************************************************/
-#define BUF ((struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
-#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
+#define BUF ((struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
+#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
+#define ICMPv6BUF ((struct icmp_ipv6hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Data
@@ -114,7 +115,8 @@ static uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len)
****************************************************************************/
#if !CONFIG_NET_ARCH_CHKSUM
-static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
+static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev,
+ uint8_t proto)
{
FAR struct net_iphdr_s *pbuf = BUF;
uint16_t upper_layer_len;
@@ -152,19 +154,6 @@ static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
#endif /* CONFIG_NET_ARCH_CHKSUM */
/****************************************************************************
- * Name: icmp_6chksum
- ****************************************************************************/
-
-#if !CONFIG_NET_ARCH_CHKSUM
-#ifdef CONFIG_NET_IPv6
-static uint16_t icmp_6chksum(FAR struct net_driver_s *dev)
-{
- return upper_layer_chksum(dev, IP_PROTO_ICMP6);
-}
-#endif /* CONFIG_NET_IPv6 */
-#endif /* CONFIG_NET_ARCH_CHKSUM */
-
-/****************************************************************************
* Name: net_carry32
*
* Description:
@@ -369,9 +358,24 @@ uint16_t udp_chksum(FAR struct net_driver_s *dev)
#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING)
uint16_t icmp_chksum(FAR struct net_driver_s *dev, int len)
{
- FAR struct icmp_iphdr_s *picmp = ICMPBUF;
- return net_chksum((uint16_t*)&picmp->type, len);
+ FAR struct icmp_iphdr_s *icmp = ICMPBUF;
+ return net_chksum((uint16_t*)&icmp->type, len);
}
#endif /* CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING */
+/****************************************************************************
+ * Name: icmpv6_chksum
+ *
+ * Description:
+ * Calculate the checksum of the ICMPv6 message
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_ICMPv6
+uint16_t icmpv6_chksum(FAR struct net_driver_s *dev)
+{
+ return upper_layer_chksum(dev, IP_PROTO_ICMP6);
+}
+#endif
+
#endif /* CONFIG_NET */
diff --git a/nuttx/net/utils/utils.h b/nuttx/net/utils/utils.h
index 6ecb47ce6..76401a27a 100644
--- a/nuttx/net/utils/utils.h
+++ b/nuttx/net/utils/utils.h
@@ -175,11 +175,25 @@ uint16_t udp_chksum(FAR struct net_driver_s *dev);
* Name: icmp_chksum
*
* Description:
- * Calculate the checksum of the ICMP message
+ * Calculate the checksum of the IPv4 ICMP message
*
****************************************************************************/
+#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING)
uint16_t icmp_chksum(FAR struct net_driver_s *dev, int len);
+#endif
+
+/****************************************************************************
+ * Name: icmpv6_chksum
+ *
+ * Description:
+ * Calculate the checksum of the ICMPv6 message
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_ICMPv6
+uint16_t icmpv6_chksum(FAR struct net_driver_s *dev);
+#endif
#undef EXTERN
#ifdef __cplusplus