diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index 45dacc7f32..a4fffd7936 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -50,7 +50,6 @@ #include "devif/devif.h" #include "arp/arp.h" -#include "neighbor/neighbor.h" #include "tcp/tcp.h" #include "udp/udp.h" #include "pkt/pkt.h" @@ -787,12 +786,6 @@ int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback) } #endif -#ifdef CONFIG_NET_IPv6 - /* Perform aging on the entries in the Neighbor Table */ - - neighbor_periodic(hsec); -#endif - #ifdef NET_TCP_HAVE_STACK /* Traverse all of the active TCP connections and perform the * timer action. diff --git a/net/neighbor/Make.defs b/net/neighbor/Make.defs index dd466a9c24..278a0f9541 100644 --- a/net/neighbor/Make.defs +++ b/net/neighbor/Make.defs @@ -37,8 +37,8 @@ ifeq ($(CONFIG_NET_IPv6),y) -NET_CSRCS += neighbor_initialize.c neighbor_add.c neighbor_lookup.c -NET_CSRCS += neighbor_update.c neighbor_periodic.c neighbor_findentry.c +NET_CSRCS += neighbor_globals.c neighbor_add.c neighbor_lookup.c +NET_CSRCS += neighbor_update.c neighbor_findentry.c # Link layer specific support diff --git a/net/neighbor/neighbor.h b/net/neighbor/neighbor.h index 74f84ae5e2..39dafdd05d 100644 --- a/net/neighbor/neighbor.h +++ b/net/neighbor/neighbor.h @@ -64,8 +64,6 @@ # define CONFIG_NET_IPv6_NCONF_ENTRIES 8 #endif -#define NEIGHBOR_MAXTIME 128 - /**************************************************************************** * Public Types ****************************************************************************/ @@ -96,7 +94,7 @@ struct neighbor_entry { net_ipv6addr_t ne_ipaddr; /* IPv6 address of the Neighbor */ struct neighbor_addr_s ne_addr; /* Link layer address of the Neighbor */ - uint8_t ne_time; /* For aging, units of half seconds */ + clock_t ne_time; /* For aging, units of tick */ }; /**************************************************************************** @@ -115,25 +113,6 @@ extern struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES]; struct net_driver_s; /* Forward reference */ -/**************************************************************************** - * Name: neighbor_initialize - * - * Description: - * Initialize Neighbor table data structures. This function is called - * prior to platform-specific driver initialization so that the networking - * subsystem is prepared to deal with network driver initialization - * actions. - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - -void neighbor_initialize(void); - /**************************************************************************** * Name: neighbor_findentry * @@ -208,23 +187,6 @@ FAR const struct neighbor_addr_s *neighbor_lookup(const net_ipv6addr_t ipaddr); void neighbor_update(const net_ipv6addr_t ipaddr); -/**************************************************************************** - * Name: neighbor_periodic - * - * Description: - * Called from the timer poll logic in order to perform agin operations on - * entries in the Neighbor Table - * - * Input Parameters: - * hsec - Elapsed time in half seconds since the last check - * - * Returned Value: - * None - * - ****************************************************************************/ - -void neighbor_periodic(int hsec); - /**************************************************************************** * Name: neighbor_dumpentry * diff --git a/net/neighbor/neighbor_add.c b/net/neighbor/neighbor_add.c index 8574588c5c..efa19ab40e 100644 --- a/net/neighbor/neighbor_add.c +++ b/net/neighbor/neighbor_add.c @@ -81,7 +81,7 @@ void neighbor_add(FAR struct net_driver_s *dev, FAR net_ipv6addr_t ipaddr, FAR uint8_t *addr) { uint8_t lltype; - uint8_t oldest_time; + clock_t oldest_time; int oldest_ndx; int i; @@ -89,18 +89,12 @@ void neighbor_add(FAR struct net_driver_s *dev, FAR net_ipv6addr_t ipaddr, /* Find the first unused entry or the oldest used entry. */ - oldest_time = 0; + oldest_time = g_neighbors[0].ne_time; oldest_ndx = 0; lltype = dev->d_lltype; for (i = 0; i < CONFIG_NET_IPv6_NCONF_ENTRIES; ++i) { - if (g_neighbors[i].ne_time == NEIGHBOR_MAXTIME) - { - oldest_ndx = i; - break; - } - if (g_neighbors[i].ne_addr.na_lltype == lltype && net_ipv6addr_cmp(g_neighbors[i].ne_ipaddr, ipaddr)) { @@ -108,7 +102,7 @@ void neighbor_add(FAR struct net_driver_s *dev, FAR net_ipv6addr_t ipaddr, break; } - if (g_neighbors[i].ne_time > oldest_time) + if ((int)(g_neighbors[i].ne_time - oldest_time) < 0) { oldest_ndx = i; oldest_time = g_neighbors[i].ne_time; @@ -119,7 +113,7 @@ void neighbor_add(FAR struct net_driver_s *dev, FAR net_ipv6addr_t ipaddr, * "oldest_ndx" variable). */ - g_neighbors[oldest_ndx].ne_time = 0; + g_neighbors[oldest_ndx].ne_time = clock_systimer(); net_ipv6addr_copy(g_neighbors[oldest_ndx].ne_ipaddr, ipaddr); g_neighbors[oldest_ndx].ne_addr.na_lltype = lltype; diff --git a/net/neighbor/neighbor_initialize.c b/net/neighbor/neighbor_initialize.c deleted file mode 100644 index d25fb782f3..0000000000 --- a/net/neighbor/neighbor_initialize.c +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** - * net/neighbor/neighbor_initialize.c - * - * Copyright (C) 2007-2009, 2015 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]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: neighbor_initialize - * - * Description: - * Initialize Neighbor table data structures. This function is called - * prior to platform-specific driver initialization so that the networking - * subsystem is prepared to deal with network driver initialization - * actions. - * - * Input Parameters: - * None - * - * Returned Value: - * None - * - ****************************************************************************/ - -void neighbor_initialize(void) -{ - int i; - - for (i = 0; i < CONFIG_NET_IPv6_NCONF_ENTRIES; ++i) - { - g_neighbors[i].ne_time = NEIGHBOR_MAXTIME; - } -} diff --git a/net/neighbor/neighbor_periodic.c b/net/neighbor/neighbor_periodic.c deleted file mode 100644 index 2ca0a5b3ca..0000000000 --- a/net/neighbor/neighbor_periodic.c +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** - * net/neighbor/neighbor_periodic.c - * - * Copyright (C) 2007-2009, 2015-2016 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 "neighbor/neighbor.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: neighbor_periodic - * - * Description: - * Called from the timer poll logic in order to perform agin operations on - * entries in the Neighbor Table - * - * Input Parameters: - * hsec - Elapsed time in half seconds since the last check - * - * Returned Value: - * None - * - ****************************************************************************/ - -void neighbor_periodic(int hsec) -{ - int i; - - /* Only perform the aging when more than a half second has elapsed */ - - if (hsec > 0) - { - /* Add the elapsed half seconds from each activate entry in the - * Neighbor table. - */ - - for (i = 0; i < CONFIG_NET_IPv6_NCONF_ENTRIES; ++i) - { - uint32_t newtime = g_neighbors[i].ne_time + hsec; - if (newtime > NEIGHBOR_MAXTIME) - { - newtime = NEIGHBOR_MAXTIME; - } - - g_neighbors[i].ne_time = newtime; - } - } -} diff --git a/net/neighbor/neighbor_update.c b/net/neighbor/neighbor_update.c index e0c7e4b92d..6bae8b636a 100644 --- a/net/neighbor/neighbor_update.c +++ b/net/neighbor/neighbor_update.c @@ -72,6 +72,6 @@ void neighbor_update(const net_ipv6addr_t ipaddr) neighbor = neighbor_findentry(ipaddr); if (neighbor != NULL) { - neighbor->ne_time = 0; + neighbor->ne_time = clock_systimer(); } } diff --git a/net/net_initialize.c b/net/net_initialize.c index 348c63079e..eb82777d0f 100644 --- a/net/net_initialize.c +++ b/net/net_initialize.c @@ -50,7 +50,6 @@ #include "netdev/netdev.h" #include "ipforward/ipforward.h" #include "sixlowpan/sixlowpan.h" -#include "neighbor/neighbor.h" #include "icmp/icmp.h" #include "icmpv6/icmpv6.h" #include "mld/mld.h" @@ -100,10 +99,6 @@ void net_initialize(void) net_lockinitialize(); #ifdef CONFIG_NET_IPv6 - /* Initialize the Neighbor Table data structures */ - - neighbor_initialize(); - #ifdef CONFIG_NET_MLD /* Initialize ICMPv6 Multicast Listener Discovery (MLD) logic */