diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-10-08 01:16:01 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-10-08 01:16:01 +0200 |
commit | 15fbb0adbd228d40b9fafab937054f68ed2d4a16 (patch) | |
tree | 83ed99ff67f14c3b612250096e623825dcceda01 /ffd/neigh.c | |
parent | a934dcc3ce78b22a0ff4db5d353a3d8dcc2b5f1d (diff) | |
download | ffd-15fbb0adbd228d40b9fafab937054f68ed2d4a16.tar ffd-15fbb0adbd228d40b9fafab937054f68ed2d4a16.zip |
Handle disappearing interfaces
Diffstat (limited to 'ffd/neigh.c')
-rw-r--r-- | ffd/neigh.c | 14 |
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; |