Commit fca59416 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Fix and simplify find_best_route.

This fixes an issue where find_best_route could very occasionally
return a route that was not feasible.
parent f6293140
...@@ -570,7 +570,19 @@ update_feasible(struct source *src, ...@@ -570,7 +570,19 @@ update_feasible(struct source *src,
(src->seqno == seqno && refmetric < src->metric)); (src->seqno == seqno && refmetric < src->metric));
} }
/* This returns the feasible route with the smallest metric. */ static int
route_acceptable(struct babel_route *route, int feasible,
struct neighbour *exclude)
{
if(route_expired(route))
return 0;
if(feasible && !route_feasible(route))
return 0;
if(exclude && route->neigh == exclude)
return 0;
return 1;
}
struct babel_route * struct babel_route *
find_best_route(const unsigned char *prefix, unsigned char plen, int feasible, find_best_route(const unsigned char *prefix, unsigned char plen, int feasible,
struct neighbour *exclude) struct neighbour *exclude)
...@@ -582,16 +594,20 @@ find_best_route(const unsigned char *prefix, unsigned char plen, int feasible, ...@@ -582,16 +594,20 @@ find_best_route(const unsigned char *prefix, unsigned char plen, int feasible,
return NULL; return NULL;
route = routes[i]; route = routes[i];
while(route && !route_acceptable(route, feasible, exclude))
route = route->next;
if(!route)
return NULL;
r = route->next; r = route->next;
while(r) { while(r) {
if(!route_expired(r) && if(route_acceptable(r, feasible, exclude) &&
(!feasible || route_feasible(r)) &&
(!exclude || r->neigh != exclude) &&
(route_metric(r) < route_metric(route))) (route_metric(r) < route_metric(route)))
route = r; route = r;
r = r->next; r = r->next;
} }
return route; return route;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment