diff options
-rw-r--r-- | src/babel.h | 7 | ||||
-rw-r--r-- | src/neigh.c | 4 | ||||
-rw-r--r-- | src/route.c | 4 | ||||
-rw-r--r-- | src/tlv_types.c | 2 |
4 files changed, 12 insertions, 5 deletions
diff --git a/src/babel.h b/src/babel.h index 93a3bcd..0b0b4d4 100644 --- a/src/babel.h +++ b/src/babel.h @@ -152,6 +152,13 @@ static inline bool gp_babel_less(uint16_t a, uint16_t b) { return (diff < 0); } +static inline int64_t gp_babel_since(gmrf_context_t *ctx, gmrf_time_t t) { + if (t == gmrf_time_unspec) + return INT64_MAX; + + return (gmrf_now(ctx->gmrf) - t)/10; +} + static inline bool gp_babel_is_metric_better(gp_babel_metric_seqno_t ms1, gp_babel_metric_seqno_t ms2) { if (ms1.metric == GP_BABEL_INFINITY) return false; diff --git a/src/neigh.c b/src/neigh.c index 0270192..bffbaa4 100644 --- a/src/neigh.c +++ b/src/neigh.c @@ -68,7 +68,7 @@ uint16_t gp_babel_neigh_get_rxcost(gmrf_context_t *ctx, const gp_babel_neigh_t * if (!neigh->hello_log || !neigh->hello_interval || !neigh->iface) return GP_BABEL_INFINITY; - int timediff = (gmrf_now(ctx->gmrf) - neigh->last_hello)/10; + int timediff = gp_babel_since(ctx, neigh->last_hello); int shift = (timediff - neigh->hello_interval/2)/neigh->hello_interval; if (shift >= 16) @@ -83,7 +83,7 @@ uint16_t gp_babel_neigh_get_rxcost(gmrf_context_t *ctx, const gp_babel_neigh_t * } uint16_t gp_babel_neigh_get_txcost(gmrf_context_t *ctx, const gp_babel_neigh_t *neigh) { - if ((gmrf_now(ctx->gmrf) - neigh->last_ihu)/10 > GP_BABEL_IHU_TIMEOUT(neigh->ihu_interval) || !neigh->iface) + if (gp_babel_since(ctx, neigh->last_ihu) > GP_BABEL_IHU_TIMEOUT(neigh->ihu_interval) || !neigh->iface) return GP_BABEL_INFINITY; else return neigh->txcost; diff --git a/src/route.c b/src/route.c index 163fb24..64107b2 100644 --- a/src/route.c +++ b/src/route.c @@ -109,7 +109,7 @@ static void maintain_nexthops(gmrf_context_t *ctx, gp_babel_route_t *route) { continue; } - if (gmrf_now(ctx->gmrf) > nexthop->last_update+GP_BABEL_UPDATE_TIMEOUT(nexthop->interval)*10) { + if (gp_babel_since(ctx, nexthop->last_update) > GP_BABEL_UPDATE_TIMEOUT(nexthop->interval)) { if (nexthop->metric_seqno.metric == GP_BABEL_INFINITY) { *cur = *next; next = cur; @@ -126,7 +126,7 @@ static void maintain_nexthops(gmrf_context_t *ctx, gp_babel_route_t *route) { nexthop->last_update += GP_BABEL_UPDATE_TIMEOUT(nexthop->interval)*10; } } - else if (gmrf_now(ctx->gmrf) > nexthop->last_update+GP_BABEL_UPDATE_REQUEST_TIMEOUT(nexthop->interval)*10 && route->selected == nexthop) { + else if (gp_babel_since(ctx, nexthop->last_update) > GP_BABEL_UPDATE_REQUEST_TIMEOUT(nexthop->interval)*10 && route->selected == nexthop) { if (!nexthop->requested_update) { gmrf_logf(ctx->gmrf, LOG_INFO, "route about to expire, requesting update"); gp_babel_send_route_request(ctx, NULL, nexthop->neigh, &route->node); diff --git a/src/tlv_types.c b/src/tlv_types.c index ddf819f..12b7248 100644 --- a/src/tlv_types.c +++ b/src/tlv_types.c @@ -77,7 +77,7 @@ static void handle_tlv_hello(gmrf_context_t *ctx, const gp_babel_tlv_hello_t *tl uint16_t seqno = ntohs(tlv->seqno); if (neigh->last_hello != gmrf_time_unspec) { - int timediff = (gmrf_now(ctx->gmrf) - neigh->last_hello)/10; + int timediff = gp_babel_since(ctx, neigh->last_hello); uint16_t seqexp = neigh->last_seqno + (timediff - neigh->hello_interval/2)/neigh->hello_interval; /* cast to int16_t to ensure correct handling of seqno wrapping */ |