gluon-radv-filterd: Fix integer underflow with low TQs

The TQ of the best router can be lower than the hysteresis_thresh. The
check could cause an integer underflow which then causes an election which
is not necessary.

This can be avoided by reordering the check slightly and only substracting
values which will not cause underflows.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
This commit is contained in:
Sven Eckelmann 2017-12-20 12:44:54 +01:00 committed by Jan-Philipp Litza
parent c9f661740c
commit 8251de682a
No known key found for this signature in database
GPG Key ID: 1FB658053CE27196

View File

@ -538,7 +538,14 @@ static bool election_required(void)
if (!G.best_router)
return true;
return G.best_router->tq < G.max_tq - G.hysteresis_thresh;
/* should never happen. G.max_tq also contains G.best_router->tq */
if (G.max_tq < G.best_router->tq)
return false;
if ((G.max_tq - G.best_router->tq) <= G.hysteresis_thresh)
return false;
return true;
}
static void update_ebtables(void) {