Skip to content

Commit e37172c

Browse files
committed
api/t/network: ValidateIPAM: ignore v6 subnet when IPv6 is disabled
Commit 4f47013 introduced a new validation step to make sure no IPv6 subnet is configured on a network which has EnableIPv6=false. Commit 5d5eeac then removed that validation step and automatically enabled IPv6 for networks with a v6 subnet. But this specific commit was reverted in c59e93a and now the error introduced by 4f47013 is re-introduced. But it turns out some users expect a network created with an IPv6 subnet and EnableIPv6=false to actually have no IPv6 connectivity. This restores that behavior. Signed-off-by: Albin Kerouanton <[email protected]>
1 parent c59e93a commit e37172c

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

api/types/network/ipam.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ func ValidateIPAM(ipam *IPAM, enableIPv6 bool) error {
4949
subnetFamily = ip6
5050
}
5151

52-
if subnet != subnet.Masked() {
53-
errs = append(errs, fmt.Errorf("invalid subnet %s: it should be %s", subnet, subnet.Masked()))
52+
if !enableIPv6 && subnetFamily == ip6 {
53+
continue
5454
}
5555

56-
if !enableIPv6 && subnetFamily == ip6 {
57-
errs = append(errs, fmt.Errorf("invalid subnet %s: IPv6 has not been enabled for this network", subnet))
56+
if subnet != subnet.Masked() {
57+
errs = append(errs, fmt.Errorf("invalid subnet %s: it should be %s", subnet, subnet.Masked()))
5858
}
5959

6060
if ipRangeErrs := validateIPRange(cfg.IPRange, subnet, subnetFamily); len(ipRangeErrs) > 0 {

api/types/network/ipam_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ func TestNetworkWithInvalidIPAM(t *testing.T) {
3131
},
3232
},
3333
{
34-
name: "IPv6 subnet is discarded when IPv6 is disabled",
35-
ipam: IPAM{Config: []IPAMConfig{{Subnet: "2001:db8::/32"}}},
36-
ipv6: false,
37-
expectedErrors: []string{"invalid subnet 2001:db8::/32: IPv6 has not been enabled for this network"},
34+
// Regression test for https://github.com/moby/moby/issues/47202
35+
name: "IPv6 subnet is discarded with no error when IPv6 is disabled",
36+
ipam: IPAM{Config: []IPAMConfig{{Subnet: "2001:db8::/32"}}},
37+
ipv6: false,
3838
},
3939
{
4040
name: "Invalid data - Subnet",

0 commit comments

Comments
 (0)