Selaa lähdekoodia

libnetwork: Endpoint.AddStaticRoute don't create StaticRoute if unused

This function either had to create a new StaticRoute, or add the destination
to the list of routes. Skip creating a StaticRoute struct if we're not
gonna use it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 vuosi sitten
vanhempi
commit
8c6a46f643
1 muutettua tiedostoa jossa 6 lisäystä ja 5 poistoa
  1. 6 5
      libnetwork/endpoint_info.go

+ 6 - 5
libnetwork/endpoint_info.go

@@ -280,15 +280,16 @@ func (ep *Endpoint) InterfaceName() driverapi.InterfaceNameInfo {
 func (ep *Endpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error {
 func (ep *Endpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error {
 	ep.mu.Lock()
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 	defer ep.mu.Unlock()
-
-	r := types.StaticRoute{Destination: destination, RouteType: routeType, NextHop: nextHop}
-
 	if routeType == types.NEXTHOP {
 	if routeType == types.NEXTHOP {
 		// If the route specifies a next-hop, then it's loosely routed (i.e. not bound to a particular interface).
 		// If the route specifies a next-hop, then it's loosely routed (i.e. not bound to a particular interface).
-		ep.joinInfo.StaticRoutes = append(ep.joinInfo.StaticRoutes, &r)
+		ep.joinInfo.StaticRoutes = append(ep.joinInfo.StaticRoutes, &types.StaticRoute{
+			Destination: destination,
+			RouteType:   routeType,
+			NextHop:     nextHop,
+		})
 	} else {
 	} else {
 		// If the route doesn't specify a next-hop, it must be a connected route, bound to an interface.
 		// If the route doesn't specify a next-hop, it must be a connected route, bound to an interface.
-		ep.iface.routes = append(ep.iface.routes, r.Destination)
+		ep.iface.routes = append(ep.iface.routes, destination)
 	}
 	}
 	return nil
 	return nil
 }
 }