IPv6 Neighbor: Update table format to support IEEE 802.15.4 MAC addresses.
This commit is contained in:
parent
a5f361e984
commit
f323f75887
8 changed files with 122 additions and 50 deletions
|
@ -74,6 +74,14 @@
|
|||
#define ICMPv6RADVERTISE \
|
||||
((struct icmpv6_router_advertise_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN])
|
||||
|
||||
#if defined(CONFIG_NET_MULTILINK)
|
||||
# define DEV_LLTYPE(d) ((d)->d_lltype)
|
||||
#elif defined(CONFIG_NET_ETHERNET)
|
||||
# define DEV_LLTYPE(d) NET_LL_ETHERNET
|
||||
#elif defined(CONFIG_NET_6LOWPAN)
|
||||
# define DEV_LLTYPE(d) NET_LL_IEEE802154
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
@ -167,8 +175,7 @@ void icmpv6_input(FAR struct net_driver_s *dev)
|
|||
{
|
||||
/* Save the sender's address mapping in our Neighbor Table. */
|
||||
|
||||
neighbor_add(icmp->srcipaddr,
|
||||
(FAR struct neighbor_addr_s *)adv->tgtlladdr);
|
||||
neighbor_add(icmp->srcipaddr, DEV_LLTYPE(dev), adv->tgtlladdr);
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
/* Then notify any logic waiting for the Neighbor Advertisement */
|
||||
|
|
|
@ -9,6 +9,4 @@ config NET_IPv6_NCONF_ENTRIES
|
|||
int "Number of IPv6 neighbors"
|
||||
default 8
|
||||
|
||||
#config NET_IPv6_NEIGHBOR_ADDRTYPE
|
||||
|
||||
endif # NET_IPv6
|
||||
|
|
|
@ -50,6 +50,10 @@ ifeq ($(CONFIG_NET_6LOWPAN),y)
|
|||
# NET_CSRCS += neighbor_6lowpan_out.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DEBUG_NET_INFO),y)
|
||||
NET_CSRCS += neighbor_dumpentry.c
|
||||
endif
|
||||
|
||||
# Include utility build support
|
||||
|
||||
DEPPATH += --dep-path neighbor
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Header file for database of link-local neighbors, used by IPv6 code and
|
||||
* to be used by future ARP code.
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2015 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2015, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* A leverage of logic from uIP which also has a BSD style license
|
||||
|
@ -51,6 +51,7 @@
|
|||
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/ieee802154.h>
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
|
||||
|
@ -72,11 +73,19 @@
|
|||
|
||||
struct neighbor_addr_s
|
||||
{
|
||||
#ifdef CONFIG_NET_IPv6_NEIGHBOR_ADDRTYPE
|
||||
CONFIG_NET_IPv6_NEIGHBOR_ADDRTYPE na_addr;
|
||||
#else
|
||||
struct ether_addr na_addr;
|
||||
union
|
||||
{
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
uint8_t na_lltype;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_ETHERNET
|
||||
struct ether_addr na_ethernet;
|
||||
#endif
|
||||
#ifdef CONFIG_NET_6LOWPAN
|
||||
struct sixlowpan_addr_s na_sixlowpan;
|
||||
#endif
|
||||
} u;
|
||||
};
|
||||
|
||||
/* This structure describes on entry in the neighbor table. This is intended
|
||||
|
@ -150,6 +159,7 @@ FAR struct neighbor_entry *neighbor_findentry(const net_ipv6addr_t ipaddr);
|
|||
*
|
||||
* Input Parameters:
|
||||
* ipaddr - The IPv6 address of the mapping.
|
||||
* lltype - The link layer address type
|
||||
* addr - The link layer address of the mapping
|
||||
*
|
||||
* Returned Value:
|
||||
|
@ -157,7 +167,8 @@ FAR struct neighbor_entry *neighbor_findentry(const net_ipv6addr_t ipaddr);
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
void neighbor_add(FAR net_ipv6addr_t ipaddr, FAR struct neighbor_addr_s *addr);
|
||||
void neighbor_add(FAR net_ipv6addr_t ipaddr, uint8_t lltype,
|
||||
FAR uint8_t *addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: neighbor_lookup
|
||||
|
@ -212,6 +223,50 @@ void neighbor_update(const net_ipv6addr_t ipaddr);
|
|||
|
||||
void neighbor_periodic(int hsec);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: neighbor_dumpentry
|
||||
*
|
||||
* Description:
|
||||
* Dump the conents of an entry Neighbor Table.
|
||||
*
|
||||
* Input Parameters:
|
||||
* msg - Message to print with the entry
|
||||
* neighbor - The table entry to dump
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_DEBUG_NET_INFO
|
||||
void neighbor_dumpentry(FAR const char *msg,
|
||||
FAR struct neighbor_entry *neighbor);
|
||||
#else
|
||||
# define neighbor_dumpentry(msg,neighbor)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: neighbor_dumpipaddr
|
||||
*
|
||||
* Description:
|
||||
* Dump an IP address.
|
||||
*
|
||||
* Input Parameters:
|
||||
* msg - Message to print with the entry
|
||||
* ipaddr - The IP address to dump
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_DEBUG_NET_INFO
|
||||
void neighbor_dumpipaddr(FAR const char *msg,
|
||||
const net_ipv6addr_t ipaddr);
|
||||
#else
|
||||
# define neighbor_dumpipaddr(msg,ipaddr)
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
#endif /* __NET_NEIGHBOR_NEIGHBOR_H */
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* net/neighbor/neighbor_add.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2015 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2015, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* A leverage of logic from uIP which also has a BSD style license
|
||||
|
@ -43,6 +43,7 @@
|
|||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <debug.h>
|
||||
|
||||
|
@ -63,6 +64,7 @@
|
|||
*
|
||||
* Input Parameters:
|
||||
* ipaddr - The IPv6 address of the mapping.
|
||||
* lltype - The link layer address type
|
||||
* addr - The link layer address of the mapping
|
||||
*
|
||||
* Returned Value:
|
||||
|
@ -70,23 +72,36 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
void neighbor_add(FAR net_ipv6addr_t ipaddr, FAR struct neighbor_addr_s *addr)
|
||||
void neighbor_add(FAR net_ipv6addr_t ipaddr, uint8_t lltype,
|
||||
FAR uint8_t *addr)
|
||||
{
|
||||
uint8_t addrlen;
|
||||
uint8_t oldest_time;
|
||||
int oldest_ndx;
|
||||
int i;
|
||||
|
||||
ninfo("Add neighbor: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
ntohs(ipaddr[0]), ntohs(ipaddr[1]), ntohs(ipaddr[2]),
|
||||
ntohs(ipaddr[3]), ntohs(ipaddr[4]), ntohs(ipaddr[5]),
|
||||
ntohs(ipaddr[6]), ntohs(ipaddr[7]));
|
||||
ninfo(" at: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
addr->na_addr.ether_addr_octet[0],
|
||||
addr->na_addr.ether_addr_octet[1],
|
||||
addr->na_addr.ether_addr_octet[2],
|
||||
addr->na_addr.ether_addr_octet[3],
|
||||
addr->na_addr.ether_addr_octet[4],
|
||||
addr->na_addr.ether_addr_octet[5]);
|
||||
/* Get the length of the address for this link layer type */
|
||||
|
||||
#ifdef CONFIG_NET_ETHERNET
|
||||
#ifdef CONFIG_NET_6LOWPAN
|
||||
if (lltype == NET_LL_ETHERNET)
|
||||
#endif
|
||||
{
|
||||
addrlen = IFHWADDRLEN;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_NET_6LOWPAN
|
||||
#ifdef CONFIG_NET_ETHERNET
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
||||
addrlen = NET_6LOWPAN_EADDRSIZE;
|
||||
#else
|
||||
addrlen = NET_6LOWPAN_SADDRSIZE;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Find the first unused entry or the oldest used entry. */
|
||||
|
||||
|
@ -101,7 +116,12 @@ void neighbor_add(FAR net_ipv6addr_t ipaddr, FAR struct neighbor_addr_s *addr)
|
|||
break;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
if (g_neighbors[i].ne_addr.na_lltype == lltype &&
|
||||
net_ipv6addr_cmp(g_neighbors[i].ne_ipaddr, ipaddr))
|
||||
#else
|
||||
if (net_ipv6addr_cmp(g_neighbors[i].ne_ipaddr, ipaddr))
|
||||
#endif
|
||||
{
|
||||
oldest_ndx = i;
|
||||
break;
|
||||
|
@ -120,5 +140,13 @@ void neighbor_add(FAR net_ipv6addr_t ipaddr, FAR struct neighbor_addr_s *addr)
|
|||
|
||||
g_neighbors[oldest_ndx].ne_time = 0;
|
||||
net_ipv6addr_copy(g_neighbors[oldest_ndx].ne_ipaddr, ipaddr);
|
||||
memcpy(&g_neighbors[oldest_ndx].ne_addr, addr, sizeof(struct neighbor_addr_s));
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
g_neighbors[oldest_ndx].ne_addr.na_lltype = lltype;
|
||||
#endif
|
||||
memcpy(&g_neighbors[oldest_ndx].ne_addr.u, addr, addrlen);
|
||||
|
||||
/* Dump the contents of the new entry */
|
||||
|
||||
neighbor_dumpentry("Added entry", &g_neighbors[oldest_ndx]);
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ void neighbor_out(FAR struct net_driver_s *dev)
|
|||
|
||||
/* Build an Ethernet header. */
|
||||
|
||||
memcpy(eth->dest, naddr->na_addr.ether_addr_octet, ETHER_ADDR_LEN);
|
||||
memcpy(eth->dest, naddr->u.na_ethernet.ether_addr_octet, ETHER_ADDR_LEN);
|
||||
}
|
||||
|
||||
/* Finish populating the Ethernet header */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* net/neighbor/neighbor_findentry.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2015 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2015, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* A leverage of logic from uIP which also has a BSD style license
|
||||
|
@ -49,7 +49,7 @@
|
|||
#include "neighbor/neighbor.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -72,29 +72,17 @@ FAR struct neighbor_entry *neighbor_findentry(const net_ipv6addr_t ipaddr)
|
|||
{
|
||||
int i;
|
||||
|
||||
ninfo("Find neighbor: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
ntohs(ipaddr[0]), ntohs(ipaddr[1]), ntohs(ipaddr[2]),
|
||||
ntohs(ipaddr[3]), ntohs(ipaddr[4]), ntohs(ipaddr[5]),
|
||||
ntohs(ipaddr[6]), ntohs(ipaddr[7]));
|
||||
|
||||
for (i = 0; i < CONFIG_NET_IPv6_NCONF_ENTRIES; ++i)
|
||||
{
|
||||
FAR struct neighbor_entry *neighbor = &g_neighbors[i];
|
||||
|
||||
if (net_ipv6addr_cmp(neighbor->ne_ipaddr, ipaddr))
|
||||
{
|
||||
ninfo(" at: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[0],
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[1],
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[2],
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[3],
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[4],
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[5]);
|
||||
|
||||
return &g_neighbors[i];
|
||||
neighbor_dumpentry("Entry found", neighbor);
|
||||
return neighbor;
|
||||
}
|
||||
}
|
||||
|
||||
ninfo(" Not found\n");
|
||||
neighbor_dumpipaddr("Not found", ipaddr);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -76,14 +76,6 @@ FAR const struct neighbor_addr_s *neighbor_lookup(const net_ipv6addr_t ipaddr)
|
|||
neighbor = neighbor_findentry(ipaddr);
|
||||
if (neighbor != NULL)
|
||||
{
|
||||
ninfo("Lookup neighbor: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[0],
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[1],
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[2],
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[3],
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[4],
|
||||
neighbor->ne_addr.na_addr.ether_addr_octet[5]);
|
||||
|
||||
return &neighbor->ne_addr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue