From 15fbb0adbd228d40b9fafab937054f68ed2d4a16 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 8 Oct 2012 01:16:01 +0200 Subject: Handle disappearing interfaces --- ffd/neigh.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ffd/neigh.c') 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; -- cgit v1.2.3