Clean a few more IPv6 compilation issues; Add implementation of net_ipv6_maskcmp()

This commit is contained in:
Gregory Nutt 2015-01-15 15:55:52 -06:00
parent d3b4416f00
commit 5b45605991
8 changed files with 146 additions and 10 deletions

View File

@ -279,9 +279,9 @@ struct net_ipv6hdr_s
*
* Example:
*
* net_ipaddr_t ipaddr1;
* net_ipaddr_t ipaddr2;
* net_ipaddr_t mask;
* in_addr_t ipaddr1;
* in_addr_t ipaddr2;
* in_addr_t mask;
*
* net_ipaddr(&mask, 255,255,255,0);
* net_ipaddr(&ipaddr1, 192,16,1,2);
@ -304,8 +304,9 @@ struct net_ipv6hdr_s
# define net_ipaddr_maskcmp(a,b,m) net_ipv4addr_maskcmp(a,b,m)
#else
bool net_ipv6addr_maskcmp(net_ipaddr_t addr1, net_ipaddr_t addr2,
net_ipaddr_t mask);
bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
const net_ipv6addr_t addr2,
const net_ipv6addr_t mask);
# define net_ipaddr_maskcmp(a,b,m) net_ipv6addr_maskcmp(a,b,m)
#endif

View File

@ -103,7 +103,7 @@
# define IPv4TCP_HDRLEN (TCP_HDRLEN + IPv4_HDRLEN) /* Size of IPv4 + TCP header */
#endif
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
# define IPv6TCP_HDRLEN (TCP_HDRLEN + IPv6_HDRLEN) /* Size of IPv4 + TCP header */
#endif

View File

@ -69,7 +69,7 @@
#endif
#ifdef CONFIG_NET_IPv6
# define IPv6UDP_HDRLEN (UDP_HDRLEN + IPv4_HDRLEN) /* Size of IPv6 + UDP headers */
# define IPv6UDP_HDRLEN (UDP_HDRLEN + IPv6_HDRLEN) /* Size of IPv6 + UDP headers */
#endif
/****************************************************************************

View File

@ -198,7 +198,7 @@ int ipv6_input(FAR struct net_driver_s *dev)
if (pbuf->proto == IP_PROTO_UDP &&
net_ipv6addr_cmp(pbuf->destipaddr, g_alloneaddr))
{
return udp_input(dev);
return udp_ipv6_input(dev);
}
/* In most other cases, the device must be assigned a non-zero IP

View File

@ -101,10 +101,18 @@ void tcp_poll(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
if ((conn->tcpstateflags & TCP_STATE_MASK) == TCP_ESTABLISHED)
{
/* Set up for the callback */
/* Set up for the callback. We can't know in advance if the application
* is going to send a IPv4 or an IPv6 packet, so this setup may not
* actually be used.
*/
#if defined(CONFIG_NET_IPv4)
dev->d_snddata = &dev->d_buf[IPv4TCP_HDRLEN + NET_LL_HDRLEN(dev)];
dev->d_appdata = &dev->d_buf[IPv4TCP_HDRLEN + NET_LL_HDRLEN(dev)];
#else /* if defined(CONFIG_NET_IPv6) */
dev->d_snddata = &dev->d_buf[IPv6TCP_HDRLEN + NET_LL_HDRLEN(dev)];
dev->d_appdata = &dev->d_buf[IPv6TCP_HDRLEN + NET_LL_HDRLEN(dev)];
#endif
dev->d_len = 0;
dev->d_sndlen = 0;

View File

@ -98,10 +98,18 @@ void udp_poll(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
if (conn->lport != 0)
{
/* Set-up for the application callback */
/* Set up for the callback. We can't know in advance if the application
* is going to send a IPv4 or an IPv6 packet, so this setup may not
* actually be used.
*/
#if defined(CONFIG_NET_IPv4)
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPv4UDP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPv4UDP_HDRLEN];
#else /* if defined(CONFIG_NET_IPv6) */
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPv6UDP_HDRLEN];
dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPv6UDP_HDRLEN];
#endif
dev->d_len = 0;
dev->d_sndlen = 0;

View File

@ -33,9 +33,17 @@
#
############################################################################
# Common utilities
NET_CSRCS += net_dsec2tick.c net_dsec2timeval.c net_timeval2dsec.c
NET_CSRCS += net_chksum.c
# IPv6 utilities
ifeq ($(CONFIG_NET_IPv6),y)
NET_CSRCS += net_ipv6_maskcmp.c
endif
# Non-interrupt level support required?
ifeq ($(CONFIG_NET_NOINTS),y)

View File

@ -0,0 +1,111 @@
/****************************************************************************
* net/utils/net_ipv6_maskcmp.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/clock.h>
#include <nuttx/net/ip.h>
#include "utils/utils.h"
#ifdef CONFIG_NET_IPv6
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Function: net_timeval2dsec
*
* Description:
* 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
* match exactly; bits outside if the mask are ignored.
*
* Example:
*
* net_ipv6addr_t ipaddr1;
* net_ipv6addr_t ipaddr2;
* net_ipv6addr_t mask;
*
* net_ipv6addr(&mask, 255,255,255,0);
* net_ipv6addr(&ipaddr1, 192,16,1,2);
* net_iv6paddr(&ipaddr2, 192,16,1,3);
* if (net_ipv6addr_maskcmp(ipaddr1, ipaddr2, &mask))
* {
* printf("They are the same");
* }
*
* Parameters:
* addr1 - The first IP address.
* addr2 - The second IP address.
* mask - The netmask.
*
* Returned Value:
* True if the address under the mask are equal
*
****************************************************************************/
bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
const net_ipv6addr_t addr2,
const net_ipv6addr_t mask)
{
int i;
/* Start from the "bottom" where the addresses will most likely differ */
for (i = 7; i >= 0; i--)
{
/* Same? */
if ((addr1[i] & mask[i]) != (addr2[i] & mask[i]))
{
/* No.. the addresses are different */
return false;
}
}
/* The addresses are the same */
return true;
}
#endif /* CONFIG_NET_IPv6 */