From a65804027fc14582a141450fb02aac55ac678888 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 28 Aug 2015 03:51:26 +0200 Subject: [PATCH] gnrc_ipv6_nc: adapt neighbor cache for different ND implementations --- sys/include/net/gnrc/ipv6/nc.h | 12 ++++++++++++ sys/net/gnrc/network_layer/ipv6/nc/gnrc_ipv6_nc.c | 12 ++++++++++-- sys/net/gnrc/network_layer/ndp/gnrc_ndp.c | 6 +++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/sys/include/net/gnrc/ipv6/nc.h b/sys/include/net/gnrc/ipv6/nc.h index 1e2a4e8d58..83efea2aa5 100644 --- a/sys/include/net/gnrc/ipv6/nc.h +++ b/sys/include/net/gnrc/ipv6/nc.h @@ -25,6 +25,7 @@ #include #include "kernel_types.h" +#include "net/eui64.h" #include "net/ipv6/addr.h" #include "net/gnrc/netif.h" #include "net/gnrc/pktqueue.h" @@ -118,7 +119,9 @@ extern "C" { * . */ typedef struct { +#ifdef MODULE_GNRC_NDP_NODE gnrc_pktqueue_t *pkts; /**< Packets waiting for address resolution */ +#endif ipv6_addr_t ipv6_addr; /**< IPv6 address of the neighbor */ uint8_t l2_addr[GNRC_IPV6_NC_L2_ADDR_MAX]; /**< Link layer address of the neighbor */ uint8_t l2_addr_len; /**< Length of gnrc_ipv6_nc_t::l2_addr */ @@ -143,6 +146,15 @@ typedef struct { */ vtimer_t nbr_adv_timer; +#ifdef MODULE_GNRC_SIXLOWPAN_ND + vtimer_t rtr_sol_timer; /**< Retransmission timer for unicast router solicitations */ +#endif +#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER + vtimer_t type_timeout; /**< Timer for type transissions */ + eui64_t eui64; /**< the unique EUI-64 of the neighbor (might be + * different from L2 address, if l2_addr_len == 2) */ +#endif + uint8_t probes_remaining; /**< remaining number of unanswered probes */ /** * @} diff --git a/sys/net/gnrc/network_layer/ipv6/nc/gnrc_ipv6_nc.c b/sys/net/gnrc/network_layer/ipv6/nc/gnrc_ipv6_nc.c index f311680609..db4c1c4bc4 100644 --- a/sys/net/gnrc/network_layer/ipv6/nc/gnrc_ipv6_nc.c +++ b/sys/net/gnrc/network_layer/ipv6/nc/gnrc_ipv6_nc.c @@ -102,7 +102,9 @@ gnrc_ipv6_nc_t *gnrc_ipv6_nc_add(kernel_pid_t iface, const ipv6_addr_t *ipv6_add /* Otherwise, fill free entry with your fresh information */ free_entry->iface = iface; +#ifdef MODULE_GNRC_NDP_NODE free_entry->pkts = NULL; +#endif memcpy(&(free_entry->ipv6_addr), ipv6_addr, sizeof(ipv6_addr_t)); DEBUG("ipv6_nc: Register %s for interface %" PRIkernel_pid, ipv6_addr_to_str(addr_str, ipv6_addr, sizeof(addr_str)), @@ -137,13 +139,19 @@ void gnrc_ipv6_nc_remove(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr) ipv6_addr_to_str(addr_str, ipv6_addr, sizeof(addr_str)), iface); +#ifdef MODULE_GNRC_NDP_NODE while (entry->pkts != NULL) { -#ifdef MODULE_GNRC_PKTBUF gnrc_pktbuf_release(entry->pkts->pkt); -#endif entry->pkts->pkt = NULL; gnrc_pktqueue_remove_head(&entry->pkts); } +#endif +#ifdef MODULE_GNRC_SIXLOWPAN_ND + vtimer_remove(&entry->rtr_sol_timer); +#endif +#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER + vtimer_remove(&entry->type_timeout); +#endif ipv6_addr_set_unspecified(&(entry->ipv6_addr)); entry->iface = KERNEL_PID_UNDEF; diff --git a/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c b/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c index e79cd12a7b..ede00c983c 100644 --- a/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c +++ b/sys/net/gnrc/network_layer/ndp/gnrc_ndp.c @@ -195,8 +195,6 @@ void gnrc_ndp_nbr_adv_handle(kernel_pid_t iface, gnrc_pktsnip_t *pkt, if (l2tgt_len != -ENOTSUP) { if (gnrc_ipv6_nc_get_state(nc_entry) == GNRC_IPV6_NC_STATE_INCOMPLETE) { - gnrc_pktqueue_t *queued_pkt; - if (_pkt_has_l2addr(netif_hdr) && (l2tgt_len == 0)) { /* link-layer has addresses, but no TLLAO supplied: discard silently * (see https://tools.ietf.org/html/rfc4861#section-7.2.5) */ @@ -221,11 +219,13 @@ void gnrc_ndp_nbr_adv_handle(kernel_pid_t iface, gnrc_pktsnip_t *pkt, nc_entry->flags &= ~GNRC_IPV6_NC_IS_ROUTER; /* TODO: update state of neighbor as router in FIB? */ } - +#ifdef MODULE_GNRC_NDP_NODE + gnrc_pktqueue_t *queued_pkt; while ((queued_pkt = gnrc_pktqueue_remove_head(&nc_entry->pkts)) != NULL) { gnrc_netapi_send(gnrc_ipv6_pid, queued_pkt->pkt); queued_pkt->pkt = NULL; } +#endif } else { /* first or-term: no link-layer, but nc_entry has l2addr,