mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 09:49:21 +08:00
net/neighbor: Simplify the neighbor table aging process
This commit is contained in:
parent
eb31dc69ac
commit
7f8496c643
8 changed files with 8 additions and 242 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
/****************************************************************************
|
||||
* net/neighbor/neighbor_initialize.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <adam@sics.se>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
#include <nuttx/clock.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
/****************************************************************************
|
||||
* net/neighbor/neighbor_periodic.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2015-2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <adam@sics.se>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
Loading…
Reference in a new issue