Commit 33d41c95 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Compute new metrics in change_route_metric itself.

parent 16c818b5
...@@ -235,9 +235,10 @@ switch_routes(struct route *old, struct route *new) ...@@ -235,9 +235,10 @@ switch_routes(struct route *old, struct route *new)
} }
static void static void
change_route_metric(struct route *route, unsigned newmetric) change_route_metric(struct route *route, unsigned cost, unsigned add)
{ {
int old, new; int old, new;
int newmetric = MIN(route->refmetric + cost + add, INFINITY);
if(route_metric(route) == newmetric) if(route_metric(route) == newmetric)
return; return;
...@@ -266,7 +267,7 @@ static void ...@@ -266,7 +267,7 @@ static void
retract_route(struct route *route) retract_route(struct route *route)
{ {
route->refmetric = INFINITY; route->refmetric = INFINITY;
change_route_metric(route, INFINITY); change_route_metric(route, INFINITY, 0);
} }
int int
...@@ -348,16 +349,11 @@ update_route_metric(struct route *route) ...@@ -348,16 +349,11 @@ update_route_metric(struct route *route)
route->src->prefix, route->src->plen, route->src->prefix, route->src->plen,
neigh->address, neigh->address,
neigh->network->ifindex); neigh->network->ifindex);
int newmetric = MIN(route->refmetric + change_route_metric(route,
add_metric + neighbour_cost(route->neigh), add_metric);
neighbour_cost(route->neigh), if(route_metric(route) != oldmetric)
INFINITY);
if(newmetric != oldmetric) {
change_route_metric(route, newmetric);
route_changed(route, route->src, oldmetric); route_changed(route, route->src, oldmetric);
} }
}
} }
void void
...@@ -420,7 +416,6 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen, ...@@ -420,7 +416,6 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
feasible = update_feasible(src, seqno, refmetric); feasible = update_feasible(src, seqno, refmetric);
route = find_route(p, plen, neigh, nexthop); route = find_route(p, plen, neigh, nexthop);
metric = MIN((int)refmetric + neighbour_cost(neigh) + add_metric, INFINITY); metric = MIN((int)refmetric + neighbour_cost(neigh) + add_metric, INFINITY);
if(route) { if(route) {
struct source *oldsrc; struct source *oldsrc;
unsigned short oldmetric; unsigned short oldmetric;
...@@ -451,7 +446,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen, ...@@ -451,7 +446,7 @@ update_route(const unsigned char *a, const unsigned char *p, unsigned char plen,
route->time = now.tv_sec; route->time = now.tv_sec;
route->seqno = seqno; route->seqno = seqno;
route->refmetric = refmetric; route->refmetric = refmetric;
change_route_metric(route, metric); change_route_metric(route, neighbour_cost(neigh), add_metric);
route->hold_time = hold_time; route->hold_time = hold_time;
route_changed(route, oldsrc, oldmetric); route_changed(route, oldsrc, oldmetric);
......
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