From b32200e3ad47edcc9c790e812d8dfb6679d0ace1 Mon Sep 17 00:00:00 2001
From: Martine Lenders <m.lenders@fu-berlin.de>
Date: Tue, 13 Jun 2017 15:51:43 +0200
Subject: [PATCH] gnrc_ipv6_nib: fix caching mechanism of neighbor cache

---
 .../network_layer/ipv6/nib/_nib-internal.c    | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c b/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c
index 0a316bb5ad..f366d5ec7c 100644
--- a/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c
+++ b/sys/net/gnrc/network_layer/ipv6/nib/_nib-internal.c
@@ -123,19 +123,18 @@ static inline _nib_onl_entry_t *_cache_out_onl_entry(const ipv6_addr_t *addr,
             res = tmp;
             res->mode = _EMPTY;
             _override_node(addr, iface, res);
-            /* cstate masked above already */
-            res->info = cstate;
+            /* cstate masked in _nib_nc_add() already */
+            res->info |= cstate;
             res->mode = _NC;
-            break;
         }
-        /* requeue if not garbage collectible at the moment */
-        DEBUG("nib: Requeing (addr = %s, iface = %u)\n",
-              ipv6_addr_to_str(addr_str, &tmp->ipv6,
-                               sizeof(addr_str)),
-              _nib_onl_get_if(tmp));
+        /* requeue if not garbage collectible at the moment or queueing
+         * newly created NCE */
         clist_rpush(&_next_removable, (clist_node_t *)tmp);
-        tmp = (_nib_onl_entry_t *)clist_lpop(&_next_removable);
-    } while (tmp != first);
+        if (res == NULL) {
+            /* no new entry created yet, get next entry in FIFO */
+            tmp = (_nib_onl_entry_t *)clist_lpop(&_next_removable);
+        }
+    } while ((tmp != first) && (res != NULL));
     return res;
 }
 
-- 
GitLab