diff --git a/network/default.go b/network/default.go index ad83c133..5b961537 100644 --- a/network/default.go +++ b/network/default.go @@ -1293,6 +1293,20 @@ func (n *network) getProtoRoutes() ([]*pbRtr.Route, error) { // encode the routes to protobuf pbRoutes := make([]*pbRtr.Route, 0, len(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 pbRoute := pbUtil.RouteToProto(route) // mask the route before outbounding