Skip to content

Commit

Permalink
network: Handle default route where gateway is empty
Browse files Browse the repository at this point in the history
In case of ipvlan plugin, the default route has an empty gateway.
Set this to default gateway value before adding this route with
netlink.

Fixes kata-containers#403

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
  • Loading branch information
amshinde committed Oct 26, 2018
1 parent dd8f32c commit 4005c33
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion network.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ var (
errNoRoutes = grpcStatus.Errorf(codes.InvalidArgument, "Need network routes")
)

const (
// ipvlan plugin adds a route of the format "default dev eth0 scope link"
// Here since source, dest and gateway are empty, netlink will complain.
// Set the gateway address explcitly to handle this, setting this address
// is equivalent to the above route.

defaultV4RouteIP = "0.0.0.0"

// Use the below address for ipv6 gateway once ipv6 support is added
// defaultV6RouteIP = "::"
)

// Network fully describes a sandbox network with its interfaces, routes and dns
// related information.
type network struct {
Expand Down Expand Up @@ -536,6 +548,13 @@ func (s *sandbox) updateRoute(netHandle *netlink.Handle, route *types.Route, add
return grpcStatus.Errorf(codes.Internal, "Could not get link's attributes for device %s", route.Device)
}

// We do not modify the gateway in the list of routes provided,
// since we loop through the routes checking for the gateway again.
gateway := route.Gateway
if route.Dest == "" && route.Gateway == "" && route.Source == "" {
gateway = defaultV4RouteIP
}

var dst *net.IPNet
if route.Dest == "default" || route.Dest == "" {
dst = nil
Expand All @@ -550,7 +569,7 @@ func (s *sandbox) updateRoute(netHandle *netlink.Handle, route *types.Route, add
LinkIndex: linkAttrs.Index,
Dst: dst,
Src: net.ParseIP(route.Source),
Gw: net.ParseIP(route.Gateway),
Gw: net.ParseIP(gateway),
Scope: netlink.Scope(route.Scope),
}

Expand Down

0 comments on commit 4005c33

Please sign in to comment.