summaryrefslogtreecommitdiffstats
path: root/ffd/neigh.c
diff options
context:
space:
mode:
Diffstat (limited to 'ffd/neigh.c')
-rw-r--r--ffd/neigh.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/ffd/neigh.c b/ffd/neigh.c
index ca72ccc..1b0d41d 100644
--- a/ffd/neigh.c
+++ b/ffd/neigh.c
@@ -32,6 +32,7 @@ ffd_neigh_t* ffd_neigh_get(ffd_iface_t *iface, const eth_addr_t *addr) {
if (!neigh) {
neigh = calloc(1, sizeof(ffd_neigh_t));
neigh->next = iface->neigh_list;
+ neigh->iface = iface;
iface->neigh_list = neigh;
neigh->addr = *addr;
@@ -41,16 +42,21 @@ ffd_neigh_t* ffd_neigh_get(ffd_iface_t *iface, const eth_addr_t *addr) {
return neigh;
}
-void ffd_neigh_free_list(ffd_neigh_t *neigh) {
+void ffd_neigh_unref_list(ffd_neigh_t *neigh) {
ffd_neigh_t *next;
for (; neigh; neigh = next) {
next = neigh->next;
- free(neigh);
+
+ neigh->iface = NULL;
+ neigh->next = NULL;
+
+ if (!neigh->ref)
+ free(neigh);
}
}
uint16_t ffd_neigh_get_rxcost(const ffd_neigh_t *neigh) {
- if (!neigh->hello_log || !neigh->hello_interval)
+ if (!neigh->hello_log || !neigh->hello_interval || !neigh->iface)
return 0xffff;
int timediff = timespec_diff(&now, &neigh->last_hello);
@@ -68,7 +74,7 @@ uint16_t ffd_neigh_get_rxcost(const ffd_neigh_t *neigh) {
}
uint16_t ffd_neigh_get_txcost(const ffd_neigh_t *neigh) {
- if (timespec_diff(&now, &neigh->last_ihu) > FFD_IHU_TIMEOUT(neigh->ihu_interval))
+ if (timespec_diff(&now, &neigh->last_ihu) > FFD_IHU_TIMEOUT(neigh->ihu_interval) || !neigh->iface)
return 0xffff;
else
return neigh->txcost;