|
@@ -592,9 +592,9 @@ func (daemon *Daemon) getNetworkSandbox(container *container.Container) libnetwo
|
|
|
return sb
|
|
|
}
|
|
|
|
|
|
-// hasUserDefinedIPAddress returns whether the passed endpoint configuration contains IP address configuration
|
|
|
-func hasUserDefinedIPAddress(epConfig *networktypes.EndpointSettings) bool {
|
|
|
- return epConfig != nil && epConfig.IPAMConfig != nil && (len(epConfig.IPAMConfig.IPv4Address) > 0 || len(epConfig.IPAMConfig.IPv6Address) > 0)
|
|
|
+// hasUserDefinedIPAddress returns whether the passed IPAM configuration contains IP address configuration
|
|
|
+func hasUserDefinedIPAddress(ipamConfig *networktypes.EndpointIPAMConfig) bool {
|
|
|
+ return ipamConfig != nil && (len(ipamConfig.IPv4Address) > 0 || len(ipamConfig.IPv6Address) > 0)
|
|
|
}
|
|
|
|
|
|
// User specified ip address is acceptable only for networks with user specified subnets.
|
|
@@ -602,9 +602,18 @@ func validateNetworkingConfig(n libnetwork.Network, epConfig *networktypes.Endpo
|
|
|
if n == nil || epConfig == nil {
|
|
|
return nil
|
|
|
}
|
|
|
- if !hasUserDefinedIPAddress(epConfig) {
|
|
|
+ if !containertypes.NetworkMode(n.Name()).IsUserDefined() {
|
|
|
+ if hasUserDefinedIPAddress(epConfig.IPAMConfig) && !enableIPOnPredefinedNetwork() {
|
|
|
+ return runconfig.ErrUnsupportedNetworkAndIP
|
|
|
+ }
|
|
|
+ if len(epConfig.Aliases) > 0 && !serviceDiscoveryOnDefaultNetwork() {
|
|
|
+ return runconfig.ErrUnsupportedNetworkAndAlias
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !hasUserDefinedIPAddress(epConfig.IPAMConfig) {
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
_, _, nwIPv4Configs, nwIPv6Configs := n.Info().IpamConfig()
|
|
|
for _, s := range []struct {
|
|
|
ipConfigured bool
|
|
@@ -653,14 +662,7 @@ func cleanOperationalData(es *network.EndpointSettings) {
|
|
|
|
|
|
func (daemon *Daemon) updateNetworkConfig(container *container.Container, n libnetwork.Network, endpointConfig *networktypes.EndpointSettings, updateSettings bool) error {
|
|
|
|
|
|
- if !containertypes.NetworkMode(n.Name()).IsUserDefined() {
|
|
|
- if hasUserDefinedIPAddress(endpointConfig) && !enableIPOnPredefinedNetwork() {
|
|
|
- return runconfig.ErrUnsupportedNetworkAndIP
|
|
|
- }
|
|
|
- if endpointConfig != nil && len(endpointConfig.Aliases) > 0 && !serviceDiscoveryOnDefaultNetwork() {
|
|
|
- return runconfig.ErrUnsupportedNetworkAndAlias
|
|
|
- }
|
|
|
- } else {
|
|
|
+ if containertypes.NetworkMode(n.Name()).IsUserDefined() {
|
|
|
addShortID := true
|
|
|
shortID := stringid.TruncateID(container.ID)
|
|
|
for _, alias := range endpointConfig.Aliases {
|