97bead5496
Change-Id: I13cc4cbfc1e305e17c0630f11a1173afe96e8a03 Signed-off-by: chao.an <anchao@xiaomi.com>
92 lines
3.7 KiB
C
92 lines
3.7 KiB
C
/****************************************************************************
|
|
* net/neighbor/neighbor_out.c
|
|
*
|
|
* Copyright (C) 2018 Pinecone Inc. All rights reserved.
|
|
* Author: Xiang Xiao <xiaoxiang@pinecone.net>
|
|
*
|
|
* 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/net/net.h>
|
|
#include <nuttx/net/netdev.h>
|
|
|
|
#include "neighbor/neighbor.h"
|
|
|
|
/****************************************************************************
|
|
* Public Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: neighbor_out
|
|
*
|
|
* Description:
|
|
* This function should be called before sending out an IPv6 packet. The
|
|
* function checks the destination IPv6 address of the IPv6 packet to see
|
|
* what L2 address that should be used as a destination L2 address.
|
|
*
|
|
* If the destination IPv6 address is in the local network (determined
|
|
* by logical ANDing of netmask and our IPv6 address), the function
|
|
* checks the Neighbor Table to see if an entry for the destination IPv6
|
|
* address is found. If so, an L2 header is pre-pended at the beginning
|
|
* of the packet and the function returns.
|
|
*
|
|
* If no Neighbor Table entry is found for the destination IPv6 address,
|
|
* the packet in the d_buf is replaced by an ICMPv6 Neighbor Solicit
|
|
* request packet for the IPv6 address. The IPv6 packet is dropped and
|
|
* it is assumed that the higher level protocols (e.g., TCP) eventually
|
|
* will retransmit the dropped packet.
|
|
*
|
|
* Upon return in either the case, a packet to be sent is present in the
|
|
* d_buf buffer and the d_len field holds the length of the L2 frame that
|
|
* should be transmitted.
|
|
*
|
|
****************************************************************************/
|
|
|
|
void neighbor_out(FAR struct net_driver_s *dev)
|
|
{
|
|
switch (dev->d_lltype)
|
|
{
|
|
#ifdef CONFIG_NET_ETHERNET
|
|
case NET_LL_ETHERNET:
|
|
case NET_LL_IEEE80211:
|
|
neighbor_ethernet_out(dev);
|
|
break;
|
|
#endif
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|