Skip to content

Commit

Permalink
network: Don't store the network info as pointers
Browse files Browse the repository at this point in the history
By storing the network information such as routes and interfaces
as pointers, we end up having issues if we try to remove some
elements from the list as the same time this list is parsed through
a for loop.

This allows for a proper duplication of the data, so that we can
actually modify the global lists maintained by the pod, while we
loop over every item of the same lists.

Fixes kata-containers#226

Signed-off-by: Sebastien Boeuf <[email protected]>
  • Loading branch information
Sebastien Boeuf committed Apr 27, 2018
1 parent 74e720e commit acc84bd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
// related information.
type network struct {
ifacesLock sync.Mutex
ifaces []*pb.Interface
ifaces []pb.Interface

routesLock sync.Mutex
routes []*pb.Route
routes []pb.Route

dns []string
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func (s *sandbox) addInterface(netHandle *netlink.Handle, iface *pb.Interface) (
}

// Update sandbox interface list.
s.network.ifaces = append(s.network.ifaces, iface)
s.network.ifaces = append(s.network.ifaces, *iface)

return iface, nil
}
Expand Down Expand Up @@ -465,7 +465,7 @@ func (s *sandbox) updateRoute(netHandle *netlink.Handle, route *pb.Route, add bo
}

// Add route to sandbox route list.
s.network.routes = append(s.network.routes, route)
s.network.routes = append(s.network.routes, *route)
} else {
if err := netHandle.RouteDel(netRoute); err != nil {
return grpcStatus.Errorf(codes.Internal, "Could not remove route dest(%s)/gw(%s)/dev(%s): %v",
Expand Down Expand Up @@ -508,15 +508,17 @@ func (s *sandbox) removeNetwork() error {
}
defer netHandle.Delete()

for _, route := range s.network.routes {
if err := s.removeRoute(netHandle, route); err != nil {
routeList := s.network.routes
for _, route := range routeList {
if err := s.removeRoute(netHandle, &route); err != nil {
return grpcStatus.Errorf(codes.Internal, "Could not remove network route %v: %v",
route, err)
}
}

for _, iface := range s.network.ifaces {
if _, err := s.removeInterface(netHandle, iface); err != nil {
ifaceList := s.network.ifaces
for _, iface := range ifaceList {
if _, err := s.removeInterface(netHandle, &iface); err != nil {
return grpcStatus.Errorf(codes.Internal, "Could not remove network interface %v: %v",
iface, err)
}
Expand Down

0 comments on commit acc84bd

Please sign in to comment.