2007-11-07 19:54:35 +01:00
|
|
|
/****************************************************************************
|
2015-01-15 15:03:56 +01:00
|
|
|
* net/devif/ipv6_input.c
|
|
|
|
* Device driver IPv6 packet receipt interface
|
2007-11-07 19:54:35 +01:00
|
|
|
*
|
2017-01-18 14:32:27 +01:00
|
|
|
* Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved.
|
2012-02-18 23:09:09 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-11-07 19:54:35 +01:00
|
|
|
*
|
|
|
|
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
|
|
|
|
*
|
|
|
|
* uIP is an implementation of the TCP/IP protocol stack intended for
|
|
|
|
* small 8-bit and 16-bit microcontrollers.
|
|
|
|
*
|
|
|
|
* uIP provides the necessary protocols for Internet communication,
|
|
|
|
* with a very small code footprint and RAM requirements - the uIP
|
|
|
|
* code size is on the order of a few kilobytes and RAM usage is on
|
|
|
|
* the order of a few hundred bytes.
|
|
|
|
*
|
|
|
|
* Original author Adam Dunkels <adam@dunkels.com>
|
|
|
|
* Copyright () 2001-2003, Adam Dunkels.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* uIP is a small implementation of the IP, UDP and TCP protocols (as
|
|
|
|
* well as some basic ICMP stuff). The implementation couples the IP,
|
|
|
|
* UDP, TCP and the application layers very tightly. To keep the size
|
|
|
|
* of the compiled code down, this code frequently uses the goto
|
2015-01-15 15:03:56 +01:00
|
|
|
* statement. While it would be possible to break the ipv6_input()
|
2007-11-07 19:54:35 +01:00
|
|
|
* function into many smaller functions, this would increase the code
|
|
|
|
* size because of the overhead of parameter passing and the fact that
|
2014-06-25 02:12:49 +02:00
|
|
|
* the optimizer would not be as efficient.
|
2007-11-07 19:54:35 +01:00
|
|
|
*
|
|
|
|
* The principle is that we have a small buffer, called the d_buf,
|
|
|
|
* in which the device driver puts an incoming packet. The TCP/IP
|
|
|
|
* stack parses the headers in the packet, and calls the
|
|
|
|
* application. If the remote host has sent data to the application,
|
|
|
|
* this data is present in the d_buf and the application read the
|
|
|
|
* data from there. It is up to the application to put this data into
|
|
|
|
* a byte stream if needed. The application will not be fed with data
|
|
|
|
* that is out of sequence.
|
|
|
|
*
|
2014-04-12 20:13:01 +02:00
|
|
|
* If the application wishes to send data to the peer, it should put
|
2007-11-07 19:54:35 +01:00
|
|
|
* its data into the d_buf. The d_appdata pointer points to the
|
|
|
|
* first available byte. The TCP/IP stack will calculate the
|
|
|
|
* checksums, and fill in the necessary header fields and finally send
|
|
|
|
* the packet back to the peer.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2015-01-15 15:03:56 +01:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2007-11-07 19:54:35 +01:00
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
2009-12-15 15:53:45 +01:00
|
|
|
#include <stdint.h>
|
2007-11-07 19:54:35 +01:00
|
|
|
#include <debug.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-01-24 14:29:43 +01:00
|
|
|
#include <net/if.h>
|
|
|
|
|
2014-06-24 16:53:28 +02:00
|
|
|
#include <nuttx/net/netconfig.h>
|
2014-06-24 17:28:44 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
2014-06-26 17:32:39 +02:00
|
|
|
#include <nuttx/net/netstats.h>
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <nuttx/net/ip.h>
|
2007-11-07 19:54:35 +01:00
|
|
|
|
2015-01-17 16:27:05 +01:00
|
|
|
#include "neighbor/neighbor.h"
|
2014-06-25 02:12:49 +02:00
|
|
|
#include "tcp/tcp.h"
|
|
|
|
#include "udp/udp.h"
|
2017-04-02 20:01:04 +02:00
|
|
|
#include "sixlowpan/sixlowpan.h"
|
2014-06-25 18:34:52 +02:00
|
|
|
#include "pkt/pkt.h"
|
2015-01-15 15:03:56 +01:00
|
|
|
#include "icmpv6/icmpv6.h"
|
|
|
|
|
2017-06-28 16:13:57 +02:00
|
|
|
#include "netdev/netdev.h"
|
2017-07-08 02:45:58 +02:00
|
|
|
#include "ipforward/ipforward.h"
|
2015-01-15 15:03:56 +01:00
|
|
|
#include "devif/devif.h"
|
2007-11-07 19:54:35 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2009-12-15 15:53:45 +01:00
|
|
|
* Pre-processor Definitions
|
2007-11-07 19:54:35 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-07-06 21:04:27 +02:00
|
|
|
/* Macros */
|
2007-11-07 19:54:35 +01:00
|
|
|
|
2015-01-19 20:21:26 +01:00
|
|
|
#define IPv6BUF ((FAR struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
|
2007-11-07 19:54:35 +01:00
|
|
|
|
2017-06-28 16:13:57 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: check_dev_destipaddr
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if the destination address in the IPv6 is destined for the
|
|
|
|
* provided network device.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 1 - This packet is destined for this network device
|
|
|
|
* 0 - This packet is NOT destined for this network device
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_MULTINIC
|
2017-06-28 23:16:15 +02:00
|
|
|
static int check_dev_destipaddr(FAR struct net_driver_s *dev, FAR void *arg)
|
2017-06-28 16:13:57 +02:00
|
|
|
{
|
|
|
|
FAR struct ipv6_hdr_s *ipv6 = (FAR struct ipv6_hdr_s *)arg;
|
|
|
|
|
|
|
|
/* Check if the IPv6 destination address matches the IPv6 address assigned
|
|
|
|
* to this device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (net_ipv6addr_cmp(ipv6->destipaddr, dev->d_ipv6addr))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No match, return 0 to keep searching */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: check_destipaddr
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if the destination address in the IPv6 is destined for us. This
|
|
|
|
* is typically just a comparison the of the IPv6 destination address in
|
|
|
|
* the IPv6 packet with the IPv6 address assigned to the receiving device.
|
|
|
|
*
|
2017-06-28 23:39:21 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* dev - The device on which the packet was received and which contains
|
|
|
|
* the IPv6 packet.
|
|
|
|
* ipv6 - A convenience pointer to the IPv6 header in within the IPv6
|
|
|
|
* packet
|
|
|
|
*
|
2017-06-28 16:13:57 +02:00
|
|
|
* Returned Value:
|
|
|
|
* true - This packet is destined for us
|
|
|
|
* false - This packet is NOT destined for us and may need to be forwarded.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static bool check_destipaddr(FAR struct net_driver_s *dev,
|
|
|
|
FAR struct ipv6_hdr_s *ipv6)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_NETDEV_MULTINIC
|
|
|
|
int ret;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* For IPv6, packet reception is a little trickier as we need to make sure
|
|
|
|
* that we listen to certain multicast addresses (all hosts multicast
|
|
|
|
* address, and the solicited-node multicast address) as well. However,
|
|
|
|
* we will cheat here and accept all multicast packets that are sent to
|
|
|
|
* the ff02::/16 addresses.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ipv6->destipaddr[0] == HTONS(0xff02))
|
|
|
|
{
|
2017-07-06 15:26:01 +02:00
|
|
|
#ifdef CONFIG_NET_IPFORWARD_BROADCAST
|
|
|
|
/* Forward multicast packets */
|
|
|
|
|
|
|
|
ipv6_forward_broadcast(dev, ipv6);
|
|
|
|
#endif
|
2017-06-28 16:13:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_MULTINIC
|
|
|
|
/* We will also allow for a perverse case where we receive a packet
|
|
|
|
* addressed to us, but on a different device. Can that really happen?
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = netdev_foreach(check_dev_destipaddr, ipv6);
|
|
|
|
if (ret == 1)
|
|
|
|
{
|
|
|
|
/* The traversal of the network devices will return 0 if there is
|
|
|
|
* no network device with that address or 1 if there is a network
|
|
|
|
* device with such an address.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* There is only one network device. If this packet is addressed to us,
|
|
|
|
* then the IPv6 destination address must be the address of assigned to
|
|
|
|
* this device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (net_ipv6addr_cmp(ipv6->destipaddr, dev->d_ipv6addr))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-11-07 19:54:35 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: ipv6_input
|
2007-11-07 19:54:35 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2017-06-28 16:13:57 +02:00
|
|
|
* Receive an IPv6 packet from the network device. Verify and forward to
|
|
|
|
* L3 packet handling logic if the packet is destined for us.
|
2007-11-07 19:54:35 +01:00
|
|
|
*
|
2017-06-28 23:39:21 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* dev - The device on which the packet was received and which contains
|
|
|
|
* the IPv6 packet.
|
2013-09-06 17:18:07 +02:00
|
|
|
* Returned Value:
|
2017-06-28 23:39:21 +02:00
|
|
|
* OK - The packet was processed (or dropped) and can be discarded.
|
|
|
|
* ERROR - There is a matching connection, but could not dispatch the
|
|
|
|
* packet yet. Currently useful for UDP when a packet arrives
|
|
|
|
* before a recv call is in place.
|
2013-10-11 18:48:00 +02:00
|
|
|
*
|
2017-06-28 16:13:57 +02:00
|
|
|
* If this function returns to the network driver with dev->d_len > 0,
|
|
|
|
* that is an indication to the driver that there is an outgoing response
|
|
|
|
* to this input.
|
|
|
|
*
|
2007-11-07 19:54:35 +01:00
|
|
|
* Assumptions:
|
2017-07-01 16:39:39 +02:00
|
|
|
* The network is locked.
|
2007-11-07 19:54:35 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-15 15:03:56 +01:00
|
|
|
int ipv6_input(FAR struct net_driver_s *dev)
|
2007-11-07 19:54:35 +01:00
|
|
|
{
|
2015-01-19 20:21:26 +01:00
|
|
|
FAR struct ipv6_hdr_s *ipv6 = IPv6BUF;
|
2016-06-09 21:16:47 +02:00
|
|
|
uint16_t hdrlen;
|
2015-01-23 23:40:18 +01:00
|
|
|
uint16_t pktlen;
|
2017-06-29 16:16:46 +02:00
|
|
|
#ifdef CONFIG_NET_IPFORWARD
|
|
|
|
int ret;
|
|
|
|
#endif
|
2009-03-08 15:42:36 +01:00
|
|
|
|
2007-11-07 19:54:35 +01:00
|
|
|
/* This is where the input processing starts. */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_STATISTICS
|
2015-01-24 15:26:12 +01:00
|
|
|
g_netstats.ipv6.recv++;
|
2007-11-07 19:54:35 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Start of IP input header processing code. */
|
|
|
|
/* Check validity of the IP header. */
|
|
|
|
|
2015-01-19 20:21:26 +01:00
|
|
|
if ((ipv6->vtc & 0xf0) != 0x60)
|
2007-11-07 19:54:35 +01:00
|
|
|
{
|
|
|
|
/* IP version and header length. */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_STATISTICS
|
2015-01-24 15:26:12 +01:00
|
|
|
g_netstats.ipv6.drop++;
|
|
|
|
g_netstats.ipv6.vhlerr++;
|
2007-11-07 19:54:35 +01:00
|
|
|
#endif
|
2015-01-19 20:21:26 +01:00
|
|
|
|
2016-06-20 17:37:08 +02:00
|
|
|
nwarn("WARNING: Invalid IPv6 version: %d\n", ipv6->vtc >> 4);
|
2007-11-07 19:54:35 +01:00
|
|
|
goto drop;
|
|
|
|
}
|
2014-04-12 20:13:01 +02:00
|
|
|
|
2016-06-09 21:16:47 +02:00
|
|
|
/* Get the size of the packet minus the size of link layer header */
|
|
|
|
|
|
|
|
hdrlen = NET_LL_HDRLEN(dev);
|
|
|
|
if ((hdrlen + IPv6_HDRLEN) > dev->d_len)
|
|
|
|
{
|
2016-06-20 17:37:08 +02:00
|
|
|
nwarn("WARNING: Packet shorter than IPv6 header\n");
|
2016-06-09 21:16:47 +02:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->d_len -= hdrlen;
|
|
|
|
|
2007-11-07 19:54:35 +01:00
|
|
|
/* Check the size of the packet. If the size reported to us in d_len is
|
|
|
|
* smaller the size reported in the IP header, we assume that the packet
|
|
|
|
* has been corrupted in transit. If the size of d_len is larger than the
|
|
|
|
* size reported in the IP packet header, the packet has been padded and
|
|
|
|
* we set d_len to the correct value.
|
2015-01-15 15:03:56 +01:00
|
|
|
*
|
|
|
|
* The length reported in the IPv6 header is the length of the payload
|
2017-01-18 14:53:28 +01:00
|
|
|
* that follows the header. The device interface uses the d_len variable
|
|
|
|
* for holding the size of the entire packet, including the IP header but
|
|
|
|
* without the link layer header.
|
2012-02-18 23:09:09 +01:00
|
|
|
*/
|
2007-11-07 19:54:35 +01:00
|
|
|
|
2015-05-27 19:39:44 +02:00
|
|
|
pktlen = ((uint16_t)ipv6->len[0] << 8) + (uint16_t)ipv6->len[1] +
|
2017-01-18 10:57:15 +01:00
|
|
|
IPv6_HDRLEN;
|
2015-01-23 23:40:18 +01:00
|
|
|
|
|
|
|
if (pktlen <= dev->d_len)
|
2012-02-18 23:09:09 +01:00
|
|
|
{
|
2015-01-23 23:40:18 +01:00
|
|
|
dev->d_len = pktlen;
|
2007-11-07 19:54:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-20 17:37:08 +02:00
|
|
|
nwarn("WARNING: IP packet shorter than length in IP header\n");
|
2007-11-07 19:54:35 +01:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
2015-10-08 23:10:04 +02:00
|
|
|
/* If IP broadcast support is configured, we check for a broadcast
|
|
|
|
* UDP packet, which may be destined to us (even if there is no IP
|
|
|
|
* address yet assigned to the device as is the case when we are
|
|
|
|
* negotiating over DHCP for an address).
|
|
|
|
*/
|
2007-12-01 00:12:11 +01:00
|
|
|
|
2017-03-31 16:58:14 +02:00
|
|
|
#if defined(CONFIG_NET_BROADCAST) && defined(NET_UDP_HAVE_STACK)
|
2015-01-19 20:21:26 +01:00
|
|
|
if (ipv6->proto == IP_PROTO_UDP &&
|
|
|
|
net_ipv6addr_cmp(ipv6->destipaddr, g_ipv6_alloneaddr))
|
2007-12-01 00:12:11 +01:00
|
|
|
{
|
2017-07-06 15:26:01 +02:00
|
|
|
#ifdef CONFIG_NET_IPFORWARD_BROADCAST
|
|
|
|
/* Forward broadcast packets */
|
|
|
|
|
|
|
|
ipv6_forward_broadcast(dev, ipv6);
|
|
|
|
#endif
|
2015-01-15 22:55:52 +01:00
|
|
|
return udp_ipv6_input(dev);
|
2007-12-01 00:12:11 +01:00
|
|
|
}
|
|
|
|
|
2015-12-01 14:48:56 +01:00
|
|
|
/* In other cases, the device must be assigned a non-zero IP address. */
|
2007-12-01 00:12:11 +01:00
|
|
|
|
|
|
|
else
|
|
|
|
#endif
|
2015-01-15 15:03:56 +01:00
|
|
|
#ifdef CONFIG_NET_ICMPv6
|
2015-01-16 19:30:18 +01:00
|
|
|
if (net_ipv6addr_cmp(dev->d_ipv6addr, g_ipv6_allzeroaddr))
|
2007-11-07 19:54:35 +01:00
|
|
|
{
|
|
|
|
/* If we are configured to use ping IP address configuration and
|
|
|
|
* hasn't been assigned an IP address yet, we accept all ICMP
|
|
|
|
* packets.
|
|
|
|
*/
|
|
|
|
|
2016-06-20 17:37:08 +02:00
|
|
|
nwarn("WARNING: No IP address assigned\n");
|
2015-01-15 15:03:56 +01:00
|
|
|
goto drop;
|
2007-11-07 19:54:35 +01:00
|
|
|
}
|
2007-12-01 00:12:11 +01:00
|
|
|
|
2010-07-11 17:17:11 +02:00
|
|
|
/* Check if the packet is destined for out IP address */
|
2017-06-28 16:13:57 +02:00
|
|
|
|
2007-11-07 19:54:35 +01:00
|
|
|
else
|
2008-09-02 22:38:12 +02:00
|
|
|
#endif
|
2007-11-07 19:54:35 +01:00
|
|
|
{
|
2017-06-28 16:13:57 +02:00
|
|
|
/* Check if the packet is destined for us. */
|
2007-11-07 19:54:35 +01:00
|
|
|
|
2017-06-28 22:12:17 +02:00
|
|
|
if (!check_destipaddr(dev, ipv6))
|
2007-11-07 19:54:35 +01:00
|
|
|
{
|
2017-06-28 23:39:21 +02:00
|
|
|
#ifdef CONFIG_NET_IPFORWARD
|
|
|
|
/* Not destined for us, try to forward the packet */
|
|
|
|
|
2017-06-29 16:16:46 +02:00
|
|
|
ret = ipv6_forward(dev, ipv6);
|
2017-06-28 23:39:21 +02:00
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
/* The packet was forwarded. Return success; d_len will
|
|
|
|
* be set appropriately by the forwarding logic: Cleared
|
|
|
|
* if the packet is forward via anoother device or non-
|
|
|
|
* zero if it will be forwarded by the same device that
|
|
|
|
* it was received on.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Not destined for us and not forwardable... drop the packet. */
|
2017-06-28 22:12:17 +02:00
|
|
|
|
2017-07-04 20:05:21 +02:00
|
|
|
nwarn("WARNING: Not destined for us; not forwardable... Dropping!\n");
|
2007-11-07 19:54:35 +01:00
|
|
|
#ifdef CONFIG_NET_STATISTICS
|
2017-06-28 23:39:21 +02:00
|
|
|
g_netstats.ipv6.drop++;
|
2007-11-07 19:54:35 +01:00
|
|
|
#endif
|
2017-06-28 23:39:21 +02:00
|
|
|
goto drop;
|
|
|
|
}
|
2007-11-07 19:54:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-24 14:29:43 +01:00
|
|
|
/* Make sure that all packet processing logic knows that there is an IPv6
|
|
|
|
* packet in the device buffer.
|
2007-11-07 19:54:35 +01:00
|
|
|
*/
|
|
|
|
|
2015-01-24 14:29:43 +01:00
|
|
|
IFF_SET_IPv6(dev->d_flags);
|
|
|
|
|
|
|
|
/* Now process the incoming packet according to the protocol. */
|
|
|
|
|
2015-01-19 20:21:26 +01:00
|
|
|
switch (ipv6->proto)
|
2007-11-07 19:54:35 +01:00
|
|
|
{
|
2017-03-31 16:58:14 +02:00
|
|
|
#ifdef NET_TCP_HAVE_STACK
|
2014-07-05 00:38:51 +02:00
|
|
|
case IP_PROTO_TCP: /* TCP input */
|
2017-04-02 19:15:46 +02:00
|
|
|
/* Forward the IPv6 TCP packet */
|
|
|
|
|
2015-01-15 22:06:46 +01:00
|
|
|
tcp_ipv6_input(dev);
|
2017-04-02 19:15:46 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
2017-04-03 20:01:04 +02:00
|
|
|
/* TCP output comes through three different mechansims. Either from:
|
2017-04-02 19:15:46 +02:00
|
|
|
*
|
|
|
|
* 1. TCP socket output. For the case of TCP output to an
|
|
|
|
* IEEE802.15.4, the TCP output is caught in the socket
|
2017-06-19 00:00:08 +02:00
|
|
|
* send()/sendto() logic and and redirected to 6LoWPAN logic.
|
2017-04-03 20:01:04 +02:00
|
|
|
* 2. TCP output from the TCP state machine. That will occur
|
|
|
|
* during TCP packet processing by the TCP state meachine.
|
|
|
|
* 3. TCP output resulting from TX or timer polling
|
|
|
|
*
|
|
|
|
* Cases 2 is handled here. Logic here detected if (1) an attempt
|
|
|
|
* to return with d_len > 0 and (2) that the device is an
|
2017-06-19 00:00:08 +02:00
|
|
|
* IEEE802.15.4 MAC network driver. Under those conditions, 6LoWPAN
|
2017-04-03 20:01:04 +02:00
|
|
|
* logic will be called to create the IEEE80215.4 frames.
|
2017-04-02 19:15:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_MULTILINK
|
2017-04-03 20:01:04 +02:00
|
|
|
/* Handle the case where multiple link layer protocols are supported */
|
2017-04-02 19:15:46 +02:00
|
|
|
|
2017-04-03 20:01:04 +02:00
|
|
|
if (dev->d_len > 0 && dev->d_lltype == CONFIG_NET_6LOWPAN)
|
2017-04-02 19:15:46 +02:00
|
|
|
#else
|
2017-04-03 20:01:04 +02:00
|
|
|
if (dev->d_len > 0)
|
2007-11-22 19:36:46 +01:00
|
|
|
#endif
|
2017-04-03 20:01:04 +02:00
|
|
|
{
|
2017-06-19 00:00:08 +02:00
|
|
|
/* Let 6LoWPAN handle the TCP output */
|
2017-04-02 19:15:46 +02:00
|
|
|
|
2017-06-28 23:39:21 +02:00
|
|
|
sixlowpan_tcp_send(dev, dev, ipv6);
|
2017-04-02 19:15:46 +02:00
|
|
|
|
|
|
|
/* Drop the packet in the d_buf */
|
|
|
|
|
|
|
|
goto drop;
|
2017-04-03 20:01:04 +02:00
|
|
|
}
|
2017-04-02 19:15:46 +02:00
|
|
|
#endif /* CONFIG_NET_6LOWPAN */
|
|
|
|
break;
|
|
|
|
#endif /* NET_TCP_HAVE_STACK */
|
2007-11-07 19:54:35 +01:00
|
|
|
|
2017-03-31 16:58:14 +02:00
|
|
|
#ifdef NET_UDP_HAVE_STACK
|
2014-07-05 00:38:51 +02:00
|
|
|
case IP_PROTO_UDP: /* UDP input */
|
2017-04-02 19:15:46 +02:00
|
|
|
/* Forward the IPv6 UDP packet */
|
|
|
|
|
2015-01-15 22:06:46 +01:00
|
|
|
udp_ipv6_input(dev);
|
2007-11-07 19:54:35 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Check for ICMP input */
|
|
|
|
|
2015-01-15 15:03:56 +01:00
|
|
|
#ifdef CONFIG_NET_ICMPv6
|
2014-07-05 00:38:51 +02:00
|
|
|
case IP_PROTO_ICMP6: /* ICMP6 input */
|
2017-04-02 19:15:46 +02:00
|
|
|
/* Forward the ICMPv6 packet */
|
|
|
|
|
2015-01-15 15:03:56 +01:00
|
|
|
icmpv6_input(dev);
|
2007-11-07 19:54:35 +01:00
|
|
|
break;
|
2007-11-22 19:36:46 +01:00
|
|
|
#endif
|
2007-11-07 19:54:35 +01:00
|
|
|
|
|
|
|
default: /* Unrecognized/unsupported protocol */
|
|
|
|
#ifdef CONFIG_NET_STATISTICS
|
2015-01-24 15:26:12 +01:00
|
|
|
g_netstats.ipv6.drop++;
|
|
|
|
g_netstats.ipv6.protoerr++;
|
2007-11-07 19:54:35 +01:00
|
|
|
#endif
|
|
|
|
|
2016-06-20 17:37:08 +02:00
|
|
|
nwarn("WARNING: Unrecognized IP protocol: %04x\n", ipv6->proto);
|
2007-11-07 19:54:35 +01:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
2013-10-11 18:48:00 +02:00
|
|
|
/* Return and let the caller do any pending transmission. */
|
2007-11-07 19:54:35 +01:00
|
|
|
|
2013-09-06 17:18:07 +02:00
|
|
|
return OK;
|
2007-11-07 19:54:35 +01:00
|
|
|
|
2013-10-11 18:48:00 +02:00
|
|
|
/* Drop the packet. NOTE that OK is returned meaning that the
|
|
|
|
* packet has been processed (although processed unsuccessfully).
|
|
|
|
*/
|
|
|
|
|
2007-11-07 19:54:35 +01:00
|
|
|
drop:
|
|
|
|
dev->d_len = 0;
|
2013-10-11 18:48:00 +02:00
|
|
|
return OK;
|
2007-11-07 19:54:35 +01:00
|
|
|
}
|
2015-01-15 15:03:56 +01:00
|
|
|
#endif /* CONFIG_NET_IPv6 */
|