diff options
-rw-r--r-- | ffd/announce.c | 23 | ||||
-rw-r--r-- | ffd/ffd.h | 5 | ||||
-rw-r--r-- | ffd/send.c | 2 |
3 files changed, 24 insertions, 6 deletions
diff --git a/ffd/announce.c b/ffd/announce.c index 62e876a..151d1b3 100644 --- a/ffd/announce.c +++ b/ffd/announce.c @@ -27,6 +27,8 @@ #include "ffd.h" #include "neigh.h" +#include <stdio.h> + static void maintain_nexthops(ffd_announce_t *announce) { ffd_nexthop_t **cur, **next; @@ -37,6 +39,16 @@ static void maintain_nexthops(ffd_announce_t *announce) { if (!nexthop->neigh) /* local */ continue; + if (!nexthop->neigh->iface) { + if (nexthop->metric_seqno.metric != 0xffff) { + nexthop->metric_seqno.metric = 0xffff; + nexthop->last_update = now; + add_interval(&nexthop->last_update, FFD_UPDATE_TIMEOUT(nexthop->interval)); + } + + continue; + } + if (timespec_diff(&now, &nexthop->last_update) > FFD_UPDATE_TIMEOUT(nexthop->interval)) { if (nexthop->metric_seqno.metric == 0xffff) { *cur = *next; @@ -54,10 +66,12 @@ static void maintain_nexthops(ffd_announce_t *announce) { add_interval(&nexthop->last_update, FFD_UPDATE_TIMEOUT(nexthop->interval)); } } - else if (!nexthop->neigh->iface && nexthop->metric_seqno.metric != 0xffff) { - nexthop->metric_seqno.metric = 0xffff; - nexthop->last_update = now; - add_interval(&nexthop->last_update, FFD_UPDATE_TIMEOUT(nexthop->interval)); + else if (timespec_diff(&now, &nexthop->last_update) > FFD_UPDATE_REQUEST_TIMEOUT(nexthop->interval) && announce->selected == nexthop) { + if (!nexthop->requested_update) { + fprintf(stderr, "info: announce about to expire, requesting update\n"); + ffd_send_announce_request(nexthop->neigh->iface, nexthop->neigh, announce->node, announce->type, announce->key, false); + nexthop->requested_update = true; + } } } } @@ -106,6 +120,7 @@ void ffd_announce_update(ffd_announce_t *announce) { void ffd_announce_update_nexthop(ffd_announce_t *announce, ffd_nexthop_t *nexthop, ffd_metric_seqno_t ms, uint16_t interval) { nexthop->metric_seqno = ms; nexthop->interval = interval; + nexthop->requested_update = false; if (ms.metric != 0xffff) nexthop->last_update = now; @@ -43,7 +43,9 @@ #define FFD_HELLO_TIMEOUT(interval) (16*(interval)) #define FFD_IHU_TIMEOUT(interval) ((interval)*7/2) -#define FFD_UPDATE_TIMEOUT(interval) ((interval)*7/2) +#define FFD_UPDATE_TIMEOUT(interval) ((interval)*7/2) /* 3.5 intervals */ + +#define FFD_UPDATE_REQUEST_TIMEOUT(interval) ((interval)*13/4) /* 3.25 intervals */ #define FFD_MAINTENANCE_INTERVAL FFD_HELLO_INTERVAL @@ -68,6 +70,7 @@ typedef struct _ffd_nexthop_t { struct timespec last_update; uint16_t interval; + bool requested_update; } ffd_nexthop_t; typedef struct _ffd_announce_t { @@ -172,7 +172,7 @@ static bool add_update(ffd_packet_t *packet, size_t max_len, ffd_node_id_t *node update->type = htons(announce->type); update->key = htons(announce->key); - if (announce->len) { + if (announce->len && announce->metric.metric != 0xff) { update->flags |= FFD_UPDATE_WITH_DATA; if (with_data) { |