Update route metric before sending the Sync message

This commit is contained in:
Milos Gajdos 2020-01-17 15:35:51 +00:00
parent 8425ae77f8
commit bf9f319cdf
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F

View File

@ -1293,6 +1293,20 @@ func (n *network) getProtoRoutes() ([]*pbRtr.Route, error) {
// encode the routes to protobuf // encode the routes to protobuf
pbRoutes := make([]*pbRtr.Route, 0, len(routes)) pbRoutes := make([]*pbRtr.Route, 0, len(routes))
for _, route := range routes { for _, route := range routes {
// calculate route metric and add to the advertised metric
// we need to make sure we do not overflow math.MaxInt64
metric := n.getRouteMetric(route.Router, route.Gateway, route.Link)
log.Tracef("Network metric for router %s and gateway %s: %v", route.Router, route.Gateway, metric)
// check we don't overflow max int 64
if d := route.Metric + metric; d <= 0 {
// set to max int64 if we overflow
route.Metric = math.MaxInt64
} else {
// set the combined value of metrics otherwise
route.Metric = d
}
// generate new route proto // generate new route proto
pbRoute := pbUtil.RouteToProto(route) pbRoute := pbUtil.RouteToProto(route)
// mask the route before outbounding // mask the route before outbounding