Networking: A few more IPv6-related fixes

This commit is contained in:
Gregory Nutt
2015-01-14 18:34:28 -06:00
parent cf9795e4df
commit a49f0231d2
5 changed files with 58 additions and 32 deletions
+16 -10
View File
@@ -257,17 +257,23 @@ struct net_iphdr_s
* addr2 The second IP address. * 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 #ifndef CONFIG_NET_IPv6
# define net_ipaddr_cmp(addr1, addr2) \ # define net_ipaddr_cmp(addr1, addr2) net_ipv6addr_cmp(addr1, addr2)
(addr1 == addr2) # define net_ipaddr_hdrcmp(addr1, addr2) net_ipv6addr_hdrcmp(addr1, addr2)
# define net_ipaddr_hdrcmp(addr1, addr2) \ #else
net_ipaddr_cmp(net_ip4addr_conv32(addr1), net_ip4addr_conv32(addr2)) # define net_ipaddr_cmp(addr1, addr2) net_ipv4addr_cmp(addr1, addr2)
#else /* !CONFIG_NET_IPv6 */ # define net_ipaddr_hdrcmp(addr1, addr2) net_ipv4addr_hdrcmp(addr1, addr2
# define net_ipaddr_cmp(addr1, addr2) \ #endif
(memcmp(&addr1, &addr2, sizeof(net_ip6addr_t)) == 0)
# define net_ipaddr_hdrcmp(addr1, addr2) \
net_ipaddr_cmp(addr, addr2)
#endif /* !CONFIG_NET_IPv6 */
/* Compare two IP addresses under a netmask. The mask is used to mask /* 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 * out the bits that are to be compared: Buts within the mask much
+2 -1
View File
@@ -128,7 +128,8 @@ void icmpv6_input(FAR struct net_driver_s *dev)
{ {
/* Save the sender's address in our neighbor list. */ /* 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 /* We should now send a neighbor advertisement back to where the
+3 -2
View File
@@ -44,6 +44,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#if defined(CONFIG_NET) && defined(CONFIG_NET_UDP) #if defined(CONFIG_NET) && defined(CONFIG_NET_UDP)
#include <string.h>
#include <debug.h> #include <debug.h>
#include <arpa/inet.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->flow = 0x00;
pudpbuf->len[0] = (dev->d_sndlen >> 8); pudpbuf->len[0] = (dev->d_sndlen >> 8);
pudpbuf->len[1] = (dev->d_sndlen & 0xff); pudpbuf->len[1] = (dev->d_sndlen & 0xff);
pudpbuf->nexthdr = IP_PROTO_UDP; pudpbuf->proto = IP_PROTO_UDP;
pudpbuf->hoplimit = conn->ttl; pudpbuf->ttl = conn->ttl;
net_ipaddr_copy(pudpbuf->srcipaddr, &dev->d_ipaddr); net_ipaddr_copy(pudpbuf->srcipaddr, &dev->d_ipaddr);
net_ipaddr_copy(pudpbuf->destipaddr, &conn->ripaddr); net_ipaddr_copy(pudpbuf->destipaddr, &conn->ripaddr);
+22 -18
View File
@@ -54,8 +54,9 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define BUF ((struct net_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 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 * 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 #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; FAR struct net_iphdr_s *pbuf = BUF;
uint16_t upper_layer_len; uint16_t upper_layer_len;
@@ -151,19 +153,6 @@ static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
} }
#endif /* CONFIG_NET_ARCH_CHKSUM */ #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 * Name: net_carry32
* *
@@ -369,9 +358,24 @@ uint16_t udp_chksum(FAR struct net_driver_s *dev)
#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) #if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING)
uint16_t icmp_chksum(FAR struct net_driver_s *dev, int len) uint16_t icmp_chksum(FAR struct net_driver_s *dev, int len)
{ {
FAR struct icmp_iphdr_s *picmp = ICMPBUF; FAR struct icmp_iphdr_s *icmp = ICMPBUF;
return net_chksum((uint16_t*)&picmp->type, len); return net_chksum((uint16_t*)&icmp->type, len);
} }
#endif /* CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING */ #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 */ #endif /* CONFIG_NET */
+15 -1
View File
@@ -175,11 +175,25 @@ uint16_t udp_chksum(FAR struct net_driver_s *dev);
* Name: icmp_chksum * Name: icmp_chksum
* *
* Description: * 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); 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 #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus