api/t/network: ValidateIPAM: ignore v6 subnet when IPv6 is disabled
Commit4f47013feb
introduced a new validation step to make sure no IPv6 subnet is configured on a network which has EnableIPv6=false. Commit5d5eeac310
then removed that validation step and automatically enabled IPv6 for networks with a v6 subnet. But this specific commit was reverted inc59e93a67b
and now the error introduced by4f47013feb
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 <albinker@gmail.com>
This commit is contained in:
parent
c59e93a67b
commit
e37172c613
2 changed files with 8 additions and 8 deletions
|
@ -49,12 +49,12 @@ func ValidateIPAM(ipam *IPAM, enableIPv6 bool) error {
|
||||||
subnetFamily = ip6
|
subnetFamily = ip6
|
||||||
}
|
}
|
||||||
|
|
||||||
if subnet != subnet.Masked() {
|
if !enableIPv6 && subnetFamily == ip6 {
|
||||||
errs = append(errs, fmt.Errorf("invalid subnet %s: it should be %s", subnet, subnet.Masked()))
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if !enableIPv6 && subnetFamily == ip6 {
|
if subnet != subnet.Masked() {
|
||||||
errs = append(errs, fmt.Errorf("invalid subnet %s: IPv6 has not been enabled for this network", subnet))
|
errs = append(errs, fmt.Errorf("invalid subnet %s: it should be %s", subnet, subnet.Masked()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ipRangeErrs := validateIPRange(cfg.IPRange, subnet, subnetFamily); len(ipRangeErrs) > 0 {
|
if ipRangeErrs := validateIPRange(cfg.IPRange, subnet, subnetFamily); len(ipRangeErrs) > 0 {
|
||||||
|
|
|
@ -31,10 +31,10 @@ func TestNetworkWithInvalidIPAM(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "IPv6 subnet is discarded when IPv6 is disabled",
|
// Regression test for https://github.com/moby/moby/issues/47202
|
||||||
|
name: "IPv6 subnet is discarded with no error when IPv6 is disabled",
|
||||||
ipam: IPAM{Config: []IPAMConfig{{Subnet: "2001:db8::/32"}}},
|
ipam: IPAM{Config: []IPAMConfig{{Subnet: "2001:db8::/32"}}},
|
||||||
ipv6: false,
|
ipv6: false,
|
||||||
expectedErrors: []string{"invalid subnet 2001:db8::/32: IPv6 has not been enabled for this network"},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Invalid data - Subnet",
|
name: "Invalid data - Subnet",
|
||||||
|
|
Loading…
Reference in a new issue