summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ffd/announce.c12
-rw-r--r--ffd/ffd.c30
-rw-r--r--ffd/ffd.h2
3 files changed, 23 insertions, 21 deletions
diff --git a/ffd/announce.c b/ffd/announce.c
index 5b31e91..e1f7ae0 100644
--- a/ffd/announce.c
+++ b/ffd/announce.c
@@ -73,10 +73,20 @@ ffd_metric_seqno_t ffd_announce_get_metric(const ffd_announce_t *announce) {
return (ffd_metric_seqno_t){0xffff, 0};
}
-void ffd_announce_update_nexthop(ffd_announce_t *announce) {
+static inline void update_selected(ffd_announce_t *announce) {
announce->selected = select_nexthop(announce);
}
+void ffd_announce_update(ffd_announce_t *announce, ffd_nexthop_t *nexthop, ffd_metric_seqno_t ms, uint16_t interval) {
+ nexthop->metric_seqno = ms;
+ nexthop->interval = interval;
+
+ if (ms.metric != 0xffff)
+ nexthop->last_update = now;
+
+ update_selected(announce);
+}
+
ffd_announce_t* ffd_announce_new(void) {
ffd_announce_t *a = calloc(1, sizeof(ffd_announce_t));
diff --git a/ffd/ffd.c b/ffd/ffd.c
index 5817106..592281a 100644
--- a/ffd/ffd.c
+++ b/ffd/ffd.c
@@ -347,28 +347,14 @@ static void handle_tlv_update(const ffd_tlv_update_t *tlv_update, size_t len, ha
ffd_nexthop_t *nexthop = find_nexthop(announce, neigh);
if (!nexthop) {
- if (!feasible || tlv_update->metric == 0xffff /* no need to ntohs */)
- return;
-
- nexthop = new_nexthop(announce, neigh);
+ if (feasible && tlv_update->metric != 0xffff /* no need to ntohs */)
+ nexthop = new_nexthop(announce, neigh);
}
else {
if (!feasible && nexthop == announce->selected)
- return;
+ nexthop = NULL;
}
- nexthop->metric_seqno.metric = ntohs(tlv_update->metric);
- nexthop->metric_seqno.seqno = ntohs(tlv_update->seqno);
- nexthop->interval = ntohs(tlv_update->interval);
-
- fprintf(stderr, "debug: the update was accepted.\n");
-
- if (nexthop->metric_seqno.metric == 0xffff)
- return;
-
- /* only update the timestamp for finite metrics */
- nexthop->last_update = now;
-
if ((tlv_update->flags & FFD_UPDATE_WITH_DATA) && !announce->data) {
if (len > sizeof(ffd_tlv_update_t)) {
announce->len = len - sizeof(ffd_tlv_update_t);
@@ -379,11 +365,17 @@ static void handle_tlv_update(const ffd_tlv_update_t *tlv_update, size_t len, ha
announce->len = 0xff;
/* request data */
- ffd_send_announce_request(arg->iface, neigh, announce->node, announce->type, announce->key, true);
+ if (nexthop)
+ ffd_send_announce_request(arg->iface, neigh, announce->node, announce->type, announce->key, true);
}
}
- ffd_announce_update_nexthop(announce);
+ if (!nexthop)
+ return;
+
+ fprintf(stderr, "debug: the update was accepted.\n");
+
+ ffd_announce_update(announce, nexthop, ms, ntohs(tlv_update->interval));
}
static void handle_tlv_announce_req(const ffd_tlv_announce_req_t *tlv_req, size_t len, handle_tlv_arg_t *arg) {
diff --git a/ffd/ffd.h b/ffd/ffd.h
index 946fcd3..0b1c296 100644
--- a/ffd/ffd.h
+++ b/ffd/ffd.h
@@ -149,7 +149,7 @@ extern struct timespec now;
bool ffd_is_feasible(const ffd_announce_t *announce, ffd_metric_seqno_t ms);
ffd_metric_seqno_t ffd_announce_get_metric(const ffd_announce_t *announce);
-void ffd_announce_update_nexthop(ffd_announce_t *announce);
+void ffd_announce_update(ffd_announce_t *announce, ffd_nexthop_t *nexthop, ffd_metric_seqno_t ms, uint16_t interval);
ffd_announce_t* ffd_announce_new(void);
void ffd_send_ack(ffd_iface_t *iface, ffd_neigh_t *neigh, uint16_t nonce);