1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add DisableGatewayService in JoinInfo to offering drivers the ability to disable default gateway

Signed-off-by: Chun Chen <ramichen@tencent.com>
This commit is contained in:
Chun Chen 2015-12-03 10:07:44 +08:00
parent 6f3c0e34f3
commit 141c51273f
8 changed files with 48 additions and 21 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)
}

View file

@ -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.

View file

@ -231,6 +231,9 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
}
}
}
if res.DisableGatewayService {
jinfo.DisableGatewayService()
}
return nil
}

View file

@ -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,

View file

@ -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
}