Skip to content

Commit

Permalink
Merge pull request #47310 from akerouanton/25.0-revert-automatically-…
Browse files Browse the repository at this point in the history
…enable-ipv6

[25.0 backport] Revert "daemon: automatically set network EnableIPv6 if needed"
  • Loading branch information
thaJeztah committed Feb 3, 2024
2 parents 5b5a58b + 0ccf1c2 commit a7f9907
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
27 changes: 5 additions & 22 deletions api/types/network/ipam.go
Expand Up @@ -30,30 +30,9 @@ const (
ip6 ipFamily = "IPv6"
)

// HasIPv6Subnets checks whether there's any IPv6 subnets in the ipam parameter. It ignores any invalid Subnet and nil
// ipam.
func HasIPv6Subnets(ipam *IPAM) bool {
if ipam == nil {
return false
}

for _, cfg := range ipam.Config {
subnet, err := netip.ParsePrefix(cfg.Subnet)
if err != nil {
continue
}

if subnet.Addr().Is6() {
return true
}
}

return false
}

// ValidateIPAM checks whether the network's IPAM passed as argument is valid. It returns a joinError of the list of
// errors found.
func ValidateIPAM(ipam *IPAM) error {
func ValidateIPAM(ipam *IPAM, enableIPv6 bool) error {
if ipam == nil {
return nil
}
Expand All @@ -70,6 +49,10 @@ func ValidateIPAM(ipam *IPAM) error {
subnetFamily = ip6
}

if !enableIPv6 && subnetFamily == ip6 {
continue
}

if subnet != subnet.Masked() {
errs = append(errs, fmt.Errorf("invalid subnet %s: it should be %s", subnet, subnet.Masked()))
}
Expand Down
8 changes: 7 additions & 1 deletion api/types/network/ipam_test.go
Expand Up @@ -30,6 +30,12 @@ func TestNetworkWithInvalidIPAM(t *testing.T) {
"invalid auxiliary address DefaultGatewayIPv4: parent subnet is an IPv4 block",
},
},
{
// 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"}}},
ipv6: false,
},
{
name: "Invalid data - Subnet",
ipam: IPAM{Config: []IPAMConfig{{Subnet: "foobar"}}},
Expand Down Expand Up @@ -122,7 +128,7 @@ func TestNetworkWithInvalidIPAM(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

errs := ValidateIPAM(&tc.ipam)
errs := ValidateIPAM(&tc.ipam, tc.ipv6)
if tc.expectedErrors == nil {
assert.NilError(t, errs)
return
Expand Down
6 changes: 1 addition & 5 deletions daemon/network.go
Expand Up @@ -305,10 +305,6 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCrea
return nil, errdefs.Forbidden(errors.New(`This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.`))
}

if network.HasIPv6Subnets(create.IPAM) {
create.EnableIPv6 = true
}

networkOptions := make(map[string]string)
for k, v := range create.Options {
networkOptions[k] = v
Expand All @@ -335,7 +331,7 @@ func (daemon *Daemon) createNetwork(cfg *config.Config, create types.NetworkCrea
nwOptions = append(nwOptions, libnetwork.NetworkOptionConfigOnly())
}

if err := network.ValidateIPAM(create.IPAM); err != nil {
if err := network.ValidateIPAM(create.IPAM, create.EnableIPv6); err != nil {
return nil, errdefs.InvalidParameter(err)
}

Expand Down

0 comments on commit a7f9907

Please sign in to comment.