2019-11-08 18:15:16 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* net/neighbor/neighbor_snapshot.c
|
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2019-11-08 18:15:16 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2019-11-08 18:15:16 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2019-11-08 18:15:16 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/net/ip.h>
|
|
|
|
|
|
|
|
#include "inet/inet.h"
|
|
|
|
#include "neighbor/neighbor.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETLINK_ROUTE
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: neighbor_snapshot
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Take a snapshot of the current state of the Neighbor table.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* snapshot - Location to return the Neighbor table copy
|
|
|
|
* nentries - The size of the user provided 'dest' in entries, each of
|
|
|
|
* size sizeof(struct arp_entry_s)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, the number of entries actually copied is returned. Unused
|
|
|
|
* entries are not returned.
|
|
|
|
*
|
|
|
|
* Assumptions
|
|
|
|
* The network is locked to assure exclusive access to the ARP table
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
unsigned int neighbor_snapshot(FAR struct neighbor_entry_s *snapshot,
|
|
|
|
unsigned int nentries)
|
|
|
|
{
|
|
|
|
unsigned int ncopied;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Copy all non-empty entries in the Neighbor table. */
|
|
|
|
|
|
|
|
for (i = 0, ncopied = 0;
|
|
|
|
nentries > ncopied && i < CONFIG_NET_IPv6_NCONF_ENTRIES;
|
|
|
|
i++)
|
|
|
|
{
|
|
|
|
FAR struct neighbor_entry_s *neighbor = &g_neighbors[i];
|
|
|
|
|
|
|
|
/* An unused entry table entry will be nullified. In particularly,
|
|
|
|
* the Neighbor IP address will be all zero (i.e., the unspecified
|
|
|
|
* IPv6 address).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!net_ipv6addr_cmp(neighbor->ne_ipaddr, g_ipv6_unspecaddr))
|
|
|
|
{
|
2021-02-19 15:01:46 +01:00
|
|
|
memcpy(&snapshot[ncopied], neighbor,
|
|
|
|
sizeof(struct neighbor_entry_s));
|
2019-11-08 18:15:16 +01:00
|
|
|
ncopied++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the number of entries copied into the user buffer */
|
|
|
|
|
|
|
|
return ncopied;
|
|
|
|
}
|
|
|
|
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_NETLINK_ROUTE */
|