Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -592,9 +592,9 @@ func (daemon *Daemon) getNetworkSandbox(container *container.Container) libnetwo |
| 592 | 592 |
return sb |
| 593 | 593 |
} |
| 594 | 594 |
|
| 595 |
-// hasUserDefinedIPAddress returns whether the passed endpoint configuration contains IP address configuration |
|
| 596 |
-func hasUserDefinedIPAddress(epConfig *networktypes.EndpointSettings) bool {
|
|
| 597 |
- return epConfig != nil && epConfig.IPAMConfig != nil && (len(epConfig.IPAMConfig.IPv4Address) > 0 || len(epConfig.IPAMConfig.IPv6Address) > 0) |
|
| 595 |
+// hasUserDefinedIPAddress returns whether the passed IPAM configuration contains IP address configuration |
|
| 596 |
+func hasUserDefinedIPAddress(ipamConfig *networktypes.EndpointIPAMConfig) bool {
|
|
| 597 |
+ return ipamConfig != nil && (len(ipamConfig.IPv4Address) > 0 || len(ipamConfig.IPv6Address) > 0) |
|
| 598 | 598 |
} |
| 599 | 599 |
|
| 600 | 600 |
// 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 |
| 602 | 602 |
if n == nil || epConfig == nil {
|
| 603 | 603 |
return nil |
| 604 | 604 |
} |
| 605 |
- if !hasUserDefinedIPAddress(epConfig) {
|
|
| 605 |
+ if !containertypes.NetworkMode(n.Name()).IsUserDefined() {
|
|
| 606 |
+ if hasUserDefinedIPAddress(epConfig.IPAMConfig) && !enableIPOnPredefinedNetwork() {
|
|
| 607 |
+ return runconfig.ErrUnsupportedNetworkAndIP |
|
| 608 |
+ } |
|
| 609 |
+ if len(epConfig.Aliases) > 0 && !serviceDiscoveryOnDefaultNetwork() {
|
|
| 610 |
+ return runconfig.ErrUnsupportedNetworkAndAlias |
|
| 611 |
+ } |
|
| 612 |
+ } |
|
| 613 |
+ if !hasUserDefinedIPAddress(epConfig.IPAMConfig) {
|
|
| 606 | 614 |
return nil |
| 607 | 615 |
} |
| 616 |
+ |
|
| 608 | 617 |
_, _, nwIPv4Configs, nwIPv6Configs := n.Info().IpamConfig() |
| 609 | 618 |
for _, s := range []struct {
|
| 610 | 619 |
ipConfigured bool |
| ... | ... |
@@ -653,14 +662,7 @@ func cleanOperationalData(es *network.EndpointSettings) {
|
| 653 | 653 |
|
| 654 | 654 |
func (daemon *Daemon) updateNetworkConfig(container *container.Container, n libnetwork.Network, endpointConfig *networktypes.EndpointSettings, updateSettings bool) error {
|
| 655 | 655 |
|
| 656 |
- if !containertypes.NetworkMode(n.Name()).IsUserDefined() {
|
|
| 657 |
- if hasUserDefinedIPAddress(endpointConfig) && !enableIPOnPredefinedNetwork() {
|
|
| 658 |
- return runconfig.ErrUnsupportedNetworkAndIP |
|
| 659 |
- } |
|
| 660 |
- if endpointConfig != nil && len(endpointConfig.Aliases) > 0 && !serviceDiscoveryOnDefaultNetwork() {
|
|
| 661 |
- return runconfig.ErrUnsupportedNetworkAndAlias |
|
| 662 |
- } |
|
| 663 |
- } else {
|
|
| 656 |
+ if containertypes.NetworkMode(n.Name()).IsUserDefined() {
|
|
| 664 | 657 |
addShortID := true |
| 665 | 658 |
shortID := stringid.TruncateID(container.ID) |
| 666 | 659 |
for _, alias := range endpointConfig.Aliases {
|