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:
parent
6f3c0e34f3
commit
141c51273f
8 changed files with 48 additions and 21 deletions
|
@ -92,6 +92,8 @@ func (ep *endpoint) AddStaticRoute(destination *net.IPNet, routeType int,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ep *endpoint) DisableGatewayService() {}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if reexec.Init() {
|
if reexec.Init() {
|
||||||
return
|
return
|
||||||
|
|
|
@ -103,6 +103,9 @@ func (sb *sandbox) needDefaultGW() bool {
|
||||||
if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" {
|
if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if ep.joinInfo.disableGatewayService {
|
||||||
|
return false
|
||||||
|
}
|
||||||
// TODO v6 needs to be handled.
|
// TODO v6 needs to be handled.
|
||||||
if len(ep.Gateway()) > 0 {
|
if len(ep.Gateway()) > 0 {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -91,6 +91,9 @@ type JoinInfo interface {
|
||||||
// AddStaticRoute adds a routes to the sandbox.
|
// AddStaticRoute adds a routes to the sandbox.
|
||||||
// It may be used in addtion to or instead of a default gateway (as above).
|
// 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
|
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
|
// DriverCallback provides a Callback interface for Drivers into LibNetwork
|
||||||
|
|
|
@ -416,6 +416,8 @@ func (te *testEndpoint) AddStaticRoute(destination *net.IPNet, routeType int, ne
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (te *testEndpoint) DisableGatewayService() {}
|
||||||
|
|
||||||
func TestQueryEndpointInfo(t *testing.T) {
|
func TestQueryEndpointInfo(t *testing.T) {
|
||||||
testQueryEndpointInfo(t, true)
|
testQueryEndpointInfo(t, true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,10 +134,11 @@ type StaticRoute struct {
|
||||||
// JoinResponse is the response to a JoinRequest.
|
// JoinResponse is the response to a JoinRequest.
|
||||||
type JoinResponse struct {
|
type JoinResponse struct {
|
||||||
Response
|
Response
|
||||||
InterfaceName *InterfaceName
|
InterfaceName *InterfaceName
|
||||||
Gateway string
|
Gateway string
|
||||||
GatewayIPv6 string
|
GatewayIPv6 string
|
||||||
StaticRoutes []StaticRoute
|
StaticRoutes []StaticRoute
|
||||||
|
DisableGatewayService bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// LeaveRequest describes the API for detaching an endpoint from a sandbox.
|
// LeaveRequest describes the API for detaching an endpoint from a sandbox.
|
||||||
|
|
|
@ -231,6 +231,9 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if res.DisableGatewayService {
|
||||||
|
jinfo.DisableGatewayService()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,19 +64,20 @@ func setupPlugin(t *testing.T, name string, mux *http.ServeMux) func() {
|
||||||
}
|
}
|
||||||
|
|
||||||
type testEndpoint struct {
|
type testEndpoint struct {
|
||||||
t *testing.T
|
t *testing.T
|
||||||
src string
|
src string
|
||||||
dst string
|
dst string
|
||||||
address string
|
address string
|
||||||
addressIPv6 string
|
addressIPv6 string
|
||||||
macAddress string
|
macAddress string
|
||||||
gateway string
|
gateway string
|
||||||
gatewayIPv6 string
|
gatewayIPv6 string
|
||||||
resolvConfPath string
|
resolvConfPath string
|
||||||
hostsPath string
|
hostsPath string
|
||||||
nextHop string
|
nextHop string
|
||||||
destination string
|
destination string
|
||||||
routeType int
|
routeType int
|
||||||
|
disableGatewayService bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test *testEndpoint) Interface() driverapi.InterfaceInfo {
|
func (test *testEndpoint) Interface() driverapi.InterfaceInfo {
|
||||||
|
@ -191,6 +192,10 @@ func (test *testEndpoint) AddStaticRoute(destination *net.IPNet, routeType int,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (test *testEndpoint) DisableGatewayService() {
|
||||||
|
test.disableGatewayService = true
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetEmptyCapabilities(t *testing.T) {
|
func TestGetEmptyCapabilities(t *testing.T) {
|
||||||
var plugin = "test-net-driver-empty-cap"
|
var plugin = "test-net-driver-empty-cap"
|
||||||
|
|
||||||
|
@ -343,7 +348,7 @@ func TestRemoteDriver(t *testing.T) {
|
||||||
"DstPrefix": ep.dst,
|
"DstPrefix": ep.dst,
|
||||||
},
|
},
|
||||||
"StaticRoutes": []map[string]interface{}{
|
"StaticRoutes": []map[string]interface{}{
|
||||||
map[string]interface{}{
|
{
|
||||||
"Destination": ep.destination,
|
"Destination": ep.destination,
|
||||||
"RouteType": ep.routeType,
|
"RouteType": ep.routeType,
|
||||||
"NextHop": ep.nextHop,
|
"NextHop": ep.nextHop,
|
||||||
|
|
|
@ -136,9 +136,10 @@ func (epi *endpointInterface) CopyTo(dstEpi *endpointInterface) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type endpointJoinInfo struct {
|
type endpointJoinInfo struct {
|
||||||
gw net.IP
|
gw net.IP
|
||||||
gw6 net.IP
|
gw6 net.IP
|
||||||
StaticRoutes []*types.StaticRoute
|
StaticRoutes []*types.StaticRoute
|
||||||
|
disableGatewayService bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep *endpoint) Info() EndpointInfo {
|
func (ep *endpoint) Info() EndpointInfo {
|
||||||
|
@ -340,3 +341,10 @@ func (ep *endpoint) retrieveFromStore() (*endpoint, error) {
|
||||||
}
|
}
|
||||||
return n.getEndpointFromStore(ep.ID())
|
return n.getEndpointFromStore(ep.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ep *endpoint) DisableGatewayService() {
|
||||||
|
ep.Lock()
|
||||||
|
defer ep.Unlock()
|
||||||
|
|
||||||
|
ep.joinInfo.disableGatewayService = true
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue