Merge pull request #1126 from milosgajdos83/metric-update

Update route metric when receiving Sync routes
This commit is contained in:
Asim Aslam 2020-01-17 18:29:55 +00:00 committed by GitHub
commit fb3927fb8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -935,6 +935,20 @@ func (n *network) processNetChan(listener tunnel.Listener) {
log.Debugf("Network node %s skipping route addition: route already present", n.id)
continue
}
metric := n.getRouteMetric(route.Router, route.Gateway, route.Link)
// 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
}
/////////////////////////////////////////////////////////////////////
// maybe we should not be this clever ¯\_(ツ)_/¯ //
/////////////////////////////////////////////////////////////////////
// lookup best routes for the services in the just received route
q := []router.QueryOption{
router.QueryService(route.Service),
@ -972,6 +986,8 @@ func (n *network) processNetChan(listener tunnel.Listener) {
if bestRoute.Metric <= route.Metric {
continue
}
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// add route to the routing table
if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute {
@ -1293,20 +1309,6 @@ 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
@ -1314,6 +1316,7 @@ func (n *network) getProtoRoutes() ([]*pbRtr.Route, error) {
// add to list of routes
pbRoutes = append(pbRoutes, pbRoute)
}
return pbRoutes, nil
}