diff --git a/libnetwork/cmd/ovrouter/ovrouter.go b/libnetwork/cmd/ovrouter/ovrouter.go index 52b2b06828..4222aae11c 100644 --- a/libnetwork/cmd/ovrouter/ovrouter.go +++ b/libnetwork/cmd/ovrouter/ovrouter.go @@ -92,6 +92,8 @@ func (ep *endpoint) AddStaticRoute(destination *net.IPNet, routeType int, return nil } +func (ep *endpoint) DisableGatewayService() {} + func main() { if reexec.Init() { return diff --git a/libnetwork/default_gateway.go b/libnetwork/default_gateway.go index 5d58b06175..d136ab1fc2 100644 --- a/libnetwork/default_gateway.go +++ b/libnetwork/default_gateway.go @@ -103,6 +103,9 @@ func (sb *sandbox) needDefaultGW() bool { if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" { continue } + if ep.joinInfo.disableGatewayService { + return false + } // TODO v6 needs to be handled. if len(ep.Gateway()) > 0 { return false diff --git a/libnetwork/driverapi/driverapi.go b/libnetwork/driverapi/driverapi.go index bd311d0035..44a937fb73 100644 --- a/libnetwork/driverapi/driverapi.go +++ b/libnetwork/driverapi/driverapi.go @@ -91,6 +91,9 @@ type JoinInfo interface { // AddStaticRoute adds a routes to the sandbox. // It may be used in addtion to or instead of a default gateway (as above). AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error + + // DisableGatewayService tells libnetwork not to provide Default GW for the container + DisableGatewayService() } // DriverCallback provides a Callback interface for Drivers into LibNetwork diff --git a/libnetwork/drivers/bridge/bridge_test.go b/libnetwork/drivers/bridge/bridge_test.go index 71de93de0b..e039a53e61 100644 --- a/libnetwork/drivers/bridge/bridge_test.go +++ b/libnetwork/drivers/bridge/bridge_test.go @@ -416,6 +416,8 @@ func (te *testEndpoint) AddStaticRoute(destination *net.IPNet, routeType int, ne return nil } +func (te *testEndpoint) DisableGatewayService() {} + func TestQueryEndpointInfo(t *testing.T) { testQueryEndpointInfo(t, true) } diff --git a/libnetwork/drivers/remote/api/api.go b/libnetwork/drivers/remote/api/api.go index 1d7742e21a..6c9fb09521 100644 --- a/libnetwork/drivers/remote/api/api.go +++ b/libnetwork/drivers/remote/api/api.go @@ -134,10 +134,11 @@ type StaticRoute struct { // JoinResponse is the response to a JoinRequest. type JoinResponse struct { Response - InterfaceName *InterfaceName - Gateway string - GatewayIPv6 string - StaticRoutes []StaticRoute + InterfaceName *InterfaceName + Gateway string + GatewayIPv6 string + StaticRoutes []StaticRoute + DisableGatewayService bool } // LeaveRequest describes the API for detaching an endpoint from a sandbox. diff --git a/libnetwork/drivers/remote/driver.go b/libnetwork/drivers/remote/driver.go index a10698e317..0a7ab1865c 100644 --- a/libnetwork/drivers/remote/driver.go +++ b/libnetwork/drivers/remote/driver.go @@ -231,6 +231,9 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, } } } + if res.DisableGatewayService { + jinfo.DisableGatewayService() + } return nil } diff --git a/libnetwork/drivers/remote/driver_test.go b/libnetwork/drivers/remote/driver_test.go index 61d46e8dea..da1a365df3 100644 --- a/libnetwork/drivers/remote/driver_test.go +++ b/libnetwork/drivers/remote/driver_test.go @@ -64,19 +64,20 @@ func setupPlugin(t *testing.T, name string, mux *http.ServeMux) func() { } type testEndpoint struct { - t *testing.T - src string - dst string - address string - addressIPv6 string - macAddress string - gateway string - gatewayIPv6 string - resolvConfPath string - hostsPath string - nextHop string - destination string - routeType int + t *testing.T + src string + dst string + address string + addressIPv6 string + macAddress string + gateway string + gatewayIPv6 string + resolvConfPath string + hostsPath string + nextHop string + destination string + routeType int + disableGatewayService bool } func (test *testEndpoint) Interface() driverapi.InterfaceInfo { @@ -191,6 +192,10 @@ func (test *testEndpoint) AddStaticRoute(destination *net.IPNet, routeType int, return nil } +func (test *testEndpoint) DisableGatewayService() { + test.disableGatewayService = true +} + func TestGetEmptyCapabilities(t *testing.T) { var plugin = "test-net-driver-empty-cap" @@ -343,7 +348,7 @@ func TestRemoteDriver(t *testing.T) { "DstPrefix": ep.dst, }, "StaticRoutes": []map[string]interface{}{ - map[string]interface{}{ + { "Destination": ep.destination, "RouteType": ep.routeType, "NextHop": ep.nextHop, diff --git a/libnetwork/endpoint_info.go b/libnetwork/endpoint_info.go index 1028308557..c081296933 100644 --- a/libnetwork/endpoint_info.go +++ b/libnetwork/endpoint_info.go @@ -136,9 +136,10 @@ func (epi *endpointInterface) CopyTo(dstEpi *endpointInterface) error { } type endpointJoinInfo struct { - gw net.IP - gw6 net.IP - StaticRoutes []*types.StaticRoute + gw net.IP + gw6 net.IP + StaticRoutes []*types.StaticRoute + disableGatewayService bool } func (ep *endpoint) Info() EndpointInfo { @@ -340,3 +341,10 @@ func (ep *endpoint) retrieveFromStore() (*endpoint, error) { } return n.getEndpointFromStore(ep.ID()) } + +func (ep *endpoint) DisableGatewayService() { + ep.Lock() + defer ep.Unlock() + + ep.joinInfo.disableGatewayService = true +}