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

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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;
@ -151,19 +153,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
*
@ -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 */

View File

@ -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