Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #158 from clearcontainers/sboeuf/fix_route_removal
Browse files Browse the repository at this point in the history
network: Update route list according to what's on the system
  • Loading branch information
jcvenegas committed Nov 13, 2017
2 parents 4eba663 + 0214486 commit c91e4ab
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,19 @@ func setupInterfaces(netHandle *netlink.Handle, ifaces []hyper.NetIface) error {
return nil
}

func setupRoutes(netHandle *netlink.Handle, routes []hyper.Route) error {
func setupRoutes(netHandle *netlink.Handle, routes *[]hyper.Route) error {
initRouteList, err := netHandle.RouteList(nil, netlink.FAMILY_ALL)
if err != nil {
return err
}

for _, route := range routes {
var finalRouteList []hyper.Route
defer func() {
// Update the route list.
*routes = finalRouteList
}()

for _, route := range *routes {
var dst *net.IPNet
var err error

Expand Down Expand Up @@ -209,6 +215,11 @@ func setupRoutes(netHandle *netlink.Handle, routes []hyper.Route) error {
return fmt.Errorf("Could not add/replace route dest(%s)/src(%s)/gw(%s)/dev(%s): %v",
route.Dest, route.Src, route.Gateway, route.Device, err)
}

// Only save the routes that we are actually adding. Don't add
// skipped routes already existing, otherwise it could cause
// issues when trying to remove them.
finalRouteList = append(finalRouteList, route)
}

return nil
Expand Down Expand Up @@ -239,7 +250,7 @@ func (p *pod) setupNetwork() error {
return fmt.Errorf("Could not setup network interfaces: %v", err)
}

if err := setupRoutes(netHandle, p.network.Routes); err != nil {
if err := setupRoutes(netHandle, &p.network.Routes); err != nil {
return fmt.Errorf("Could not setup network routes: %v", err)
}

Expand Down

0 comments on commit c91e4ab

Please sign in to comment.