diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 35c78e7cf90..df82948dcd8 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -554,24 +554,23 @@ int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback); * 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 Ethernet MAC address that should be used as a destination MAC - * address on the Ethernet. + * 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 Ethernet header is pre-pended at the - * beginning of the packet and the function returns. + * 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 Solict + * 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 Ethernet - * frame that should be transmitted. + * d_buf buffer and the d_len field holds the length of the L2 frame that + * should be transmitted. * ****************************************************************************/ diff --git a/net/neighbor/Make.defs b/net/neighbor/Make.defs index 278a0f95419..8b3d71a5ca2 100644 --- a/net/neighbor/Make.defs +++ b/net/neighbor/Make.defs @@ -38,7 +38,7 @@ ifeq ($(CONFIG_NET_IPv6),y) NET_CSRCS += neighbor_globals.c neighbor_add.c neighbor_lookup.c -NET_CSRCS += neighbor_update.c neighbor_findentry.c +NET_CSRCS += neighbor_update.c neighbor_findentry.c neighbor_out.c # Link layer specific support diff --git a/net/neighbor/neighbor.h b/net/neighbor/neighbor.h index 4abfb149961..64a9a2f5865 100644 --- a/net/neighbor/neighbor.h +++ b/net/neighbor/neighbor.h @@ -190,6 +190,37 @@ int neighbor_lookup(FAR const net_ipv6addr_t ipaddr, void neighbor_update(const net_ipv6addr_t ipaddr); +/**************************************************************************** + * Name: neighbor_ethernet_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 Ethernet MAC address that should be used as a destination MAC + * address on the Ethernet. + * + * 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 Ethernet 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 Ethernet + * frame that should be transmitted. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_ETHERNET +void neighbor_ethernet_out(FAR struct net_driver_s *dev); +#endif + /**************************************************************************** * Name: neighbor_dumpentry * diff --git a/net/neighbor/neighbor_ethernet_out.c b/net/neighbor/neighbor_ethernet_out.c index 063531acd91..c61c71dadee 100644 --- a/net/neighbor/neighbor_ethernet_out.c +++ b/net/neighbor/neighbor_ethernet_out.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/neighbor/neighbor_ethernet_out.c * - * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -54,12 +54,8 @@ * Pre-processor Definitions ****************************************************************************/ -#define ETHBUF ((struct eth_hdr_s *)dev->d_buf) -#define IPv6BUF ((struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) - -/**************************************************************************** - * Private Types - ****************************************************************************/ +#define ETHBUF ((FAR struct eth_hdr_s *)dev->d_buf) +#define IPv6BUF ((FAR struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)]) /**************************************************************************** * Private Data @@ -79,7 +75,8 @@ static const struct ether_addr g_broadcast_ethaddr = * Well-known ethernet multicast address: * * ADDRESS TYPE USAGE - * 01-00-0c-cc-cc-cc 0x0802 CDP (Cisco Discovery Protocol), VTP (Virtual Trunking Protocol) + * 01-00-0c-cc-cc-cc 0x0802 CDP (Cisco Discovery Protocol), VTP (Virtual + * Trunking Protocol) * 01-00-0c-cc-cc-cd 0x0802 Cisco Shared Spanning Tree Protocol Address * 01-80-c2-00-00-00 0x0802 Spanning Tree Protocol (for bridges) IEEE 802.1D * 01-80-c2-00-00-02 0x0809 Ethernet OAM Protocol IEEE 802.3ah @@ -106,7 +103,7 @@ static const uint8_t g_multicast_ethaddr[3] = ****************************************************************************/ /**************************************************************************** - * Name: neighbor_out + * Name: neighbor_ethernet_out * * Description: * This function should be called before sending out an IPv6 packet. The @@ -132,7 +129,7 @@ static const uint8_t g_multicast_ethaddr[3] = * ****************************************************************************/ -void neighbor_out(FAR struct net_driver_s *dev) +void neighbor_ethernet_out(FAR struct net_driver_s *dev) { FAR struct eth_hdr_s *eth = ETHBUF; FAR struct ipv6_hdr_s *ip = IPv6BUF; @@ -179,9 +176,6 @@ void neighbor_out(FAR struct net_driver_s *dev) * * IPv6 multicast addresses are have the high-order octet of the * addresses=0xff (ff00::/8.) - * - * REVISIT: See comments above. How do we distinguish broadcast - * from IGMP multicast? */ #warning Missing logic #endif diff --git a/net/neighbor/neighbor_globals.c b/net/neighbor/neighbor_globals.c new file mode 100644 index 00000000000..16434ae6876 --- /dev/null +++ b/net/neighbor/neighbor_globals.c @@ -0,0 +1,58 @@ +/**************************************************************************** + * net/neighbor/neighbor_globals.c + * + * Copyright (C) 2007-2009, 2015, 2018 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * A leverage of logic from uIP which also has a BSD style license + * + * Copyright (c) 2006, Swedish Institute of Computer Science. All rights + * reserved. + * Author: Adam Dunkels + * + * 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 of the Institute 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 INSTITUTE 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 INSTITUTE 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 +#include + +#include "neighbor/neighbor.h" + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* This is the Neighbor table. The network should be locked when accessing + * this table. + */ + +struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES]; + diff --git a/net/neighbor/neighbor_out.c b/net/neighbor/neighbor_out.c new file mode 100644 index 00000000000..5ee500284d5 --- /dev/null +++ b/net/neighbor/neighbor_out.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * net/neighbor/neighbor_out.c + * + * Copyright (C) 2018 Pinecone Inc. All rights reserved. + * Author: Xiang Xiao + * + * 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 + +#include +#include + +#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: + neighbor_ethernet_out(dev); + break; +#endif + + default: + break; + } +}