mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #199 from aboch/rest
Support network options in rest api
This commit is contained in:
commit
35672dacaf
28 changed files with 325 additions and 156 deletions
|
@ -16,7 +16,7 @@ var (
|
||||||
successResponse = responseStatus{Status: "Success", StatusCode: http.StatusOK}
|
successResponse = responseStatus{Status: "Success", StatusCode: http.StatusOK}
|
||||||
createdResponse = responseStatus{Status: "Created", StatusCode: http.StatusCreated}
|
createdResponse = responseStatus{Status: "Created", StatusCode: http.StatusCreated}
|
||||||
mismatchResponse = responseStatus{Status: "Body/URI parameter mismatch", StatusCode: http.StatusBadRequest}
|
mismatchResponse = responseStatus{Status: "Body/URI parameter mismatch", StatusCode: http.StatusBadRequest}
|
||||||
badQueryresponse = responseStatus{Status: "Unsupported query", StatusCode: http.StatusBadRequest}
|
badQueryResponse = responseStatus{Status: "Unsupported query", StatusCode: http.StatusBadRequest}
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -170,9 +170,19 @@ func buildEndpointResource(ep libnetwork.Endpoint) *endpointResource {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************
|
/****************
|
||||||
Options Parser
|
Options Parsers
|
||||||
***************/
|
*****************/
|
||||||
|
|
||||||
|
func (nc *networkCreate) parseOptions() []libnetwork.NetworkOption {
|
||||||
|
var setFctList []libnetwork.NetworkOption
|
||||||
|
|
||||||
|
if nc.Options != nil {
|
||||||
|
setFctList = append(setFctList, libnetwork.NetworkOptionGeneric(nc.Options))
|
||||||
|
}
|
||||||
|
|
||||||
|
return setFctList
|
||||||
|
}
|
||||||
|
|
||||||
func (ej *endpointJoin) parseOptions() []libnetwork.EndpointOption {
|
func (ej *endpointJoin) parseOptions() []libnetwork.EndpointOption {
|
||||||
var setFctList []libnetwork.EndpointOption
|
var setFctList []libnetwork.EndpointOption
|
||||||
|
@ -224,7 +234,7 @@ func procCreateNetwork(c libnetwork.NetworkController, vars map[string]string, b
|
||||||
return "", &responseStatus{Status: "Invalid body: " + err.Error(), StatusCode: http.StatusBadRequest}
|
return "", &responseStatus{Status: "Invalid body: " + err.Error(), StatusCode: http.StatusBadRequest}
|
||||||
}
|
}
|
||||||
|
|
||||||
nw, err := c.NewNetwork(create.NetworkType, create.Name, nil)
|
nw, err := c.NewNetwork(create.NetworkType, create.Name, create.parseOptions()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", convertNetworkError(err)
|
return "", convertNetworkError(err)
|
||||||
}
|
}
|
||||||
|
@ -248,7 +258,7 @@ func procGetNetworks(c libnetwork.NetworkController, vars map[string]string, bod
|
||||||
name, queryByName := vars[urlNwName]
|
name, queryByName := vars[urlNwName]
|
||||||
shortID, queryByPid := vars[urlNwPID]
|
shortID, queryByPid := vars[urlNwPID]
|
||||||
if queryByName && queryByPid {
|
if queryByName && queryByPid {
|
||||||
return nil, &badQueryresponse
|
return nil, &badQueryResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
if queryByName {
|
if queryByName {
|
||||||
|
@ -323,7 +333,7 @@ func procGetEndpoints(c libnetwork.NetworkController, vars map[string]string, bo
|
||||||
name, queryByName := vars[urlEpName]
|
name, queryByName := vars[urlEpName]
|
||||||
shortID, queryByPid := vars[urlEpPID]
|
shortID, queryByPid := vars[urlEpPID]
|
||||||
if queryByName && queryByPid {
|
if queryByName && queryByPid {
|
||||||
return nil, &badQueryresponse
|
return nil, &badQueryResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
nwT, nwBy := detectNetworkTarget(vars)
|
nwT, nwBy := detectNetworkTarget(vars)
|
||||||
|
|
|
@ -78,6 +78,25 @@ func i2nL(i interface{}) []*networkResource {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createTestNetwork(t *testing.T, network string) (libnetwork.NetworkController, libnetwork.Network) {
|
||||||
|
c, err := libnetwork.New()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = c.ConfigureNetworkDriver(bridgeNetType, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
nw, err := c.NewNetwork(bridgeNetType, network, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, nw
|
||||||
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
if reexec.Init() {
|
if reexec.Init() {
|
||||||
return
|
return
|
||||||
|
@ -184,8 +203,15 @@ func TestCreateDeleteNetwork(t *testing.T) {
|
||||||
t.Fatalf("Expected StatusBadRequest status code, got: %v", errRsp)
|
t.Fatalf("Expected StatusBadRequest status code, got: %v", errRsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
ops := make(map[string]interface{})
|
ops := options.Generic{
|
||||||
ops[netlabel.GenericData] = options.Generic{}
|
netlabel.EnableIPv6: true,
|
||||||
|
netlabel.GenericData: map[string]string{
|
||||||
|
"BridgeName": "abc",
|
||||||
|
"AllowNonDefaultBridge": "true",
|
||||||
|
"FixedCIDRv6": "fe80::1/64",
|
||||||
|
"AddressIP": "172.28.30.254/24",
|
||||||
|
},
|
||||||
|
}
|
||||||
nc := networkCreate{Name: "network_1", NetworkType: bridgeNetType, Options: ops}
|
nc := networkCreate{Name: "network_1", NetworkType: bridgeNetType, Options: ops}
|
||||||
goodBody, err := json.Marshal(nc)
|
goodBody, err := json.Marshal(nc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -498,19 +524,7 @@ func TestDetectGetNetworksInvalidQueryComposition(t *testing.T) {
|
||||||
func TestDetectGetEndpointsInvalidQueryComposition(t *testing.T) {
|
func TestDetectGetEndpointsInvalidQueryComposition(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
|
|
||||||
c, err := libnetwork.New()
|
c, _ := createTestNetwork(t, "network")
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
err = c.ConfigureNetworkDriver(bridgeNetType, nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = c.NewNetwork(bridgeNetType, "network", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
vars := map[string]string{urlNwName: "network", urlEpName: "x", urlEpPID: "y"}
|
vars := map[string]string{urlNwName: "network", urlEpName: "x", urlEpPID: "y"}
|
||||||
_, errRsp := procGetEndpoints(c, vars, nil)
|
_, errRsp := procGetEndpoints(c, vars, nil)
|
||||||
|
@ -522,19 +536,7 @@ func TestDetectGetEndpointsInvalidQueryComposition(t *testing.T) {
|
||||||
func TestFindNetworkUtil(t *testing.T) {
|
func TestFindNetworkUtil(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
|
|
||||||
c, err := libnetwork.New()
|
c, nw := createTestNetwork(t, "network")
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
err = c.ConfigureNetworkDriver(bridgeNetType, nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
nw, err := c.NewNetwork(bridgeNetType, "network", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
nid := nw.ID()
|
nid := nw.ID()
|
||||||
|
|
||||||
defer checkPanic(t)
|
defer checkPanic(t)
|
||||||
|
@ -880,19 +882,7 @@ func TestJoinLeave(t *testing.T) {
|
||||||
func TestFindEndpointUtil(t *testing.T) {
|
func TestFindEndpointUtil(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
|
|
||||||
c, err := libnetwork.New()
|
c, nw := createTestNetwork(t, "network")
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
err = c.ConfigureNetworkDriver(bridgeNetType, nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
nw, err := c.NewNetwork(bridgeNetType, "second", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
nid := nw.ID()
|
nid := nw.ID()
|
||||||
|
|
||||||
ep, err := nw.CreateEndpoint("secondEp", nil)
|
ep, err := nw.CreateEndpoint("secondEp", nil)
|
||||||
|
@ -1228,8 +1218,22 @@ func TestEndToEnd(t *testing.T) {
|
||||||
}
|
}
|
||||||
handleRequest := NewHTTPHandler(c)
|
handleRequest := NewHTTPHandler(c)
|
||||||
|
|
||||||
|
ops := options.Generic{
|
||||||
|
netlabel.EnableIPv6: true,
|
||||||
|
netlabel.GenericData: map[string]string{
|
||||||
|
"BridgeName": "cdef",
|
||||||
|
"FixedCIDRv6": "fe80:2000::1/64",
|
||||||
|
"EnableIPv6": "true",
|
||||||
|
"Mtu": "1460",
|
||||||
|
"EnableIPTables": "true",
|
||||||
|
"AddressIP": "172.28.30.254/16",
|
||||||
|
"EnableUserlandProxy": "true",
|
||||||
|
"AllowNonDefaultBridge": "true",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// Create network
|
// Create network
|
||||||
nc := networkCreate{Name: "network-fiftyfive", NetworkType: bridgeNetType}
|
nc := networkCreate{Name: "network-fiftyfive", NetworkType: bridgeNetType, Options: ops}
|
||||||
body, err := json.Marshal(nc)
|
body, err := json.Marshal(nc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
|
"github.com/docker/libnetwork/netlabel"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -54,7 +55,17 @@ func (cli *NetworkCli) CmdNetworkCreate(chain string, args ...string) error {
|
||||||
*flDriver = nullNetType
|
*flDriver = nullNetType
|
||||||
}
|
}
|
||||||
|
|
||||||
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver}
|
// Construct network create request body
|
||||||
|
ops := make(map[string]interface{})
|
||||||
|
nc := networkCreate{Name: cmd.Arg(0), NetworkType: *flDriver, Options: ops}
|
||||||
|
|
||||||
|
// Set driver specific options
|
||||||
|
if *flDriver == "bridge" {
|
||||||
|
ops[netlabel.GenericData] = map[string]string{
|
||||||
|
"BridgeName": cmd.Arg(0),
|
||||||
|
"AllowNonDefaultBridge": "true",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
|
obj, _, err := readBody(cli.call("POST", "/networks", nc, nil))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package bridge
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -31,13 +32,13 @@ var (
|
||||||
portMapper *portmapper.PortMapper
|
portMapper *portmapper.PortMapper
|
||||||
)
|
)
|
||||||
|
|
||||||
// Configuration info for the "bridge" driver.
|
// configuration info for the "bridge" driver.
|
||||||
type Configuration struct {
|
type configuration struct {
|
||||||
EnableIPForwarding bool
|
EnableIPForwarding bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkConfiguration for network specific configuration
|
// networkConfiguration for network specific configuration
|
||||||
type NetworkConfiguration struct {
|
type networkConfiguration struct {
|
||||||
BridgeName string
|
BridgeName string
|
||||||
AddressIPv4 *net.IPNet
|
AddressIPv4 *net.IPNet
|
||||||
FixedCIDR *net.IPNet
|
FixedCIDR *net.IPNet
|
||||||
|
@ -54,15 +55,15 @@ type NetworkConfiguration struct {
|
||||||
EnableUserlandProxy bool
|
EnableUserlandProxy bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// EndpointConfiguration represents the user specified configuration for the sandbox endpoint
|
// endpointConfiguration represents the user specified configuration for the sandbox endpoint
|
||||||
type EndpointConfiguration struct {
|
type endpointConfiguration struct {
|
||||||
MacAddress net.HardwareAddr
|
MacAddress net.HardwareAddr
|
||||||
PortBindings []types.PortBinding
|
PortBindings []types.PortBinding
|
||||||
ExposedPorts []types.TransportPort
|
ExposedPorts []types.TransportPort
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerConfiguration represents the user specified configuration for a container
|
// containerConfiguration represents the user specified configuration for a container
|
||||||
type ContainerConfiguration struct {
|
type containerConfiguration struct {
|
||||||
ParentEndpoints []string
|
ParentEndpoints []string
|
||||||
ChildEndpoints []string
|
ChildEndpoints []string
|
||||||
}
|
}
|
||||||
|
@ -71,21 +72,21 @@ type bridgeEndpoint struct {
|
||||||
id types.UUID
|
id types.UUID
|
||||||
intf *sandbox.Interface
|
intf *sandbox.Interface
|
||||||
macAddress net.HardwareAddr
|
macAddress net.HardwareAddr
|
||||||
config *EndpointConfiguration // User specified parameters
|
config *endpointConfiguration // User specified parameters
|
||||||
containerConfig *ContainerConfiguration
|
containerConfig *containerConfiguration
|
||||||
portMapping []types.PortBinding // Operation port bindings
|
portMapping []types.PortBinding // Operation port bindings
|
||||||
}
|
}
|
||||||
|
|
||||||
type bridgeNetwork struct {
|
type bridgeNetwork struct {
|
||||||
id types.UUID
|
id types.UUID
|
||||||
bridge *bridgeInterface // The bridge's L3 interface
|
bridge *bridgeInterface // The bridge's L3 interface
|
||||||
config *NetworkConfiguration
|
config *networkConfiguration
|
||||||
endpoints map[types.UUID]*bridgeEndpoint // key: endpoint id
|
endpoints map[types.UUID]*bridgeEndpoint // key: endpoint id
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type driver struct {
|
type driver struct {
|
||||||
config *Configuration
|
config *configuration
|
||||||
network *bridgeNetwork
|
network *bridgeNetwork
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
@ -107,7 +108,7 @@ func Init(dc driverapi.DriverCallback) error {
|
||||||
|
|
||||||
// Validate performs a static validation on the network configuration parameters.
|
// Validate performs a static validation on the network configuration parameters.
|
||||||
// Whatever can be assessed a priori before attempting any programming.
|
// Whatever can be assessed a priori before attempting any programming.
|
||||||
func (c *NetworkConfiguration) Validate() error {
|
func (c *networkConfiguration) Validate() error {
|
||||||
if c.Mtu < 0 {
|
if c.Mtu < 0 {
|
||||||
return ErrInvalidMtu(c.Mtu)
|
return ErrInvalidMtu(c.Mtu)
|
||||||
}
|
}
|
||||||
|
@ -145,6 +146,147 @@ func (c *NetworkConfiguration) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FromMap retrieve the configuration data from the map form.
|
||||||
|
func (c *networkConfiguration) FromMap(data map[string]interface{}) error {
|
||||||
|
if i, ok := data["BridgeName"]; ok && i != nil {
|
||||||
|
if c.BridgeName, ok = i.(string); !ok {
|
||||||
|
return types.BadRequestErrorf("invalid type for BridgeName value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if i, ok := data["Mtu"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if c.Mtu, err = strconv.Atoi(s); err != nil {
|
||||||
|
return types.BadRequestErrorf("failed to parse Mtu value: %s", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for Mtu value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i, ok := data["EnableIPv6"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if c.EnableIPv6, err = strconv.ParseBool(s); err != nil {
|
||||||
|
return types.BadRequestErrorf("failed to parse EnableIPv6 value: %s", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for EnableIPv6 value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i, ok := data["EnableIPTables"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if c.EnableIPTables, err = strconv.ParseBool(s); err != nil {
|
||||||
|
return types.BadRequestErrorf("failed to parse EnableIPTables value: %s", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for EnableIPTables value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i, ok := data["EnableIPMasquerade"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if c.EnableIPMasquerade, err = strconv.ParseBool(s); err != nil {
|
||||||
|
return types.BadRequestErrorf("failed to parse EnableIPMasquerade value: %s", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for EnableIPMasquerade value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i, ok := data["EnableICC"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if c.EnableICC, err = strconv.ParseBool(s); err != nil {
|
||||||
|
return types.BadRequestErrorf("failed to parse EnableICC value: %s", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for EnableICC value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i, ok := data["AllowNonDefaultBridge"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if c.AllowNonDefaultBridge, err = strconv.ParseBool(s); err != nil {
|
||||||
|
return types.BadRequestErrorf("failed to parse AllowNonDefaultBridge value: %s", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for AllowNonDefaultBridge value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i, ok := data["AddressIPv4"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if ip, nw, e := net.ParseCIDR(s); e == nil {
|
||||||
|
nw.IP = ip
|
||||||
|
c.AddressIPv4 = nw
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("failed to parse AddressIPv4 value")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for AddressIPv4 value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i, ok := data["FixedCIDR"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if ip, nw, e := net.ParseCIDR(s); e == nil {
|
||||||
|
nw.IP = ip
|
||||||
|
c.FixedCIDR = nw
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("failed to parse FixedCIDR value")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for FixedCIDR value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i, ok := data["FixedCIDRv6"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if ip, nw, e := net.ParseCIDR(s); e == nil {
|
||||||
|
nw.IP = ip
|
||||||
|
c.FixedCIDRv6 = nw
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("failed to parse FixedCIDRv6 value")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for FixedCIDRv6 value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i, ok := data["DefaultGatewayIPv4"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if c.DefaultGatewayIPv4 = net.ParseIP(s); c.DefaultGatewayIPv4 == nil {
|
||||||
|
return types.BadRequestErrorf("failed to parse DefaultGatewayIPv4 value")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for DefaultGatewayIPv4 value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i, ok := data["DefaultGatewayIPv6"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if c.DefaultGatewayIPv6 = net.ParseIP(s); c.DefaultGatewayIPv6 == nil {
|
||||||
|
return types.BadRequestErrorf("failed to parse DefaultGatewayIPv6 value")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for DefaultGatewayIPv6 value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i, ok := data["DefaultBindingIP"]; ok && i != nil {
|
||||||
|
if s, ok := i.(string); ok {
|
||||||
|
if c.DefaultBindingIP = net.ParseIP(s); c.DefaultBindingIP == nil {
|
||||||
|
return types.BadRequestErrorf("failed to parse DefaultBindingIP value")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return types.BadRequestErrorf("invalid type for DefaultBindingIP value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (n *bridgeNetwork) getEndpoint(eid types.UUID) (*bridgeEndpoint, error) {
|
func (n *bridgeNetwork) getEndpoint(eid types.UUID) (*bridgeEndpoint, error) {
|
||||||
n.Lock()
|
n.Lock()
|
||||||
defer n.Unlock()
|
defer n.Unlock()
|
||||||
|
@ -161,7 +303,7 @@ func (n *bridgeNetwork) getEndpoint(eid types.UUID) (*bridgeEndpoint, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *driver) Config(option map[string]interface{}) error {
|
func (d *driver) Config(option map[string]interface{}) error {
|
||||||
var config *Configuration
|
var config *configuration
|
||||||
|
|
||||||
d.Lock()
|
d.Lock()
|
||||||
defer d.Unlock()
|
defer d.Unlock()
|
||||||
|
@ -174,12 +316,12 @@ func (d *driver) Config(option map[string]interface{}) error {
|
||||||
if ok && genericData != nil {
|
if ok && genericData != nil {
|
||||||
switch opt := genericData.(type) {
|
switch opt := genericData.(type) {
|
||||||
case options.Generic:
|
case options.Generic:
|
||||||
opaqueConfig, err := options.GenerateFromModel(opt, &Configuration{})
|
opaqueConfig, err := options.GenerateFromModel(opt, &configuration{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
config = opaqueConfig.(*Configuration)
|
config = opaqueConfig.(*configuration)
|
||||||
case *Configuration:
|
case *configuration:
|
||||||
config = opt
|
config = opt
|
||||||
default:
|
default:
|
||||||
return &ErrInvalidDriverConfig{}
|
return &ErrInvalidDriverConfig{}
|
||||||
|
@ -187,7 +329,7 @@ func (d *driver) Config(option map[string]interface{}) error {
|
||||||
|
|
||||||
d.config = config
|
d.config = config
|
||||||
} else {
|
} else {
|
||||||
config = &Configuration{}
|
config = &configuration{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.EnableIPForwarding {
|
if config.EnableIPForwarding {
|
||||||
|
@ -205,30 +347,30 @@ func (d *driver) getNetwork(id types.UUID) (*bridgeNetwork, error) {
|
||||||
return d.network, nil
|
return d.network, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseNetworkOptions(option options.Generic) (*NetworkConfiguration, error) {
|
func parseNetworkOptions(option options.Generic) (*networkConfiguration, error) {
|
||||||
var config *NetworkConfiguration
|
config := &networkConfiguration{}
|
||||||
|
if genData, ok := option[netlabel.GenericData]; ok && genData != nil {
|
||||||
|
switch opt := genData.(type) {
|
||||||
|
|
||||||
genericData, ok := option[netlabel.GenericData]
|
case map[string]interface{}:
|
||||||
if ok && genericData != nil {
|
if err := config.FromMap(opt); err != nil {
|
||||||
switch opt := genericData.(type) {
|
return nil, err
|
||||||
|
}
|
||||||
case options.Generic:
|
case options.Generic:
|
||||||
opaqueConfig, err := options.GenerateFromModel(opt, &NetworkConfiguration{})
|
opaqueConfig, err := options.GenerateFromModel(opt, &networkConfiguration{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config = opaqueConfig.(*NetworkConfiguration)
|
config = opaqueConfig.(*networkConfiguration)
|
||||||
case *NetworkConfiguration:
|
case *networkConfiguration:
|
||||||
config = opt
|
config = opt
|
||||||
default:
|
default:
|
||||||
return nil, &ErrInvalidNetworkConfig{}
|
return nil, types.BadRequestErrorf("do not recognize network configuration format: %T", opt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := config.Validate(); err != nil {
|
if err := config.Validate(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
config = &NetworkConfiguration{}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := option[netlabel.EnableIPv6]; ok {
|
if _, ok := option[netlabel.EnableIPv6]; ok {
|
||||||
config.EnableIPv6 = option[netlabel.EnableIPv6].(bool)
|
config.EnableIPv6 = option[netlabel.EnableIPv6].(bool)
|
||||||
|
@ -754,7 +896,7 @@ func (d *driver) Leave(nid, eid types.UUID) error {
|
||||||
|
|
||||||
func (d *driver) link(network *bridgeNetwork, endpoint *bridgeEndpoint, options map[string]interface{}, enable bool) error {
|
func (d *driver) link(network *bridgeNetwork, endpoint *bridgeEndpoint, options map[string]interface{}, enable bool) error {
|
||||||
var (
|
var (
|
||||||
cc *ContainerConfiguration
|
cc *containerConfiguration
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -845,12 +987,12 @@ func (d *driver) Type() string {
|
||||||
return networkType
|
return networkType
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseEndpointOptions(epOptions map[string]interface{}) (*EndpointConfiguration, error) {
|
func parseEndpointOptions(epOptions map[string]interface{}) (*endpointConfiguration, error) {
|
||||||
if epOptions == nil {
|
if epOptions == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ec := &EndpointConfiguration{}
|
ec := &endpointConfiguration{}
|
||||||
|
|
||||||
if opt, ok := epOptions[netlabel.MacAddress]; ok {
|
if opt, ok := epOptions[netlabel.MacAddress]; ok {
|
||||||
if mac, ok := opt.(net.HardwareAddr); ok {
|
if mac, ok := opt.(net.HardwareAddr); ok {
|
||||||
|
@ -879,7 +1021,7 @@ func parseEndpointOptions(epOptions map[string]interface{}) (*EndpointConfigurat
|
||||||
return ec, nil
|
return ec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseContainerOptions(cOptions map[string]interface{}) (*ContainerConfiguration, error) {
|
func parseContainerOptions(cOptions map[string]interface{}) (*containerConfiguration, error) {
|
||||||
if cOptions == nil {
|
if cOptions == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -889,19 +1031,19 @@ func parseContainerOptions(cOptions map[string]interface{}) (*ContainerConfigura
|
||||||
}
|
}
|
||||||
switch opt := genericData.(type) {
|
switch opt := genericData.(type) {
|
||||||
case options.Generic:
|
case options.Generic:
|
||||||
opaqueConfig, err := options.GenerateFromModel(opt, &ContainerConfiguration{})
|
opaqueConfig, err := options.GenerateFromModel(opt, &containerConfiguration{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return opaqueConfig.(*ContainerConfiguration), nil
|
return opaqueConfig.(*containerConfiguration), nil
|
||||||
case *ContainerConfiguration:
|
case *containerConfiguration:
|
||||||
return opt, nil
|
return opt, nil
|
||||||
default:
|
default:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func electMacAddress(epConfig *EndpointConfiguration) net.HardwareAddr {
|
func electMacAddress(epConfig *endpointConfiguration) net.HardwareAddr {
|
||||||
if epConfig != nil && epConfig.MacAddress != nil {
|
if epConfig != nil && epConfig.MacAddress != nil {
|
||||||
return epConfig.MacAddress
|
return epConfig.MacAddress
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ func TestCreateFullOptions(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
d := newDriver()
|
d := newDriver()
|
||||||
|
|
||||||
config := &Configuration{
|
config := &configuration{
|
||||||
EnableIPForwarding: true,
|
EnableIPForwarding: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
netConfig := &NetworkConfiguration{
|
netConfig := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
EnableIPv6: true,
|
EnableIPv6: true,
|
||||||
FixedCIDR: bridgeNetworks[0],
|
FixedCIDR: bridgeNetworks[0],
|
||||||
|
@ -50,7 +50,7 @@ func TestCreate(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
d := newDriver()
|
d := newDriver()
|
||||||
|
|
||||||
config := &NetworkConfiguration{BridgeName: DefaultBridgeName}
|
config := &networkConfiguration{BridgeName: DefaultBridgeName}
|
||||||
genericOption := make(map[string]interface{})
|
genericOption := make(map[string]interface{})
|
||||||
genericOption[netlabel.GenericData] = config
|
genericOption[netlabel.GenericData] = config
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ func TestCreateFail(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
d := newDriver()
|
d := newDriver()
|
||||||
|
|
||||||
config := &NetworkConfiguration{BridgeName: "dummy0"}
|
config := &networkConfiguration{BridgeName: "dummy0"}
|
||||||
genericOption := make(map[string]interface{})
|
genericOption := make(map[string]interface{})
|
||||||
genericOption[netlabel.GenericData] = config
|
genericOption[netlabel.GenericData] = config
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) {
|
||||||
d := newDriver()
|
d := newDriver()
|
||||||
dd, _ := d.(*driver)
|
dd, _ := d.(*driver)
|
||||||
|
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
EnableIPTables: true,
|
EnableIPTables: true,
|
||||||
EnableICC: false,
|
EnableICC: false,
|
||||||
|
@ -227,7 +227,7 @@ func TestCreateLinkWithOptions(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
d := newDriver()
|
d := newDriver()
|
||||||
|
|
||||||
config := &NetworkConfiguration{BridgeName: DefaultBridgeName}
|
config := &networkConfiguration{BridgeName: DefaultBridgeName}
|
||||||
netOptions := make(map[string]interface{})
|
netOptions := make(map[string]interface{})
|
||||||
netOptions[netlabel.GenericData] = config
|
netOptions[netlabel.GenericData] = config
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ func TestLinkContainers(t *testing.T) {
|
||||||
|
|
||||||
d := newDriver()
|
d := newDriver()
|
||||||
|
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
EnableIPTables: true,
|
EnableIPTables: true,
|
||||||
EnableICC: false,
|
EnableICC: false,
|
||||||
|
@ -323,7 +323,7 @@ func TestLinkContainers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ce := []string{"ep1"}
|
ce := []string{"ep1"}
|
||||||
cConfig := &ContainerConfiguration{ChildEndpoints: ce}
|
cConfig := &containerConfiguration{ChildEndpoints: ce}
|
||||||
genericOption = make(map[string]interface{})
|
genericOption = make(map[string]interface{})
|
||||||
genericOption[netlabel.GenericData] = cConfig
|
genericOption[netlabel.GenericData] = cConfig
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ func TestLinkContainers(t *testing.T) {
|
||||||
|
|
||||||
// Error condition test with an invalid endpoint-id "ep4"
|
// Error condition test with an invalid endpoint-id "ep4"
|
||||||
ce = []string{"ep1", "ep4"}
|
ce = []string{"ep1", "ep4"}
|
||||||
cConfig = &ContainerConfiguration{ChildEndpoints: ce}
|
cConfig = &containerConfiguration{ChildEndpoints: ce}
|
||||||
genericOption = make(map[string]interface{})
|
genericOption = make(map[string]interface{})
|
||||||
genericOption[netlabel.GenericData] = cConfig
|
genericOption[netlabel.GenericData] = cConfig
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ func TestLinkContainers(t *testing.T) {
|
||||||
func TestValidateConfig(t *testing.T) {
|
func TestValidateConfig(t *testing.T) {
|
||||||
|
|
||||||
// Test mtu
|
// Test mtu
|
||||||
c := NetworkConfiguration{Mtu: -2}
|
c := networkConfiguration{Mtu: -2}
|
||||||
err := c.Validate()
|
err := c.Validate()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Failed to detect invalid MTU number")
|
t.Fatalf("Failed to detect invalid MTU number")
|
||||||
|
@ -417,7 +417,7 @@ func TestValidateConfig(t *testing.T) {
|
||||||
|
|
||||||
// Test FixedCIDR
|
// Test FixedCIDR
|
||||||
_, containerSubnet, _ := net.ParseCIDR("172.27.0.0/16")
|
_, containerSubnet, _ := net.ParseCIDR("172.27.0.0/16")
|
||||||
c = NetworkConfiguration{
|
c = networkConfiguration{
|
||||||
AddressIPv4: network,
|
AddressIPv4: network,
|
||||||
FixedCIDR: containerSubnet,
|
FixedCIDR: containerSubnet,
|
||||||
}
|
}
|
||||||
|
@ -463,7 +463,7 @@ func TestValidateConfig(t *testing.T) {
|
||||||
|
|
||||||
// Test v6 gw
|
// Test v6 gw
|
||||||
_, containerSubnet, _ = net.ParseCIDR("2001:1234:ae:b004::/64")
|
_, containerSubnet, _ = net.ParseCIDR("2001:1234:ae:b004::/64")
|
||||||
c = NetworkConfiguration{
|
c = networkConfiguration{
|
||||||
EnableIPv6: true,
|
EnableIPv6: true,
|
||||||
FixedCIDRv6: containerSubnet,
|
FixedCIDRv6: containerSubnet,
|
||||||
DefaultGatewayIPv6: net.ParseIP("2001:1234:ac:b004::bad:a55"),
|
DefaultGatewayIPv6: net.ParseIP("2001:1234:ac:b004::bad:a55"),
|
||||||
|
@ -495,7 +495,7 @@ func TestSetDefaultGw(t *testing.T) {
|
||||||
gw4[3] = 254
|
gw4[3] = 254
|
||||||
gw6 := net.ParseIP("2001:db8:ea9:9abc:b0c4::254")
|
gw6 := net.ParseIP("2001:db8:ea9:9abc:b0c4::254")
|
||||||
|
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
EnableIPv6: true,
|
EnableIPv6: true,
|
||||||
FixedCIDRv6: subnetv6,
|
FixedCIDRv6: subnetv6,
|
||||||
|
|
|
@ -22,10 +22,10 @@ type bridgeInterface struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newInterface creates a new bridge interface structure. It attempts to find
|
// newInterface creates a new bridge interface structure. It attempts to find
|
||||||
// an already existing device identified by the Configuration BridgeName field,
|
// an already existing device identified by the configuration BridgeName field,
|
||||||
// or the default bridge name when unspecified), but doesn't attempt to create
|
// or the default bridge name when unspecified), but doesn't attempt to create
|
||||||
// one when missing
|
// one when missing
|
||||||
func newInterface(config *NetworkConfiguration) *bridgeInterface {
|
func newInterface(config *networkConfiguration) *bridgeInterface {
|
||||||
i := &bridgeInterface{}
|
i := &bridgeInterface{}
|
||||||
|
|
||||||
// Initialize the bridge name to the default if unspecified.
|
// Initialize the bridge name to the default if unspecified.
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
func TestInterfaceDefaultName(t *testing.T) {
|
func TestInterfaceDefaultName(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
|
|
||||||
config := &NetworkConfiguration{}
|
config := &networkConfiguration{}
|
||||||
if _ = newInterface(config); config.BridgeName != DefaultBridgeName {
|
if _ = newInterface(config); config.BridgeName != DefaultBridgeName {
|
||||||
t.Fatalf("Expected default interface name %q, got %q", DefaultBridgeName, config.BridgeName)
|
t.Fatalf("Expected default interface name %q, got %q", DefaultBridgeName, config.BridgeName)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func TestInterfaceDefaultName(t *testing.T) {
|
||||||
func TestAddressesEmptyInterface(t *testing.T) {
|
func TestAddressesEmptyInterface(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
|
|
||||||
inf := newInterface(&NetworkConfiguration{})
|
inf := newInterface(&networkConfiguration{})
|
||||||
addrv4, addrsv6, err := inf.addresses()
|
addrv4, addrsv6, err := inf.addresses()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to get addresses of default interface: %v", err)
|
t.Fatalf("Failed to get addresses of default interface: %v", err)
|
||||||
|
|
|
@ -15,7 +15,7 @@ func TestLinkCreate(t *testing.T) {
|
||||||
dr := d.(*driver)
|
dr := d.(*driver)
|
||||||
|
|
||||||
mtu := 1490
|
mtu := 1490
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
Mtu: mtu,
|
Mtu: mtu,
|
||||||
EnableIPv6: true,
|
EnableIPv6: true,
|
||||||
|
@ -105,7 +105,7 @@ func TestLinkCreateTwo(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
d := newDriver()
|
d := newDriver()
|
||||||
|
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
EnableIPv6: true}
|
EnableIPv6: true}
|
||||||
genericOption := make(map[string]interface{})
|
genericOption := make(map[string]interface{})
|
||||||
|
@ -137,7 +137,7 @@ func TestLinkCreateNoEnableIPv6(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
d := newDriver()
|
d := newDriver()
|
||||||
|
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName}
|
BridgeName: DefaultBridgeName}
|
||||||
genericOption := make(map[string]interface{})
|
genericOption := make(map[string]interface{})
|
||||||
genericOption[netlabel.GenericData] = config
|
genericOption[netlabel.GenericData] = config
|
||||||
|
@ -167,7 +167,7 @@ func TestLinkDelete(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
d := newDriver()
|
d := newDriver()
|
||||||
|
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
EnableIPv6: true}
|
EnableIPv6: true}
|
||||||
genericOption := make(map[string]interface{})
|
genericOption := make(map[string]interface{})
|
||||||
|
|
|
@ -15,7 +15,7 @@ var (
|
||||||
defaultBindingIP = net.IPv4(0, 0, 0, 0)
|
defaultBindingIP = net.IPv4(0, 0, 0, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
func allocatePorts(epConfig *EndpointConfiguration, intf *sandbox.Interface, reqDefBindIP net.IP, ulPxyEnabled bool) ([]types.PortBinding, error) {
|
func allocatePorts(epConfig *endpointConfiguration, intf *sandbox.Interface, reqDefBindIP net.IP, ulPxyEnabled bool) ([]types.PortBinding, error) {
|
||||||
if epConfig == nil || epConfig.PortBindings == nil {
|
if epConfig == nil || epConfig.PortBindings == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func TestPortMappingConfig(t *testing.T) {
|
||||||
epOptions := make(map[string]interface{})
|
epOptions := make(map[string]interface{})
|
||||||
epOptions[netlabel.PortMap] = portBindings
|
epOptions[netlabel.PortMap] = portBindings
|
||||||
|
|
||||||
netConfig := &NetworkConfiguration{
|
netConfig := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
EnableIPTables: true,
|
EnableIPTables: true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package bridge
|
package bridge
|
||||||
|
|
||||||
type setupStep func(*NetworkConfiguration, *bridgeInterface) error
|
type setupStep func(*networkConfiguration, *bridgeInterface) error
|
||||||
|
|
||||||
type bridgeSetup struct {
|
type bridgeSetup struct {
|
||||||
config *NetworkConfiguration
|
config *networkConfiguration
|
||||||
bridge *bridgeInterface
|
bridge *bridgeInterface
|
||||||
steps []setupStep
|
steps []setupStep
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBridgeSetup(c *NetworkConfiguration, i *bridgeInterface) *bridgeSetup {
|
func newBridgeSetup(c *networkConfiguration, i *bridgeInterface) *bridgeSetup {
|
||||||
return &bridgeSetup{config: c, bridge: i}
|
return &bridgeSetup{config: c, bridge: i}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,12 @@ import (
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/pkg/parsers/kernel"
|
"github.com/docker/docker/pkg/parsers/kernel"
|
||||||
"github.com/docker/libnetwork/netutils"
|
"github.com/docker/libnetwork/netutils"
|
||||||
|
"github.com/docker/libnetwork/types"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupDevice create a new bridge interface/
|
// SetupDevice create a new bridge interface/
|
||||||
func setupDevice(config *NetworkConfiguration, i *bridgeInterface) error {
|
func setupDevice(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
// We only attempt to create the bridge when the requested device name is
|
// We only attempt to create the bridge when the requested device name is
|
||||||
// the default one.
|
// the default one.
|
||||||
if config.BridgeName != DefaultBridgeName && !config.AllowNonDefaultBridge {
|
if config.BridgeName != DefaultBridgeName && !config.AllowNonDefaultBridge {
|
||||||
|
@ -31,11 +32,14 @@ func setupDevice(config *NetworkConfiguration, i *bridgeInterface) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call out to netlink to create the device.
|
// Call out to netlink to create the device.
|
||||||
return netlink.LinkAdd(i.Link)
|
if err = netlink.LinkAdd(i.Link); err != nil {
|
||||||
|
return types.InternalErrorf("Failed to program bridge link: %s", err.Error())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupDeviceUp ups the given bridge interface.
|
// SetupDeviceUp ups the given bridge interface.
|
||||||
func setupDeviceUp(config *NetworkConfiguration, i *bridgeInterface) error {
|
func setupDeviceUp(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
err := netlink.LinkSetUp(i.Link)
|
err := netlink.LinkSetUp(i.Link)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
func TestSetupNewBridge(t *testing.T) {
|
func TestSetupNewBridge(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
|
|
||||||
config := &NetworkConfiguration{BridgeName: DefaultBridgeName}
|
config := &networkConfiguration{BridgeName: DefaultBridgeName}
|
||||||
br := &bridgeInterface{}
|
br := &bridgeInterface{}
|
||||||
|
|
||||||
if err := setupDevice(config, br); err != nil {
|
if err := setupDevice(config, br); err != nil {
|
||||||
|
@ -32,7 +32,7 @@ func TestSetupNewBridge(t *testing.T) {
|
||||||
func TestSetupNewNonDefaultBridge(t *testing.T) {
|
func TestSetupNewNonDefaultBridge(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
|
|
||||||
config := &NetworkConfiguration{BridgeName: "test0"}
|
config := &networkConfiguration{BridgeName: "test0"}
|
||||||
br := &bridgeInterface{}
|
br := &bridgeInterface{}
|
||||||
|
|
||||||
err := setupDevice(config, br)
|
err := setupDevice(config, br)
|
||||||
|
@ -48,7 +48,7 @@ func TestSetupNewNonDefaultBridge(t *testing.T) {
|
||||||
func TestSetupDeviceUp(t *testing.T) {
|
func TestSetupDeviceUp(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
|
|
||||||
config := &NetworkConfiguration{BridgeName: DefaultBridgeName}
|
config := &networkConfiguration{BridgeName: DefaultBridgeName}
|
||||||
br := &bridgeInterface{}
|
br := &bridgeInterface{}
|
||||||
|
|
||||||
if err := setupDevice(config, br); err != nil {
|
if err := setupDevice(config, br); err != nil {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupFixedCIDRv4(config *NetworkConfiguration, i *bridgeInterface) error {
|
func setupFixedCIDRv4(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
addrv4, _, err := i.addresses()
|
addrv4, _, err := i.addresses()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
func TestSetupFixedCIDRv4(t *testing.T) {
|
func TestSetupFixedCIDRv4(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
|
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
AddressIPv4: &net.IPNet{IP: net.ParseIP("192.168.1.1"), Mask: net.CIDRMask(16, 32)},
|
AddressIPv4: &net.IPNet{IP: net.ParseIP("192.168.1.1"), Mask: net.CIDRMask(16, 32)},
|
||||||
FixedCIDR: &net.IPNet{IP: net.ParseIP("192.168.2.0"), Mask: net.CIDRMask(24, 32)}}
|
FixedCIDR: &net.IPNet{IP: net.ParseIP("192.168.2.0"), Mask: net.CIDRMask(24, 32)}}
|
||||||
|
@ -37,7 +37,7 @@ func TestSetupFixedCIDRv4(t *testing.T) {
|
||||||
func TestSetupBadFixedCIDRv4(t *testing.T) {
|
func TestSetupBadFixedCIDRv4(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
|
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
AddressIPv4: &net.IPNet{IP: net.ParseIP("192.168.1.1"), Mask: net.CIDRMask(24, 32)},
|
AddressIPv4: &net.IPNet{IP: net.ParseIP("192.168.1.1"), Mask: net.CIDRMask(24, 32)},
|
||||||
FixedCIDR: &net.IPNet{IP: net.ParseIP("192.168.2.0"), Mask: net.CIDRMask(24, 32)}}
|
FixedCIDR: &net.IPNet{IP: net.ParseIP("192.168.2.0"), Mask: net.CIDRMask(24, 32)}}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupFixedCIDRv6(config *NetworkConfiguration, i *bridgeInterface) error {
|
func setupFixedCIDRv6(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
log.Debugf("Using IPv6 subnet: %v", config.FixedCIDRv6)
|
log.Debugf("Using IPv6 subnet: %v", config.FixedCIDRv6)
|
||||||
if err := ipAllocator.RegisterSubnet(config.FixedCIDRv6, config.FixedCIDRv6); err != nil {
|
if err := ipAllocator.RegisterSubnet(config.FixedCIDRv6, config.FixedCIDRv6); err != nil {
|
||||||
return &FixedCIDRv6Error{Net: config.FixedCIDRv6, Err: err}
|
return &FixedCIDRv6Error{Net: config.FixedCIDRv6, Err: err}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
func TestSetupFixedCIDRv6(t *testing.T) {
|
func TestSetupFixedCIDRv6(t *testing.T) {
|
||||||
defer netutils.SetupTestNetNS(t)()
|
defer netutils.SetupTestNetNS(t)()
|
||||||
|
|
||||||
config := &NetworkConfiguration{}
|
config := &networkConfiguration{}
|
||||||
br := newInterface(config)
|
br := newInterface(config)
|
||||||
|
|
||||||
_, config.FixedCIDRv6, _ = net.ParseCIDR("2002:db8::/48")
|
_, config.FixedCIDRv6, _ = net.ParseCIDR("2002:db8::/48")
|
||||||
|
|
|
@ -10,7 +10,7 @@ const (
|
||||||
ipv4ForwardConfPerm = 0644
|
ipv4ForwardConfPerm = 0644
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupIPForwarding(config *Configuration) error {
|
func setupIPForwarding(config *configuration) error {
|
||||||
// Sanity Check
|
// Sanity Check
|
||||||
if config.EnableIPForwarding == false {
|
if config.EnableIPForwarding == false {
|
||||||
return &ErrIPFwdCfg{}
|
return &ErrIPFwdCfg{}
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestSetupIPForwarding(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create test interface with ip forwarding setting enabled
|
// Create test interface with ip forwarding setting enabled
|
||||||
config := &Configuration{
|
config := &configuration{
|
||||||
EnableIPForwarding: true}
|
EnableIPForwarding: true}
|
||||||
|
|
||||||
// Set IP Forwarding
|
// Set IP Forwarding
|
||||||
|
@ -38,7 +38,7 @@ func TestUnexpectedSetupIPForwarding(t *testing.T) {
|
||||||
defer reconcileIPForwardingSetting(t, procSetting)
|
defer reconcileIPForwardingSetting(t, procSetting)
|
||||||
|
|
||||||
// Create test interface without ip forwarding setting enabled
|
// Create test interface without ip forwarding setting enabled
|
||||||
config := &Configuration{
|
config := &configuration{
|
||||||
EnableIPForwarding: false}
|
EnableIPForwarding: false}
|
||||||
|
|
||||||
// Attempt Set IP Forwarding
|
// Attempt Set IP Forwarding
|
||||||
|
|
|
@ -13,7 +13,7 @@ const (
|
||||||
DockerChain = "DOCKER"
|
DockerChain = "DOCKER"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupIPTables(config *NetworkConfiguration, i *bridgeInterface) error {
|
func setupIPTables(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
// Sanity check.
|
// Sanity check.
|
||||||
if config.EnableIPTables == false {
|
if config.EnableIPTables == false {
|
||||||
return IPTableCfgError(config.BridgeName)
|
return IPTableCfgError(config.BridgeName)
|
||||||
|
|
|
@ -58,14 +58,14 @@ func TestSetupIPTables(t *testing.T) {
|
||||||
assertBridgeConfig(config, br, t)
|
assertBridgeConfig(config, br, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBasicTestConfig() *NetworkConfiguration {
|
func getBasicTestConfig() *networkConfiguration {
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
AddressIPv4: &net.IPNet{IP: net.ParseIP(iptablesTestBridgeIP), Mask: net.CIDRMask(16, 32)}}
|
AddressIPv4: &net.IPNet{IP: net.ParseIP(iptablesTestBridgeIP), Mask: net.CIDRMask(16, 32)}}
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestBridge(config *NetworkConfiguration, br *bridgeInterface, t *testing.T) {
|
func createTestBridge(config *networkConfiguration, br *bridgeInterface, t *testing.T) {
|
||||||
if err := setupDevice(config, br); err != nil {
|
if err := setupDevice(config, br); err != nil {
|
||||||
t.Fatalf("Failed to create the testing Bridge: %s", err.Error())
|
t.Fatalf("Failed to create the testing Bridge: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ func assertIPTableChainProgramming(rule iptRule, descr string, t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert function which pushes chains based on bridge config parameters.
|
// Assert function which pushes chains based on bridge config parameters.
|
||||||
func assertBridgeConfig(config *NetworkConfiguration, br *bridgeInterface, t *testing.T) {
|
func assertBridgeConfig(config *networkConfiguration, br *bridgeInterface, t *testing.T) {
|
||||||
// Attempt programming of ip tables.
|
// Attempt programming of ip tables.
|
||||||
err := setupIPTables(config, br)
|
err := setupIPTables(config, br)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
@ -44,7 +43,7 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupBridgeIPv4(config *NetworkConfiguration, i *bridgeInterface) error {
|
func setupBridgeIPv4(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
addrv4, _, err := i.addresses()
|
addrv4, _, err := i.addresses()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -81,12 +80,12 @@ func setupBridgeIPv4(config *NetworkConfiguration, i *bridgeInterface) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func allocateBridgeIP(config *NetworkConfiguration, i *bridgeInterface) error {
|
func allocateBridgeIP(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
ipAllocator.RequestIP(i.bridgeIPv4, i.bridgeIPv4.IP)
|
ipAllocator.RequestIP(i.bridgeIPv4, i.bridgeIPv4.IP)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func electBridgeIPv4(config *NetworkConfiguration) (*net.IPNet, error) {
|
func electBridgeIPv4(config *networkConfiguration) (*net.IPNet, error) {
|
||||||
// Use the requested IPv4 CIDR when available.
|
// Use the requested IPv4 CIDR when available.
|
||||||
if config.AddressIPv4 != nil {
|
if config.AddressIPv4 != nil {
|
||||||
return config.AddressIPv4, nil
|
return config.AddressIPv4, nil
|
||||||
|
@ -112,7 +111,7 @@ func electBridgeIPv4(config *NetworkConfiguration) (*net.IPNet, error) {
|
||||||
return nil, IPv4AddrRangeError(config.BridgeName)
|
return nil, IPv4AddrRangeError(config.BridgeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupGatewayIPv4(config *NetworkConfiguration, i *bridgeInterface) error {
|
func setupGatewayIPv4(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
if !i.bridgeIPv4.Contains(config.DefaultGatewayIPv4) {
|
if !i.bridgeIPv4.Contains(config.DefaultGatewayIPv4) {
|
||||||
return &ErrInvalidGateway{}
|
return &ErrInvalidGateway{}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +125,7 @@ func setupGatewayIPv4(config *NetworkConfiguration, i *bridgeInterface) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupLoopbackAdressesRouting(config *NetworkConfiguration, i *bridgeInterface) error {
|
func setupLoopbackAdressesRouting(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
// Enable loopback adresses routing
|
// Enable loopback adresses routing
|
||||||
sysPath := filepath.Join("/proc/sys/net/ipv4/conf", config.BridgeName, "route_localnet")
|
sysPath := filepath.Join("/proc/sys/net/ipv4/conf", config.BridgeName, "route_localnet")
|
||||||
if err := ioutil.WriteFile(sysPath, []byte{'1', '\n'}, 0644); err != nil {
|
if err := ioutil.WriteFile(sysPath, []byte{'1', '\n'}, 0644); err != nil {
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupTestInterface(t *testing.T) (*NetworkConfiguration, *bridgeInterface) {
|
func setupTestInterface(t *testing.T) (*networkConfiguration, *bridgeInterface) {
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName}
|
BridgeName: DefaultBridgeName}
|
||||||
br := &bridgeInterface{}
|
br := &bridgeInterface{}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ func TestSetupGatewayIPv4(t *testing.T) {
|
||||||
nw.IP = ip
|
nw.IP = ip
|
||||||
gw := net.ParseIP("192.168.0.254")
|
gw := net.ParseIP("192.168.0.254")
|
||||||
|
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
DefaultGatewayIPv4: gw}
|
DefaultGatewayIPv4: gw}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupBridgeIPv6(config *NetworkConfiguration, i *bridgeInterface) error {
|
func setupBridgeIPv6(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
// Enable IPv6 on the bridge
|
// Enable IPv6 on the bridge
|
||||||
procFile := "/proc/sys/net/ipv6/conf/" + config.BridgeName + "/disable_ipv6"
|
procFile := "/proc/sys/net/ipv6/conf/" + config.BridgeName + "/disable_ipv6"
|
||||||
if err := ioutil.WriteFile(procFile, []byte{'0', '\n'}, 0644); err != nil {
|
if err := ioutil.WriteFile(procFile, []byte{'0', '\n'}, 0644); err != nil {
|
||||||
|
@ -48,7 +48,7 @@ func setupBridgeIPv6(config *NetworkConfiguration, i *bridgeInterface) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupGatewayIPv6(config *NetworkConfiguration, i *bridgeInterface) error {
|
func setupGatewayIPv6(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
if config.FixedCIDRv6 == nil {
|
if config.FixedCIDRv6 == nil {
|
||||||
return &ErrInvalidContainerSubnet{}
|
return &ErrInvalidContainerSubnet{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ func TestSetupGatewayIPv6(t *testing.T) {
|
||||||
_, nw, _ := net.ParseCIDR("2001:db8:ea9:9abc:ffff::/80")
|
_, nw, _ := net.ParseCIDR("2001:db8:ea9:9abc:ffff::/80")
|
||||||
gw := net.ParseIP("2001:db8:ea9:9abc:ffff::254")
|
gw := net.ParseIP("2001:db8:ea9:9abc:ffff::254")
|
||||||
|
|
||||||
config := &NetworkConfiguration{
|
config := &networkConfiguration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
FixedCIDRv6: nw,
|
FixedCIDRv6: nw,
|
||||||
DefaultGatewayIPv6: gw}
|
DefaultGatewayIPv6: gw}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupVerifyAndReconcile(config *NetworkConfiguration, i *bridgeInterface) error {
|
func setupVerifyAndReconcile(config *networkConfiguration, i *bridgeInterface) error {
|
||||||
// Fetch a single IPv4 and a slice of IPv6 addresses from the bridge.
|
// Fetch a single IPv4 and a slice of IPv6 addresses from the bridge.
|
||||||
addrv4, addrsv6, err := i.addresses()
|
addrv4, addrsv6, err := i.addresses()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -27,7 +27,7 @@ func TestSetupVerify(t *testing.T) {
|
||||||
|
|
||||||
addrv4 := net.IPv4(192, 168, 1, 1)
|
addrv4 := net.IPv4(192, 168, 1, 1)
|
||||||
inf := setupVerifyTest(t)
|
inf := setupVerifyTest(t)
|
||||||
config := &NetworkConfiguration{}
|
config := &networkConfiguration{}
|
||||||
config.AddressIPv4 = &net.IPNet{IP: addrv4, Mask: addrv4.DefaultMask()}
|
config.AddressIPv4 = &net.IPNet{IP: addrv4, Mask: addrv4.DefaultMask()}
|
||||||
|
|
||||||
if err := netlink.AddrAdd(inf.Link, &netlink.Addr{IPNet: config.AddressIPv4}); err != nil {
|
if err := netlink.AddrAdd(inf.Link, &netlink.Addr{IPNet: config.AddressIPv4}); err != nil {
|
||||||
|
@ -44,7 +44,7 @@ func TestSetupVerifyBad(t *testing.T) {
|
||||||
|
|
||||||
addrv4 := net.IPv4(192, 168, 1, 1)
|
addrv4 := net.IPv4(192, 168, 1, 1)
|
||||||
inf := setupVerifyTest(t)
|
inf := setupVerifyTest(t)
|
||||||
config := &NetworkConfiguration{}
|
config := &networkConfiguration{}
|
||||||
config.AddressIPv4 = &net.IPNet{IP: addrv4, Mask: addrv4.DefaultMask()}
|
config.AddressIPv4 = &net.IPNet{IP: addrv4, Mask: addrv4.DefaultMask()}
|
||||||
|
|
||||||
ipnet := &net.IPNet{IP: net.IPv4(192, 168, 1, 2), Mask: addrv4.DefaultMask()}
|
ipnet := &net.IPNet{IP: net.IPv4(192, 168, 1, 2), Mask: addrv4.DefaultMask()}
|
||||||
|
@ -62,7 +62,7 @@ func TestSetupVerifyMissing(t *testing.T) {
|
||||||
|
|
||||||
addrv4 := net.IPv4(192, 168, 1, 1)
|
addrv4 := net.IPv4(192, 168, 1, 1)
|
||||||
inf := setupVerifyTest(t)
|
inf := setupVerifyTest(t)
|
||||||
config := &NetworkConfiguration{}
|
config := &networkConfiguration{}
|
||||||
config.AddressIPv4 = &net.IPNet{IP: addrv4, Mask: addrv4.DefaultMask()}
|
config.AddressIPv4 = &net.IPNet{IP: addrv4, Mask: addrv4.DefaultMask()}
|
||||||
|
|
||||||
if err := setupVerifyAndReconcile(config, inf); err == nil {
|
if err := setupVerifyAndReconcile(config, inf); err == nil {
|
||||||
|
@ -75,7 +75,7 @@ func TestSetupVerifyIPv6(t *testing.T) {
|
||||||
|
|
||||||
addrv4 := net.IPv4(192, 168, 1, 1)
|
addrv4 := net.IPv4(192, 168, 1, 1)
|
||||||
inf := setupVerifyTest(t)
|
inf := setupVerifyTest(t)
|
||||||
config := &NetworkConfiguration{}
|
config := &networkConfiguration{}
|
||||||
config.AddressIPv4 = &net.IPNet{IP: addrv4, Mask: addrv4.DefaultMask()}
|
config.AddressIPv4 = &net.IPNet{IP: addrv4, Mask: addrv4.DefaultMask()}
|
||||||
config.EnableIPv6 = true
|
config.EnableIPv6 = true
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ func TestSetupVerifyIPv6Missing(t *testing.T) {
|
||||||
|
|
||||||
addrv4 := net.IPv4(192, 168, 1, 1)
|
addrv4 := net.IPv4(192, 168, 1, 1)
|
||||||
inf := setupVerifyTest(t)
|
inf := setupVerifyTest(t)
|
||||||
config := &NetworkConfiguration{}
|
config := &networkConfiguration{}
|
||||||
config.AddressIPv4 = &net.IPNet{IP: addrv4, Mask: addrv4.DefaultMask()}
|
config.AddressIPv4 = &net.IPNet{IP: addrv4, Mask: addrv4.DefaultMask()}
|
||||||
config.EnableIPv6 = true
|
config.EnableIPv6 = true
|
||||||
|
|
||||||
|
|
|
@ -314,8 +314,7 @@ func TestDuplicateNetwork(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = controller.NewNetwork(bridgeNetType, "testnetwork",
|
_, err = controller.NewNetwork(bridgeNetType, "testnetwork", nil)
|
||||||
libnetwork.NetworkOptionGeneric(genericOption))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue